Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Fix Proxmox read-state CPU normalization
rcourtman21b15e6755d4
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex b2add17308..e556a863ce 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -50,6 +50,12 @@ per-core CPU percent, but monitoring-owned history and alert thresholdevaluation use host-capacity-normalized CPU percent when host CPU capacity isknown. Raw runtime CPU remains alert/resource metadata, not the canonicalthreshold value.+Proxmox read-state rehydration is the inverse boundary: canonical+unified-resource CPU metrics are 0..100 percentages, while legacy+`models.Node.CPU`, `models.VM.CPU`, and `models.Container.CPU` remain Proxmox+0..1 ratio fields. Monitoring-owned read-state conversion must divide canonical+Proxmox node, VM, and LXC CPU percentages before handing them back to legacy+snapshot/current-row paths.## Canonical Filesdiff --git a/internal/monitoring/canonical_guardrails_test.go b/internal/monitoring/canonical_guardrails_test.goindex 06fbfe9bd5..dbe199f873 100644--- a/internal/monitoring/canonical_guardrails_test.go+++ b/internal/monitoring/canonical_guardrails_test.go@@ -1,6 +1,7 @@package monitoringimport (+ "math""os""path/filepath""regexp"@@ -111,6 +112,84 @@ func TestBroadcastResourceDiskIOUsesUnifiedResourceMetrics(t *testing.T) {}}+func TestProxmoxReadStateCPUPercentRehydratesLegacyRatios(t *testing.T) {+ const (+ canonicalPercent = 0.6+ legacyRatio = 0.006+ )++ t.Run("node", func(t *testing.T) {+ view := unifiedresources.NewNodeView(&unifiedresources.Resource{+ ID: "node-pve1",+ Name: "pve1",+ Type: unifiedresources.ResourceTypeAgent,+ Status: unifiedresources.StatusOnline,+ Metrics: &unifiedresources.ResourceMetrics{+ CPU: &unifiedresources.MetricValue{Percent: canonicalPercent},+ },+ Proxmox: &unifiedresources.ProxmoxData{+ SourceID: "node/pve1",+ NodeName: "pve1",+ Instance: "lab",+ },+ })++ got := nodeFromReadStateView(&view)+ assertFloatClose(t, got.CPU, legacyRatio)+ })++ t.Run("vm", func(t *testing.T) {+ view := unifiedresources.NewVMView(&unifiedresources.Resource{+ ID: "vm-101",+ Name: "debian",+ Type: unifiedresources.ResourceTypeVM,+ Status: unifiedresources.StatusOnline,+ Metrics: &unifiedresources.ResourceMetrics{+ CPU: &unifiedresources.MetricValue{Percent: canonicalPercent},+ },+ Proxmox: &unifiedresources.ProxmoxData{+ SourceID: "qemu/101",+ NodeName: "pve1",+ Instance: "lab",+ VMID: 101,+ },+ })++ got := vmFromReadStateView(&view)+ assertFloatClose(t, got.CPU, legacyRatio)+ })++ t.Run("container", func(t *testing.T) {+ view := unifiedresources.NewContainerView(&unifiedresources.Resource{+ ID: "ct-201",+ Name: "nginx",+ Type: unifiedresources.ResourceTypeSystemContainer,+ Status: unifiedresources.StatusOnline,+ Metrics: &unifiedresources.ResourceMetrics{+ CPU: &unifiedresources.MetricValue{Percent: canonicalPercent},+ },+ Proxmox: &unifiedresources.ProxmoxData{+ SourceID: "lxc/201",+ NodeName: "pve1",+ Instance: "lab",+ VMID: 201,+ ContainerType: "lxc",+ },+ })++ got := containerFromReadStateView(&view)+ assertFloatClose(t, got.CPU, legacyRatio)+ })+}++func assertFloatClose(t *testing.T, got float64, want float64) {+ t.Helper()++ if math.Abs(got-want) > 0.000001 {+ t.Fatalf("got %v, want %v", got, want)+ }+}+func TestStandaloneInactiveDockerSwarmMetadataIsNotCapabilityEvidence(t *testing.T) {got := convertDockerSwarmInfo(&agentsdocker.SwarmInfo{NodeRole: "worker",diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.goindex c17acfe0b8..a229942d86 100644--- a/internal/monitoring/monitor.go+++ b/internal/monitoring/monitor.go@@ -3054,6 +3054,13 @@ func storageFromReadStateView(view *unifiedresources.StoragePoolView) models.Sto}}+func proxmoxRatioFromPercent(percent float64) float64 {+ if math.IsNaN(percent) || math.IsInf(percent, 0) || percent <= 0 {+ return 0+ }+ return percent / 100+}+func nodeFromReadStateView(view *unifiedresources.NodeView) models.Node {if view == nil {return models.Node{}@@ -3074,7 +3081,7 @@ func nodeFromReadStateView(view *unifiedresources.NodeView) models.Node {GuestURL: view.GuestURL(),Status: string(view.Status()),Type: "node",- CPU: view.CPUPercent(),+ CPU: proxmoxRatioFromPercent(view.CPUPercent()),Memory: models.Memory{Used: view.MemoryUsed(), Total: view.MemoryTotal(), Free: maxInt64(0, view.MemoryTotal()-view.MemoryUsed()), Usage: view.MemoryPercent()},Disk: models.Disk{Used: view.DiskUsed(), Total: view.DiskTotal(), Free: maxInt64(0, view.DiskTotal()-view.DiskUsed()), Usage: view.DiskPercent()},Uptime: view.Uptime(),@@ -3167,7 +3174,7 @@ func vmFromReadStateView(view *unifiedresources.VMView) models.VM {Instance: view.Instance(),Status: string(view.Status()),Type: "qemu",- CPU: view.CPUPercent(),+ CPU: proxmoxRatioFromPercent(view.CPUPercent()),CPUs: view.CPUs(),Memory: models.Memory{Total: totalMemory, Used: usedMemory, Free: maxInt64(0, totalMemory-usedMemory), Usage: view.MemoryPercent()},Disk: models.Disk{Used: usedDisk, Total: totalDisk, Free: maxInt64(0, totalDisk-usedDisk), Usage: view.DiskPercent()},@@ -3209,7 +3216,7 @@ func containerFromReadStateView(view *unifiedresources.ContainerView) models.ConInstance: view.Instance(),Status: string(view.Status()),Type: firstNonEmptyString(view.ContainerType(), "lxc"),- CPU: view.CPUPercent(),+ CPU: proxmoxRatioFromPercent(view.CPUPercent()),CPUs: view.CPUs(),Memory: models.Memory{Total: totalMemory, Used: usedMemory, Free: maxInt64(0, totalMemory-usedMemory), Usage: view.MemoryPercent()},Disk: models.Disk{Used: usedDisk, Total: totalDisk, Free: maxInt64(0, totalDisk-usedDisk), Usage: view.DiskPercent()},