Mining/pkg/mining/ttminer_stats.go
snider 8460b8f3be feat: Add multi-miner dashboard support and TT-Miner implementation
Dashboard:
- Add aggregate stats across all running miners (total hashrate, shares)
- Add workers table with per-miner stats, efficiency, and controls
- Show hashrate bars and efficiency badges for each worker
- Support stopping individual workers or all at once

TT-Miner:
- Implement Install, Start, GetStats, CheckInstallation, Uninstall
- Add TT-Miner to Manager's StartMiner and ListAvailableMiners
- Support GPU-specific config options (devices, intensity, cliArgs)

Chart:
- Improve styling with WA-Pro theme variables
- Add hashrate unit formatting (H/s, kH/s, MH/s)
- Better tooltip and axis styling

Also:
- Fix XMRig download URLs (linux-static-x64, windows-x64)
- Add Playwright E2E testing infrastructure
- Add XMR pool research documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 22:48:20 +00:00

59 lines
1.4 KiB
Go

package mining
import (
"encoding/json"
"errors"
"fmt"
"net/http"
)
// GetStats retrieves performance metrics from the TT-Miner API.
func (m *TTMiner) GetStats() (*PerformanceMetrics, error) {
m.mu.RLock()
defer m.mu.RUnlock()
if !m.Running {
return nil, errors.New("miner is not running")
}
if m.API == nil || m.API.ListenPort == 0 {
return nil, errors.New("miner API not configured or port is zero")
}
// TT-Miner API endpoint - try the summary endpoint
resp, err := httpClient.Get(fmt.Sprintf("http://%s:%d/summary", m.API.ListenHost, m.API.ListenPort))
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("failed to get stats: unexpected status code %d", resp.StatusCode)
}
var summary TTMinerSummary
if err := json.NewDecoder(resp.Body).Decode(&summary); err != nil {
return nil, err
}
// Store the full summary in the miner struct
m.FullStats = &summary
// Calculate total hashrate from all GPUs
var totalHashrate float64
if len(summary.Hashrate.Total) > 0 {
totalHashrate = summary.Hashrate.Total[0]
} else {
// Sum individual GPU hashrates
for _, gpu := range summary.GPUs {
totalHashrate += gpu.Hashrate
}
}
return &PerformanceMetrics{
Hashrate: int(totalHashrate),
Shares: summary.Results.SharesGood,
Rejected: summary.Results.SharesTotal - summary.Results.SharesGood,
Uptime: summary.Uptime,
Algorithm: summary.Algo,
}, nil
}