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
Normalize physical disk endurance evidence
rcourtman8c341753ae89
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 95af0739ef..eea1b9b020 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -118,6 +118,9 @@ identifiers, preserves explicit failure over a later coarse healthy value, andlets explicit SMART endurance replace contradictory Proxmox wearout. Missingpermission, ambiguous identity, standby, and absent SMART fields remainneutral rather than borrowing telemetry from another disk.+Negative percentage-used counters remain unknown; values above 100 clamp to+exhausted before deriving remaining life, so invalid or over-limit controller+data cannot wrap into a fabricated healthy value.## Canonical Filesdiff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.mdindex 705e6529cf..e691418475 100644--- a/docs/release-control/v6/internal/subsystems/unified-resources.md+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md@@ -46,6 +46,9 @@ missing. The canonical disk payload also carries provider vendor metadata anduses explicit SMART health, temperature, and wearout ahead of coarsercontradictory inventory values without manufacturing facts when telemetry isabsent.+NVMe percentage-used conversion is shared with storage risk: negative values+remain unknown, while values above 100 clamp to exhausted before remaining+life is derived.## Canonical Filesdiff --git a/internal/monitoring/canonical_guardrails_test.go b/internal/monitoring/canonical_guardrails_test.goindex e446bc6efa..5ed57ab1c2 100644--- a/internal/monitoring/canonical_guardrails_test.go+++ b/internal/monitoring/canonical_guardrails_test.go@@ -2138,6 +2138,7 @@ func TestProxmoxDiskAlertsRunOnMergedDiskState(t *testing.T) {snippets: []string{"func mergeHostAgentSMARTIntoDisks(disks []models.PhysicalDisk, nodes []models.Node, hosts []models.Host) []models.PhysicalDisk {","deriveWearoutFromSMARTAttributes(matched.Attributes)",+ "storagehealth.RemainingLifeFromPercentageUsed(*attrs.PercentageUsed)","shouldUseHostAgentPhysicalDiskHealth(updated[i].Health, matched.Health)",`if incoming == "FAILED"`,},diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.goindex ab2d108cde..4df5f96b67 100644--- a/internal/monitoring/monitor.go+++ b/internal/monitoring/monitor.go@@ -26,6 +26,7 @@ import ("github.com/rcourtman/pulse-go-rewrite/internal/monitoring/errors""github.com/rcourtman/pulse-go-rewrite/internal/notifications"recoverymanager "github.com/rcourtman/pulse-go-rewrite/internal/recovery/manager"+ "github.com/rcourtman/pulse-go-rewrite/internal/storagehealth""github.com/rcourtman/pulse-go-rewrite/internal/system""github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources""github.com/rcourtman/pulse-go-rewrite/internal/websocket"@@ -730,15 +731,7 @@ func deriveWearoutFromSMARTAttributes(attrs *models.SMARTAttributes) int {if attrs == nil || attrs.PercentageUsed == nil {return -1}-- used := *attrs.PercentageUsed- if used < 0 {- used = 0- }- if used > 100 {- used = 100- }- return 100 - used+ return storagehealth.RemainingLifeFromPercentageUsed(*attrs.PercentageUsed)}func physicalDiskFromReadStateView(view *unifiedresources.PhysicalDiskView) models.PhysicalDisk {diff --git a/internal/storagehealth/risk.go b/internal/storagehealth/risk.goindex 35bdd1adf5..dc840ddf3b 100644--- a/internal/storagehealth/risk.go+++ b/internal/storagehealth/risk.go@@ -77,8 +77,13 @@ func AssessPhysicalDisk(disk models.PhysicalDisk) Assessment {}if attrs.PercentageUsed != nil {sample.PercentageUsed = *attrs.PercentageUsed- sample.Wearout = 100 - *attrs.PercentageUsed- sample.WearoutKnown = true+ if remaining := RemainingLifeFromPercentageUsed(*attrs.PercentageUsed); remaining >= 0 {+ sample.Wearout = remaining+ sample.WearoutKnown = true+ } else {+ sample.Wearout = -1+ sample.WearoutKnown = false+ }}if attrs.AvailableSpare != nil {sample.AvailableSpare = *attrs.AvailableSpare@@ -122,8 +127,13 @@ func AssessHostSMARTDisk(disk models.HostDiskSMART) Assessment {}if attrs.PercentageUsed != nil {sample.PercentageUsed = *attrs.PercentageUsed- sample.Wearout = 100 - *attrs.PercentageUsed- sample.WearoutKnown = true+ if remaining := RemainingLifeFromPercentageUsed(*attrs.PercentageUsed); remaining >= 0 {+ sample.Wearout = remaining+ sample.WearoutKnown = true+ } else {+ sample.Wearout = -1+ sample.WearoutKnown = false+ }}if attrs.AvailableSpare != nil {sample.AvailableSpare = *attrs.AvailableSpare@@ -207,6 +217,19 @@ func AssessSample(sample Sample) Assessment {return assessment}+// RemainingLifeFromPercentageUsed converts the NVMe percentage-used counter+// into Pulse's remaining-life representation. Negative controller values are+// invalid and stay unknown; values above 100 mean endurance is exhausted.+func RemainingLifeFromPercentageUsed(used int) int {+ if used < 0 {+ return -1+ }+ if used > 100 {+ used = 100+ }+ return 100 - used+}+func isNonRotationalDiskType(diskType string) bool {switch strings.ToLower(strings.TrimSpace(diskType)) {case "nvme", "ssd":diff --git a/internal/storagehealth/risk_test.go b/internal/storagehealth/risk_test.goindex af5b55bff8..4f8ab6e731 100644--- a/internal/storagehealth/risk_test.go+++ b/internal/storagehealth/risk_test.go@@ -156,6 +156,54 @@ func TestAssessPhysicalDisk_PercentageUsedProvesZeroLifeOnSATASSD(t *testing.T)}}+func TestAssessPhysicalDisk_ReportedZeroWearoutUsesMediaType(t *testing.T) {+ if assessment := AssessPhysicalDisk(models.PhysicalDisk{+ Type: "nvme",+ Health: "PASSED",+ Wearout: 0,+ }); assessment.Level != RiskCritical {+ t.Fatalf("reported NVMe wearout=0 should be critical, got %+v", assessment)+ }+ if assessment := AssessPhysicalDisk(models.PhysicalDisk{+ Type: "sata",+ Health: "PASSED",+ Wearout: 0,+ }); assessment.Level != RiskHealthy {+ t.Fatalf("SATA transport without endurance evidence should remain neutral, got %+v", assessment)+ }+}++func TestRemainingLifeFromPercentageUsedClampsControllerValues(t *testing.T) {+ for _, test := range []struct {+ used int+ want int+ }{+ {used: -4, want: -1},+ {used: 0, want: 100},+ {used: 95, want: 5},+ {used: 100, want: 0},+ {used: 143, want: 0},+ } {+ if got := RemainingLifeFromPercentageUsed(test.used); got != test.want {+ t.Fatalf("RemainingLifeFromPercentageUsed(%d) = %d, want %d", test.used, got, test.want)+ }+ }+}++func TestAssessPhysicalDisk_InvalidPercentageUsedRemainsUnknown(t *testing.T) {+ percentageUsed := -4+ assessment := AssessPhysicalDisk(models.PhysicalDisk{+ Type: "nvme",+ SmartAttributes: &models.SMARTAttributes{+ PercentageUsed: &percentageUsed,+ },+ })++ if assessment.Level != RiskHealthy || len(assessment.Reasons) != 0 {+ t.Fatalf("invalid percentage used should remain neutral, got %+v", assessment)+ }+}+func TestAssessSample_WearoutWarning(t *testing.T) {assessment := AssessSample(Sample{Health: "PASSED",diff --git a/internal/unifiedresources/adapters.go b/internal/unifiedresources/adapters.goindex 983039723d..21f43ff3b3 100644--- a/internal/unifiedresources/adapters.go+++ b/internal/unifiedresources/adapters.go@@ -885,14 +885,7 @@ func physicalDiskWearoutFromSMARTAttributes(attrs *models.SMARTAttributes) int {if attrs == nil || attrs.PercentageUsed == nil {return -1}- used := *attrs.PercentageUsed- if used < 0 {- used = 0- }- if used > 100 {- used = 100- }- return 100 - used+ return storagehealth.RemainingLifeFromPercentageUsed(*attrs.PercentageUsed)}func hostUnraidStorageIdentity(host models.Host) string {diff --git a/internal/unifiedresources/adapters_test.go b/internal/unifiedresources/adapters_test.goindex 555bc82024..64f2a21399 100644--- a/internal/unifiedresources/adapters_test.go+++ b/internal/unifiedresources/adapters_test.go@@ -1778,3 +1778,13 @@ func TestCollectInterfaceIDsAllVirtualStillCollects(t *testing.T) {t.Fatalf("expected virtual-only host to keep its address, got %v", ips)}}++func TestPhysicalDiskWearoutFromSMARTAttributesClampsExhaustedMedia(t *testing.T) {+ percentageUsed := 143+ got := physicalDiskWearoutFromSMARTAttributes(&models.SMARTAttributes{+ PercentageUsed: &percentageUsed,+ })+ if got != 0 {+ t.Fatalf("wearout remaining = %d, want 0 for percentage-used above 100", got)+ }+}diff --git a/internal/unifiedresources/physical_disk_risk.go b/internal/unifiedresources/physical_disk_risk.goindex 1c94883d93..75f50908c2 100644--- a/internal/unifiedresources/physical_disk_risk.go+++ b/internal/unifiedresources/physical_disk_risk.go@@ -108,8 +108,13 @@ func physicalDiskAssessmentFromMeta(meta *PhysicalDiskMeta) storagehealth.Assess}if meta.SMART.PercentageUsed != nil {sample.PercentageUsed = *meta.SMART.PercentageUsed- sample.Wearout = 100 - *meta.SMART.PercentageUsed- sample.WearoutKnown = true+ if remaining := storagehealth.RemainingLifeFromPercentageUsed(*meta.SMART.PercentageUsed); remaining >= 0 {+ sample.Wearout = remaining+ sample.WearoutKnown = true+ } else {+ sample.Wearout = -1+ sample.WearoutKnown = false+ }}if meta.SMART.AvailableSpare != nil {sample.AvailableSpare = *meta.SMART.AvailableSparediff --git a/internal/unifiedresources/physical_disk_risk_test.go b/internal/unifiedresources/physical_disk_risk_test.goindex 1065276431..28087ea2f2 100644--- a/internal/unifiedresources/physical_disk_risk_test.go+++ b/internal/unifiedresources/physical_disk_risk_test.go@@ -175,6 +175,37 @@ func TestPhysicalDiskAssessmentFromMeta_PercentageUsedProvesZeroLifeOnSATASSD(t}}+func TestPhysicalDiskAssessmentFromMeta_ReportedZeroWearoutUsesMediaType(t *testing.T) {+ if assessment := physicalDiskAssessmentFromMeta(&PhysicalDiskMeta{+ DiskType: "ssd",+ Health: "PASSED",+ Wearout: 0,+ }); assessment.Level != storagehealth.RiskCritical {+ t.Fatalf("reported SSD wearout=0 should be critical, got %+v", assessment)+ }+ if assessment := physicalDiskAssessmentFromMeta(&PhysicalDiskMeta{+ DiskType: "sata",+ Health: "PASSED",+ Wearout: 0,+ }); assessment.Level != storagehealth.RiskHealthy {+ t.Fatalf("SATA transport without endurance evidence should remain neutral, got %+v", assessment)+ }+}++func TestPhysicalDiskAssessmentFromMeta_InvalidPercentageUsedRemainsUnknown(t *testing.T) {+ percentageUsed := -4+ meta := &PhysicalDiskMeta{+ DiskType: "nvme",+ SMART: &SMARTMeta{+ PercentageUsed: &percentageUsed,+ },+ }+ assessment := physicalDiskAssessmentFromMeta(meta)+ if assessment.Level != storagehealth.RiskHealthy || len(assessment.Reasons) != 0 {+ t.Fatalf("invalid percentage used should remain neutral, got %+v", assessment)+ }+}+// --- physicalDiskStatus ---func TestPhysicalDiskStatus_CriticalAssessment(t *testing.T) {diff --git a/internal/unifiedresources/registry_test.go b/internal/unifiedresources/registry_test.goindex 73b51bdb79..aac128b023 100644--- a/internal/unifiedresources/registry_test.go+++ b/internal/unifiedresources/registry_test.go@@ -5241,3 +5241,42 @@ func TestIngestRecordsSkipRecordDeclaredSuccessionForLiveOldID(t *testing.T) {t.Fatalf("expected operator state to stay under live old ID (found=%v err=%v)", found, err)}}++func TestResourceRegistryClampsExhaustedSMARTWearout(t *testing.T) {+ percentageUsed := 143+ registry := NewRegistry(nil)+ registry.IngestSnapshot(models.StateSnapshot{+ Hosts: []models.Host{+ {+ ID: "host-exhausted",+ Hostname: "pve-exhausted",+ Status: "online",+ Sensors: models.HostSensorSummary{+ SMART: []models.HostDiskSMART{+ {+ Device: "/dev/nvme0n1",+ Model: "Example NVMe",+ Serial: "EXHAUSTED-NVME",+ Type: "nvme",+ Health: "PASSED",+ Attributes: &models.SMARTAttributes{+ PercentageUsed: &percentageUsed,+ },+ },+ },+ },+ },+ },+ })++ disks := registry.ListByType(ResourceTypePhysicalDisk)+ if len(disks) != 1 || disks[0].PhysicalDisk == nil {+ t.Fatalf("expected one physical disk, got %+v", disks)+ }+ if disks[0].PhysicalDisk.Wearout != 0 {+ t.Fatalf("wearout remaining = %d, want 0", disks[0].PhysicalDisk.Wearout)+ }+ if risk := disks[0].PhysicalDisk.Risk; risk == nil || risk.Level != storagehealth.RiskCritical {+ t.Fatalf("exhausted media risk = %+v, want critical", risk)+ }+}