From f01375470e13e08920dcd8c750ccb2c83b15ce67 Mon Sep 17 00:00:00 2001 From: mrhid6 Date: Thu, 17 Sep 2026 08:52:21 +0000 Subject: [PATCH] fix(monitors): ignore partitions reporting more used than total --- server/internal/services/metricrules.go | 2 +- server/internal/services/metricrules_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/server/internal/services/metricrules.go b/server/internal/services/metricrules.go index 14aff7c..e8f70a3 100644 --- a/server/internal/services/metricrules.go +++ b/server/internal/services/metricrules.go @@ -109,7 +109,7 @@ func evalDisk(t models.MonitorTarget, parts []models.Partition) (bool, float64, var worstVal float64 var worstMsg string for _, p := range parts { - if p.TotalBytes == 0 || (t.Mount != "" && p.Mountpoint != t.Mount) { + if p.TotalBytes == 0 || p.UsedBytes > p.TotalBytes || (t.Mount != "" && p.Mountpoint != t.Mount) { continue } var breach bool diff --git a/server/internal/services/metricrules_test.go b/server/internal/services/metricrules_test.go index f62ad7b..af37d89 100644 --- a/server/internal/services/metricrules_test.go +++ b/server/internal/services/metricrules_test.go @@ -44,6 +44,7 @@ func TestEvaluateMetric(t *testing.T) { {"disk pct missing mount skips", models.MonitorTarget{Metric: MetricDiskPct, Threshold: 90, Mount: "/data"}, srvWith(disk), nil, false, false, ""}, {"disk free gb breaches", models.MonitorTarget{Metric: MetricDiskFreeGB, Threshold: 10}, srvWith(disk), nil, true, true, "GB free"}, {"zero total partition ignored", models.MonitorTarget{Metric: MetricDiskPct, Threshold: 1}, srvWith(models.Inventory{Partitions: []models.Partition{{Mountpoint: "/proc"}}}), nil, false, false, ""}, + {"used over total partition ignored", models.MonitorTarget{Metric: MetricDiskFreeGB, Threshold: 10}, srvWith(models.Inventory{Partitions: []models.Partition{{Mountpoint: "/", TotalBytes: 100e9, UsedBytes: 150e9}}}), nil, false, false, ""}, {"mem pct", models.MonitorTarget{Metric: MetricMemPct, Threshold: 80}, srvWith(models.Inventory{Memory: models.MemInfo{TotalBytes: 100, UsedBytes: 85}}), nil, true, true, "memory"}, {"load per core", models.MonitorTarget{Metric: MetricLoadPerCore, Threshold: 1.5}, srvWith(models.Inventory{CPU: models.CPUInfo{Cores: 4, Load1: 8}}), nil, true, true, "load"}, {"load no cores skips", models.MonitorTarget{Metric: MetricLoadPerCore, Threshold: 1.5}, srvWith(models.Inventory{CPU: models.CPUInfo{Load1: 8}}), nil, false, false, ""},