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
Restore physical disk node matching and unify the wearout sentinel
rcourtmanb254d0f19d1e
diff --git a/frontend-modern/src/components/Storage/__tests__/diskResourceUtils.test.ts b/frontend-modern/src/components/Storage/__tests__/diskResourceUtils.test.tsindex 1d81f10b31..4733bc71fc 100644--- a/frontend-modern/src/components/Storage/__tests__/diskResourceUtils.test.ts+++ b/frontend-modern/src/components/Storage/__tests__/diskResourceUtils.test.ts@@ -87,6 +87,34 @@ describe('diskResourceUtils', () => {).toBe(true);});+ it('keeps agent-reported disks attached to their Proxmox node without instance evidence', () => {+ // A host-agent SMART disk carries no Proxmox block at all, so it has no+ // instance to compare against the PVE node it physically lives on.+ const agentDisk = buildDisk({+ platformId: 'agent-tower',+ platformType: 'agent',+ sourceType: 'agent',+ platformData: { physicalDisk: { devPath: '/dev/sda' } } as never,+ });++ expect(+ matchesPhysicalDiskNode(agentDisk, {+ id: 'node-1',+ name: 'tower',+ instance: 'cluster-main',+ }),+ ).toBe(true);++ // Node identity still has to agree.+ expect(+ matchesPhysicalDiskNode(agentDisk, {+ id: 'node-2',+ name: 'other-node',+ instance: 'cluster-main',+ }),+ ).toBe(false);+ });+it('resolves physical disk metric targets through linked agents when needed', () => {expect(resolvePhysicalDiskMetricResourceId(buildDisk(), [buildNode()], '/dev/sda')).toBe('agent-tower:sda',diff --git a/frontend-modern/src/components/Storage/diskResourceUtils.ts b/frontend-modern/src/components/Storage/diskResourceUtils.tsindex b5ccb4bcbc..caf8e30eae 100644--- a/frontend-modern/src/components/Storage/diskResourceUtils.ts+++ b/frontend-modern/src/components/Storage/diskResourceUtils.ts@@ -48,11 +48,19 @@ export const matchesPhysicalDiskNode = (const diskInstance = normalize(diskIdentity.instance);const targetInstance = normalize(target.instance);- if (!diskInstance && !targetInstance) {++ // Host-agent SMART disks carry no Proxmox scope, so the disk side has no+ // instance to discriminate on and the matching node name is the only+ // evidence available. Requiring an instance here dropped agent-reported+ // disks on Proxmox nodes out of the node filter, grouping, and metric+ // target resolution entirely (#1487, #1516).+ if (!diskInstance) {return true;}- return Boolean(diskInstance && targetInstance && diskInstance === targetInstance);+ // A Proxmox-scoped disk only belongs to a node in the same instance. A node+ // with no instance is not that scope, so it must not absorb the disk.+ return Boolean(targetInstance && diskInstance === targetInstance);};export const resolvePhysicalDiskMetricResourceId = (diff --git a/frontend-modern/src/components/shared/__tests__/webInterfaceUrlFieldModel.branchcov0712.test.ts b/frontend-modern/src/components/shared/__tests__/webInterfaceUrlFieldModel.branchcov0712.test.tsindex 3c159f0eea..b1ca5b1c89 100644--- a/frontend-modern/src/components/shared/__tests__/webInterfaceUrlFieldModel.branchcov0712.test.ts+++ b/frontend-modern/src/components/shared/__tests__/webInterfaceUrlFieldModel.branchcov0712.test.ts@@ -21,13 +21,11 @@ describe('webInterfaceUrlFieldModel.branchcov2', () => {);});- it('returns the parse-failure message for a whitespace-only value (truthy string that URL rejects)', () => {- // ' ' is a truthy string so it bypasses the `!value` guard but still- // throws inside `new URL(...)`, exercising the catch arm via a different- // inbound state than a plain word.- expect(validateWebInterfaceCustomUrl(' ')).toBe(- 'Enter a valid URL (for example: https://198.51.100.100:8080).',- );+ it('treats a whitespace-only value as empty rather than invalid', () => {+ // The field trims before classifying, so a value of only spaces is the+ // same inbound state as a cleared field. Nagging "enter a valid URL" at+ // someone who has just emptied the box is noise, not validation.+ expect(validateWebInterfaceCustomUrl(' ')).toBeNull();});it('returns the parse-failure message for a bare scheme like "http://" (URL constructor throws)', () => {diff --git a/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.branchcov.test.ts b/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.branchcov.test.tsindex 4b7a278ee4..6fd31f8757 100644--- a/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.branchcov.test.ts+++ b/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.branchcov.test.ts@@ -586,11 +586,23 @@ describe('getPhysicalDiskHealthStatus branch coverage', () => {expect(status.summary).toBe('No active disk-health issues.');});- it('does not classify wearout of 0 as low life (unreported boundary)', () => {+ it('classifies wearout of 0 on an SSD as low life (no endurance remaining)', () => {+ const disk = makeDiskData({ health: 'PASSED', wearout: 0, type: 'ssd' });+ expect(getPhysicalDiskHealthStatus(disk).label).toBe('Needs Attention');+ });++ it('does not classify wearout of 0 on a disk that reports no endurance as low life', () => {+ // Rotational and untyped disks never report endurance, so a 0 from one is+ // absent evidence rather than a spent disk.const disk = makeDiskData({ health: 'PASSED', wearout: 0 });expect(getPhysicalDiskHealthStatus(disk).label).toBe('Healthy');});+ it('does not classify the unreported wearout sentinel -1 as low life', () => {+ const disk = makeDiskData({ health: 'PASSED', wearout: -1, type: 'ssd' });+ expect(getPhysicalDiskHealthStatus(disk).label).toBe('Healthy');+ });+it('does not classify wearout of exactly 10 as low life (upper boundary)', () => {const disk = makeDiskData({ health: 'PASSED', wearout: 10 });expect(getPhysicalDiskHealthStatus(disk).label).toBe('Healthy');diff --git a/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.branchcov0712b.test.ts b/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.branchcov0712b.test.tsindex 34007257af..73a382b439 100644--- a/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.branchcov0712b.test.ts+++ b/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.branchcov0712b.test.ts@@ -323,12 +323,18 @@ describe('getPhysicalDiskLifeTextClass (branchcov2)', () => {);});- it('returns the muted placeholder class for wearout 0 (<= 0 branch)', () => {+ it('returns the muted placeholder class for wearout 0 on a disk that reports no endurance', () => {expect(getPhysicalDiskLifeTextClass(makeDiskData({ wearout: 0 }))).toBe(PHYSICAL_DISK_MUTED_PLACEHOLDER_CLASS,);});+ it('returns the critical class for wearout 0 on an SSD (no endurance remaining)', () => {+ expect(getPhysicalDiskLifeTextClass(makeDiskData({ wearout: 0, type: 'ssd' }))).toBe(+ 'text-red-600 dark:text-red-400',+ );+ });+it('returns the muted placeholder class when wearout is not a number', () => {expect(getPhysicalDiskLifeTextClass(makeDiskData({ wearout: 'nope' as unknown as number })),diff --git a/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.branchcov0720pm.test.ts b/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.branchcov0720pm.test.tsindex 86f0d39d1d..70d1ddba9a 100644--- a/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.branchcov0720pm.test.ts+++ b/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.branchcov0720pm.test.ts@@ -489,12 +489,24 @@ describe('diskPresentation.branchcov0720pm', () => {});describe('getPhysicalDiskLifeTextClass muted placeholder arm', () => {- it('returns the muted placeholder class when wearout is 0', () => {+ it('returns the muted placeholder class when wearout is 0 on a disk that reports no endurance', () => {expect(getPhysicalDiskLifeTextClass(makeDiskData({ wearout: 0 }))).toBe(PHYSICAL_DISK_MUTED_PLACEHOLDER_CLASS,);});+ it('returns the critical class when an SSD reports wearout 0', () => {+ expect(getPhysicalDiskLifeTextClass(makeDiskData({ wearout: 0, type: 'nvme' }))).toBe(+ 'text-red-600 dark:text-red-400',+ );+ });++ it('returns the muted placeholder class for the unreported sentinel -1', () => {+ expect(getPhysicalDiskLifeTextClass(makeDiskData({ wearout: -1, type: 'nvme' }))).toBe(+ PHYSICAL_DISK_MUTED_PLACEHOLDER_CLASS,+ );+ });+it('returns the muted placeholder class when wearout is not a number', () => {expect(getPhysicalDiskLifeTextClass(makeDiskData({ wearout: 'nan' as unknown as number })),diff --git a/frontend-modern/src/features/storageBackups/diskPresentation.ts b/frontend-modern/src/features/storageBackups/diskPresentation.tsindex 54e00408a7..1fbffd4738 100644--- a/frontend-modern/src/features/storageBackups/diskPresentation.ts+++ b/frontend-modern/src/features/storageBackups/diskPresentation.ts@@ -542,7 +542,7 @@ export function getPhysicalDiskHealthStatus(const criticalRisk = (disk.riskLevel || '').trim().toLowerCase() === 'critical';const warningRisk = (disk.riskLevel || '').trim().toLowerCase() === 'warning';const smartWarning = hasPhysicalDiskSmartWarning(disk);- const lowLife = disk.wearout >= 0 && disk.wearout < 10;+ const lowLife = isPhysicalDiskWearoutReported(disk) && disk.wearout < 10;if (normalizedHealth === 'FAILED' || criticalRisk) {return {@@ -632,14 +632,24 @@ export function getPhysicalDiskParentLabel(disk: PhysicalDiskPresentationData):return '';}+// Mirrors storagehealth.WearoutReported on the backend. Wearout is "% life+// remaining" (100 = new). -1 is the unreported sentinel, and 0 is a real+// reading only from a device that reports endurance at all, so a 0 from a+// rotational disk is absent evidence rather than a spent disk.+export function isPhysicalDiskWearoutReported(disk: PhysicalDiskPresentationData): boolean {+ if (typeof disk.wearout !== 'number') return false;+ if (disk.wearout > 0) return true;+ const normalizedType = (disk.type || '').trim().toLowerCase();+ return disk.wearout === 0 && (normalizedType === 'nvme' || normalizedType === 'ssd');+}+export function getPhysicalDiskLifeLabel(disk: PhysicalDiskPresentationData): string {- // Wearout is "% life remaining" (100 = new); only negative values are unreported.if (typeof disk.wearout !== 'number' || disk.wearout < 0) return '';return `${Math.min(disk.wearout, 100)}%`;}export function getPhysicalDiskLifeTextClass(disk: PhysicalDiskPresentationData): string {- if (typeof disk.wearout !== 'number' || disk.wearout < 0) {+ if (!isPhysicalDiskWearoutReported(disk)) {return PHYSICAL_DISK_MUTED_PLACEHOLDER_CLASS;}if (disk.wearout < 20) return 'text-red-600 dark:text-red-400';diff --git a/internal/alerts/disk_health.go b/internal/alerts/disk_health.goindex e6e147f216..eea484d24c 100644--- a/internal/alerts/disk_health.go+++ b/internal/alerts/disk_health.go@@ -119,8 +119,11 @@ func (m *Manager) CheckDiskHealth(instance, node string, disk proxmox.Disk) {clearDiskAlert(alertID, canonicalHealthAlertID)}- // Check for low wearout (SSD life remaining)- if disk.Wearout > 0 && disk.Wearout < 10 {+ // Check for low wearout (SSD life remaining). Gate on the same predicate+ // the risk assessment uses so a disk cannot read critical in the UI while+ // staying silent here: 0 from an SSD means no endurance left and must+ // alert, while -1 and a rotational 0 are absent evidence.+ if storagehealth.WearoutReported(disk.Wearout, disk.Type) && disk.Wearout < 10 {message := fmt.Sprintf("SSD has less than 10%% life remaining (%d%% wearout)", disk.Wearout)spec, err := buildCanonicalSeverityThresholdSpecWithDirection(canonicalResourceID+"-wearout", canonicalResourceID, resourceName, resourceType, "wearout-remaining", alertspecs.ThresholdDirectionBelow, 10, 0, false)if err != nil {diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.goindex f209288c8c..bf95d88e3c 100644--- a/internal/monitoring/monitor.go+++ b/internal/monitoring/monitor.go@@ -716,7 +716,9 @@ func deriveWearoutFromSMARTAttributes(attrs *models.SMARTAttributes) int {func physicalDiskFromReadStateView(view *unifiedresources.PhysicalDiskView) models.PhysicalDisk {if view == nil {- return models.PhysicalDisk{}+ // Wearout 0 means no endurance remaining, so an absent view has to+ // carry the unreported sentinel rather than the struct zero value.+ return models.PhysicalDisk{Wearout: unifiedresources.WearoutUnreported}}return models.PhysicalDisk{diff --git a/internal/storagehealth/risk.go b/internal/storagehealth/risk.goindex dc840ddf3b..49e6333dcd 100644--- a/internal/storagehealth/risk.go+++ b/internal/storagehealth/risk.go@@ -52,9 +52,8 @@ func AssessPhysicalDisk(disk models.PhysicalDisk) Assessment {Model: disk.Model,Health: disk.Health,Temperature: disk.Temperature,- Wearout: disk.Wearout,- WearoutKnown: disk.Wearout > 0 ||- (disk.Wearout == 0 && isNonRotationalDiskType(disk.Type)),+ Wearout: disk.Wearout,+ WearoutKnown: WearoutReported(disk.Wearout, disk.Type),}if attrs := disk.SmartAttributes; attrs != nil {if attrs.PowerOnHours != nil {@@ -230,6 +229,19 @@ func RemainingLifeFromPercentageUsed(used int) int {return 100 - used}+// WearoutReported reports whether a wearout reading is real evidence rather+// than an absent value. -1 is the canonical unreported sentinel. 0 is a real+// reading meaning no endurance remains, but only from a device that reports+// endurance at all: rotational disks never do, so a 0 from one is treated as+// absent. Every consumer of wearout must gate on this rather than reinventing+// the boundary, or the UI and alerting drift apart on the same disk.+func WearoutReported(wearout int, diskType string) bool {+ if wearout > 0 {+ return true+ }+ return wearout == 0 && isNonRotationalDiskType(diskType)+}+func isNonRotationalDiskType(diskType string) bool {switch strings.ToLower(strings.TrimSpace(diskType)) {case "nvme", "ssd":diff --git a/internal/unifiedresources/physical_disk_risk.go b/internal/unifiedresources/physical_disk_risk.goindex 75f50908c2..8ac5eb6587 100644--- a/internal/unifiedresources/physical_disk_risk.go+++ b/internal/unifiedresources/physical_disk_risk.go@@ -83,9 +83,8 @@ func physicalDiskAssessmentFromMeta(meta *PhysicalDiskMeta) storagehealth.AssessModel: meta.Model,Health: meta.Health,Temperature: meta.Temperature,- Wearout: meta.Wearout,- WearoutKnown: meta.Wearout > 0 ||- (meta.Wearout == 0 && physicalDiskTypeIsNonRotational(meta.DiskType)),+ Wearout: meta.Wearout,+ WearoutKnown: storagehealth.WearoutReported(meta.Wearout, meta.DiskType),}if meta.SMART != nil {if meta.SMART.PowerOnHours != nil {@@ -130,15 +129,6 @@ func physicalDiskAssessmentFromMeta(meta *PhysicalDiskMeta) storagehealth.Assessreturn storagehealth.AssessSample(sample)}-func physicalDiskTypeIsNonRotational(diskType string) bool {- switch strings.ToLower(strings.TrimSpace(diskType)) {- case "nvme", "ssd":- return true- default:- return false- }-}-func physicalDiskStatus(model, health string, assessment storagehealth.Assessment) ResourceStatus {switch assessment.Level {case storagehealth.RiskCritical, storagehealth.RiskWarning:diff --git a/internal/unifiedresources/types.go b/internal/unifiedresources/types.goindex b84c5ff2b6..2973056bbf 100644--- a/internal/unifiedresources/types.go+++ b/internal/unifiedresources/types.go@@ -469,6 +469,11 @@ type PoolHealth struct {ObservedAt time.Time `json:"observedAt,omitempty"`}+// WearoutUnreported is the canonical sentinel for PhysicalDiskMeta.Wearout when+// a disk reports no endurance evidence. 0 is a real value meaning no endurance+// remaining, so unknown must never collapse onto it.+const WearoutUnreported = -1+// PhysicalDiskMeta contains physical disk-specific metadata.type PhysicalDiskMeta struct {DevPath string `json:"devPath"`diff --git a/internal/unifiedresources/views.go b/internal/unifiedresources/views.goindex e22d56e7bf..b760af91d3 100644--- a/internal/unifiedresources/views.go+++ b/internal/unifiedresources/views.go@@ -2118,8 +2118,10 @@ func (v PhysicalDiskView) Health() string {}func (v PhysicalDiskView) Wearout() int {+ // -1 is the canonical unreported sentinel for this field. Returning 0 here+ // published "0% endurance remaining" for a disk that reported nothing.if v.r == nil || v.r.PhysicalDisk == nil {- return 0+ return WearoutUnreported}return v.r.PhysicalDisk.Wearout}