refactor(api): name monitoring row payloads
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
c74f62e6d7
commit
33d35ed063
3 changed files with 47 additions and 20 deletions
|
|
@ -76,6 +76,22 @@ type ResultsResponse struct {
|
|||
Best [10]uint64 `json:"best"`
|
||||
}
|
||||
|
||||
// WorkersResponse is the /1/workers JSON body.
|
||||
//
|
||||
// {"mode":"rig-id","workers":[["rig-alpha","10.0.0.1",1,10,0,0,100000,1712232000,1.0,1.0,1.0,1.0,1.0]]}
|
||||
type WorkersResponse struct {
|
||||
Mode string `json:"mode"`
|
||||
Workers []proxy.WorkerRow `json:"workers"`
|
||||
}
|
||||
|
||||
// MinersResponse is the /1/miners JSON body.
|
||||
//
|
||||
// {"format":["id","ip","tx","rx","state","diff","user","password","rig_id","agent"],"miners":[[1,"10.0.0.1:49152",4096,512,2,100000,"WALLET","********","rig-alpha","XMRig/6.21.0"]]}
|
||||
type MinersResponse struct {
|
||||
Format []string `json:"format"`
|
||||
Miners []proxy.MinerRow `json:"miners"`
|
||||
}
|
||||
|
||||
// RegisterRoutes wires the monitoring endpoints onto the supplied router.
|
||||
//
|
||||
// proxyapi.RegisterRoutes(mux, p)
|
||||
|
|
@ -131,11 +147,11 @@ func summaryResponse(p *proxy.Proxy) SummaryResponse {
|
|||
}
|
||||
}
|
||||
|
||||
func workersResponse(p *proxy.Proxy) any {
|
||||
func workersResponse(p *proxy.Proxy) WorkersResponse {
|
||||
records := p.WorkerRecords()
|
||||
rows := make([]any, 0, len(records))
|
||||
rows := make([]proxy.WorkerRow, 0, len(records))
|
||||
for _, record := range records {
|
||||
rows = append(rows, []any{
|
||||
rows = append(rows, proxy.WorkerRow{
|
||||
record.Name,
|
||||
record.LastIP,
|
||||
record.Connections,
|
||||
|
|
@ -151,17 +167,17 @@ func workersResponse(p *proxy.Proxy) any {
|
|||
record.Hashrate(86400),
|
||||
})
|
||||
}
|
||||
return map[string]any{
|
||||
"mode": string(p.WorkersMode()),
|
||||
"workers": rows,
|
||||
return WorkersResponse{
|
||||
Mode: string(p.WorkersMode()),
|
||||
Workers: rows,
|
||||
}
|
||||
}
|
||||
|
||||
func minersResponse(p *proxy.Proxy) any {
|
||||
func minersResponse(p *proxy.Proxy) MinersResponse {
|
||||
records := p.MinerSnapshots()
|
||||
rows := make([]any, 0, len(records))
|
||||
rows := make([]proxy.MinerRow, 0, len(records))
|
||||
for _, miner := range records {
|
||||
rows = append(rows, []any{
|
||||
rows = append(rows, proxy.MinerRow{
|
||||
miner.ID,
|
||||
miner.IP,
|
||||
miner.TX,
|
||||
|
|
@ -174,9 +190,9 @@ func minersResponse(p *proxy.Proxy) any {
|
|||
miner.Agent,
|
||||
})
|
||||
}
|
||||
return map[string]any{
|
||||
"format": []string{"id", "ip", "tx", "rx", "state", "diff", "user", "password", "rig_id", "agent"},
|
||||
"miners": rows,
|
||||
return MinersResponse{
|
||||
Format: []string{"id", "ip", "tx", "rx", "state", "diff", "user", "password", "rig_id", "agent"},
|
||||
Miners: rows,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
11
api_rows.go
Normal file
11
api_rows.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package proxy
|
||||
|
||||
// WorkerRow is one row in the /1/workers table.
|
||||
//
|
||||
// WorkerRow{"rig-alpha", "10.0.0.1", 1, 10, 0, 0, 100000, 1712232000, 1.0, 1.0, 1.0, 1.0, 1.0}
|
||||
type WorkerRow [13]any
|
||||
|
||||
// MinerRow is one row in the /1/miners table.
|
||||
//
|
||||
// MinerRow{1, "10.0.0.1:49152", 4096, 512, 2, 100000, "WALLET", "********", "rig-alpha", "XMRig/6.21.0"}
|
||||
type MinerRow [10]any
|
||||
|
|
@ -612,13 +612,13 @@ type summaryResultsPayload struct {
|
|||
}
|
||||
|
||||
type workersDocumentPayload struct {
|
||||
Mode string `json:"mode"`
|
||||
Workers [][]any `json:"workers"`
|
||||
Mode string `json:"mode"`
|
||||
Workers []WorkerRow `json:"workers"`
|
||||
}
|
||||
|
||||
type minersDocumentPayload struct {
|
||||
Format []string `json:"format"`
|
||||
Miners [][]any `json:"miners"`
|
||||
Format []string `json:"format"`
|
||||
Miners []MinerRow `json:"miners"`
|
||||
}
|
||||
|
||||
func (p *Proxy) summaryDocument() summaryDocumentPayload {
|
||||
|
|
@ -653,9 +653,9 @@ func (p *Proxy) summaryDocument() summaryDocumentPayload {
|
|||
|
||||
func (p *Proxy) workersDocument() workersDocumentPayload {
|
||||
records := p.WorkerRecords()
|
||||
rows := make([][]any, 0, len(records))
|
||||
rows := make([]WorkerRow, 0, len(records))
|
||||
for _, record := range records {
|
||||
rows = append(rows, []any{
|
||||
rows = append(rows, WorkerRow{
|
||||
record.Name,
|
||||
record.LastIP,
|
||||
record.Connections,
|
||||
|
|
@ -679,9 +679,9 @@ func (p *Proxy) workersDocument() workersDocumentPayload {
|
|||
|
||||
func (p *Proxy) minersDocument() minersDocumentPayload {
|
||||
records := p.MinerSnapshots()
|
||||
rows := make([][]any, 0, len(records))
|
||||
rows := make([]MinerRow, 0, len(records))
|
||||
for _, miner := range records {
|
||||
rows = append(rows, []any{
|
||||
rows = append(rows, MinerRow{
|
||||
miner.ID,
|
||||
miner.IP,
|
||||
miner.TX,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue