diff --git a/internal/web/ui.go b/internal/web/ui.go index 9aa29ea..c5b9bfd 100644 --- a/internal/web/ui.go +++ b/internal/web/ui.go @@ -83,6 +83,7 @@ type PageData struct { ResourceStatusBoard *service.ResourceStatusBoard AlarmRecords []service.AlarmRecord TodayAlarmCount int + DeviceMetrics []DeviceMetric FaceGalleryPersons []storage.PersonRecord Templates []service.Template Template *service.Template @@ -777,6 +778,25 @@ func (u *UI) pageDashboard(w http.ResponseWriter, r *http.Request) { data.Tasks = u.tasks.ListTasks() } data.AttentionDevices = nil + // Load device metrics + if u.agent != nil { + for _, dev := range data.Devices { + if dev == nil || !dev.Online { continue } + body, code, err := u.agent.Do("GET", dev.IP, dev.AgentPort, "/v1/metrics", nil) + if err != nil || code != 200 { continue } + var m struct { + CPU struct{ UsagePct float64 } `json:"cpu"` + Memory struct{ TotalKB, AvailableKB uint64 } `json:"memory"` + NPU struct{ UsagePct float64 } `json:"npu"` + } + json.Unmarshal(body, &m) + var mem float64 + if m.Memory.TotalKB > 0 { mem = float64(m.Memory.TotalKB-m.Memory.AvailableKB) / float64(m.Memory.TotalKB) * 100 } + data.DeviceMetrics = append(data.DeviceMetrics, DeviceMetric{ + Name: dev.DisplayName(), CPU: m.CPU.UsagePct, Mem: mem, NPU: m.NPU.UsagePct, + }) + } + } for _, dev := range data.Devices { if dev != nil && !dev.Online { data.AttentionDevices = append(data.AttentionDevices, dev) @@ -4191,3 +4211,10 @@ func (u *UI) apiDeviceMetrics(w http.ResponseWriter, r *http.Request) { w.WriteHeader(code) w.Write(body) } + +type DeviceMetric struct { + Name string `json:"name"` + CPU float64 `json:"cpu"` + Mem float64 `json:"mem"` + NPU float64 `json:"npu"` +} diff --git a/internal/web/ui/templates/dashboard.html b/internal/web/ui/templates/dashboard.html index e018b48..b822e98 100644 --- a/internal/web/ui/templates/dashboard.html +++ b/internal/web/ui/templates/dashboard.html @@ -28,7 +28,20 @@