chore: sync local updates
This commit is contained in:
25
mengyamonitor-backend-client/dashboard_payload.go
Normal file
25
mengyamonitor-backend-client/dashboard_payload.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// BuildDashboardPayloadJSON builds the same JSON shape the browser expects (including latency).
|
||||
// collectorToCentralMs is 采集器到监控中心 TCP 建连毫秒数,失败传 -1。
|
||||
func BuildDashboardPayloadJSON(collectorToCentralMs float64) ([]byte, error) {
|
||||
m, err := CollectMetrics()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var o map[string]any
|
||||
if err := json.Unmarshal(b, &o); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
o["latency"] = map[string]any{
|
||||
"clientToServer": collectorToCentralMs,
|
||||
"external": readExternalLatencies(),
|
||||
}
|
||||
return json.Marshal(o)
|
||||
}
|
||||
Reference in New Issue
Block a user