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 Docker app-container percent normalization
rcourtman7ddc2fcb478b
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.mdindex e4f0b1f686..d43bf82e55 100644--- a/docs/release-control/v6/internal/subsystems/unified-resources.md+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md@@ -20,7 +20,9 @@ cross-source deduplication.For Docker and Podman container resources, the canonical CPU metric representshost-capacity-normalized utilization. Runtime-native per-core CPU percent iskept on Docker metadata as raw evidence and must not replace the canonical-metric or threshold surface.+metric or threshold surface. After that capacity normalization, app-container+CPU and memory metrics are already 0..100 percentages and must be clamped+directly rather than treated as 0..1 ratios.Host-agent and Docker-host CPU, memory, and disk usage fields are alreadyreported as 0..100 percentages. Unified-resource host metric payloads andhost-derived storage adapters must clamp those reported percentages directlydiff --git a/internal/unifiedresources/metrics.go b/internal/unifiedresources/metrics.goindex e75025b6b2..3198b436cb 100644--- a/internal/unifiedresources/metrics.go+++ b/internal/unifiedresources/metrics.go@@ -261,10 +261,10 @@ func metricsFromDockerContainer(ct models.DockerContainer, hostCPUs ...int) *Resif len(hostCPUs) > 0 {cpuCapacity = hostCPUs[0]}- cpuPercent := percentFromUsage(models.DockerContainerCPUCapacityPercent(ct, cpuCapacity))+ cpuPercent := percentFromReportedPercent(models.DockerContainerCPUCapacityPercent(ct, cpuCapacity))metrics.CPU = &MetricValue{Value: cpuPercent, Percent: cpuPercent, Unit: "percent", Source: SourceDocker}if ct.MemoryLimit > 0 {- percent := percentFromUsage(ct.MemoryPercent)+ percent := percentFromReportedPercent(ct.MemoryPercent)metrics.Memory = &MetricValue{Used: &ct.MemoryUsage, Total: &ct.MemoryLimit, Percent: percent, Unit: "bytes", Source: SourceDocker}}if ct.RootFilesystemBytes > 0 {@@ -646,7 +646,9 @@ func syntheticDockerContainerIOMetrics(ct models.DockerContainer) dockerContainestate := strings.ToLower(strings.TrimSpace(ct.State))running := state == "running" || state == "restarting"- activity := clampMetricValue((percentFromUsage(ct.CPUPercent)+percentFromUsage(ct.MemoryPercent))/180.0, 0.12, 1.25)+ cpuActivity := percentFromReportedPercent(models.DockerContainerCPUCapacityPercent(ct, 0))+ memoryActivity := percentFromReportedPercent(ct.MemoryPercent)+ activity := clampMetricValue((cpuActivity+memoryActivity)/180.0, 0.12, 1.25)if !running {activity = clampMetricValue(activity*0.32, 0.05, 0.45)}diff --git a/internal/unifiedresources/metrics_test.go b/internal/unifiedresources/metrics_test.goindex 94ce1c8830..f893a14133 100644--- a/internal/unifiedresources/metrics_test.go+++ b/internal/unifiedresources/metrics_test.go@@ -70,6 +70,23 @@ func TestMetricsFromDockerHostKeepsReportedPercentValues(t *testing.T) {}}+func TestMetricsFromDockerContainerKeepsCapacityPercentValues(t *testing.T) {+ container := models.DockerContainer{+ CPUPercent: 2,+ MemoryUsage: 5,+ MemoryLimit: 1000,+ MemoryPercent: 0.5,+ }++ metrics := metricsFromDockerContainer(container, 4)+ if metrics.CPU == nil || metrics.CPU.Percent != 0.5 || metrics.CPU.Value != 0.5 {+ t.Fatalf("expected docker container cpu percent 0.5, got %+v", metrics.CPU)+ }+ if metrics.Memory == nil || metrics.Memory.Percent != 0.5 {+ t.Fatalf("expected docker container memory percent 0.5, got %+v", metrics.Memory)+ }+}+func TestMetricsFromKubernetesClusterAggregatesLinkedHostReportedPercents(t *testing.T) {cluster := models.KubernetesCluster{ID: "cluster-1", Name: "cluster-1"}hosts := []*models.Host{