Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

Fix physical disk I/O metrics skipped when SMART data is empty (#1487)

rcourtman9d2df76b3f33
diff --git a/internal/monitoring/monitor_agents.go b/internal/monitoring/monitor_agents.go
index 58537ad6cc..a4e372a86a 100644
--- a/internal/monitoring/monitor_agents.go
+++ b/internal/monitoring/monitor_agents.go
@@ -2321,7 +2321,12 @@ func isLegacyUnraidEmptySlot(disk agentshost.UnraidDisk, normalizedStatus string
disk.SizeBytes == 0
}
-func hostDiskIOMetricResourceID(host models.Host, io models.DiskIO) string {
+type proxmoxDiskMatch struct {
+ device string
+ metricID string
+}
+
+func hostDiskIOMetricResourceID(host models.Host, io models.DiskIO, proxmoxDisks []proxmoxDiskMatch) string {
device := normalizeHostDiskDevice(io.Device)
if device == "" {
return ""
@@ -2336,20 +2341,34 @@ func hostDiskIOMetricResourceID(host models.Host, io models.DiskIO) string {
}
}
- return ""
+ for _, pd := range proxmoxDisks {
+ if pd.device == "" || pd.metricID == "" {
+ continue
+ }
+ if strings.EqualFold(pd.device, device) {
+ return pd.metricID
+ }
+ }
+
+ return fmt.Sprintf("%s:%s", strings.TrimSpace(host.ID), device)
}
func (m *Monitor) writeHostPhysicalDiskIOMetrics(host models.Host, now time.Time) {
if shouldSkipNativeMockStateMetricWrites() || (m.metricsHistory == nil && m.metricsStore == nil) {
return
}
- if len(host.DiskIO) == 0 || len(host.Sensors.SMART) == 0 {
+ if len(host.DiskIO) == 0 {
return
}
+ var proxmoxDisks []proxmoxDiskMatch
+ if host.LinkedNodeID != "" {
+ proxmoxDisks = m.proxmoxPhysicalDiskMatchesForLinkedNode(host.LinkedNodeID)
+ }
+
seenResourceIDs := make(map[string]struct{}, len(host.DiskIO))
for _, io := range host.DiskIO {
- resourceID := hostDiskIOMetricResourceID(host, io)
+ resourceID := hostDiskIOMetricResourceID(host, io, proxmoxDisks)
if resourceID == "" {
continue
}
@@ -2394,6 +2413,39 @@ func (m *Monitor) writeHostPhysicalDiskIOMetrics(host models.Host, now time.Time
}
}
+func (m *Monitor) proxmoxPhysicalDiskMatchesForLinkedNode(linkedNodeID string) []proxmoxDiskMatch {
+ if linkedNodeID == "" {
+ return nil
+ }
+ readState := m.GetUnifiedReadStateOrSnapshot()
+ if readState == nil {
+ return nil
+ }
+ var matches []proxmoxDiskMatch
+ for _, disk := range readState.PhysicalDisks() {
+ instance := strings.TrimSpace(disk.Instance())
+ node := strings.TrimSpace(disk.Node())
+ var diskLinkedID string
+ if instance == "" {
+ diskLinkedID = node
+ } else {
+ diskLinkedID = fmt.Sprintf("%s-%s", instance, node)
+ }
+ if diskLinkedID != linkedNodeID {
+ continue
+ }
+ metricID := strings.TrimSpace(disk.MetricResourceID())
+ if metricID == "" {
+ continue
+ }
+ matches = append(matches, proxmoxDiskMatch{
+ device: normalizeHostDiskDevice(disk.DevPath()),
+ metricID: metricID,
+ })
+ }
+ return matches
+}
+
// applyClusterSensors stores temperature data collected from Proxmox cluster
// siblings via SSH. Each entry is keyed by lowercase node name so that
// getHostAgentTemperatureByID can use it as a fallback.
diff --git a/internal/monitoring/monitor_host_agents_test.go b/internal/monitoring/monitor_host_agents_test.go
index e60cab05f5..2c021c04c1 100644
--- a/internal/monitoring/monitor_host_agents_test.go
+++ b/internal/monitoring/monitor_host_agents_test.go
@@ -1841,6 +1841,126 @@ func TestApplyHostReportPersistsPhysicalDiskIOMetricsForAgentDisks(t *testing.T)
}
}
+func TestApplyHostReportPersistsDiskIOMetricsWithoutSMART(t *testing.T) {
+ t.Helper()
+
+ storeCfg := metrics.DefaultConfig(t.TempDir())
+ storeCfg.WriteBufferSize = 1
+ store, err := metrics.NewStore(storeCfg)
+ if err != nil {
+ t.Fatalf("NewStore: %v", err)
+ }
+ defer store.Close()
+
+ monitor := &Monitor{
+ state: models.NewState(),
+ alertManager: alerts.NewManager(),
+ hostTokenBindings: make(map[string]string),
+ config: &config.Config{},
+ rateTracker: NewRateTracker(),
+ metricsHistory: NewMetricsHistory(1000, 24*time.Hour),
+ metricsStore: store,
+ }
+ t.Cleanup(func() { monitor.alertManager.Stop() })
+
+ baseReport := agentshost.Report{
+ Agent: agentshost.AgentInfo{
+ ID: "agent-pve3",
+ Version: "1.0.0",
+ IntervalSeconds: 30,
+ },
+ Host: agentshost.HostInfo{
+ ID: "host-pve3",
+ Hostname: "pve3",
+ MachineID: "machine-pve3",
+ },
+ Metrics: agentshost.Metrics{
+ Memory: agentshost.MemoryMetric{TotalBytes: 1024, UsedBytes: 512, FreeBytes: 512, Usage: 50},
+ },
+ DiskIO: []agentshost.DiskIO{
+ {
+ Device: "sda",
+ ReadBytes: 1_000_000,
+ WriteBytes: 2_000_000,
+ ReadOps: 100,
+ WriteOps: 200,
+ IOTime: 10_000,
+ },
+ },
+ Timestamp: time.Now().UTC(),
+ }
+
+ if _, err := monitor.ApplyHostReport(baseReport, nil); err != nil {
+ t.Fatalf("ApplyHostReport initial: %v", err)
+ }
+
+ nextReport := baseReport
+ nextReport.Timestamp = baseReport.Timestamp.Add(30 * time.Second)
+ nextReport.DiskIO = []agentshost.DiskIO{
+ {
+ Device: "sda",
+ ReadBytes: 4_000_000,
+ WriteBytes: 5_000_000,
+ ReadOps: 250,
+ WriteOps: 350,
+ IOTime: 22_000,
+ },
+ }
+
+ if _, err := monitor.ApplyHostReport(nextReport, nil); err != nil {
+ t.Fatalf("ApplyHostReport second: %v", err)
+ }
+ store.Flush()
+
+ fallbackID := "host-pve3:sda"
+
+ readPoints := waitForStoredDiskMetric(t, store, fallbackID, "diskread")
+ writePoints := waitForStoredDiskMetric(t, store, fallbackID, "diskwrite")
+ busyPoints := waitForStoredDiskMetric(t, store, fallbackID, "disk")
+
+ if got := readPoints[len(readPoints)-1].Value; got <= 0 {
+ t.Fatalf("expected persisted diskread rate > 0 without SMART, got %+v", readPoints)
+ }
+ if got := writePoints[len(writePoints)-1].Value; got <= 0 {
+ t.Fatalf("expected persisted diskwrite rate > 0 without SMART, got %+v", writePoints)
+ }
+ if got := busyPoints[len(busyPoints)-1].Value; got <= 0 || got > 100 {
+ t.Fatalf("expected persisted disk busy percent within (0,100] without SMART, got %+v", busyPoints)
+ }
+}
+
+func TestHostDiskIOMetricResourceIDFallbacks(t *testing.T) {
+ host := models.Host{
+ ID: "myhost",
+ Sensors: models.HostSensorSummary{
+ SMART: []models.HostDiskSMART{
+ {Device: "/dev/nvme0n1", Serial: "NVME-SERIAL-123"},
+ },
+ },
+ }
+
+ io := models.DiskIO{Device: "nvme0n1"}
+
+ got := hostDiskIOMetricResourceID(host, io, nil)
+ if got != "NVME-SERIAL-123" {
+ t.Fatalf("SMART match: expected NVME-SERIAL-123, got %q", got)
+ }
+
+ ioNoSMART := models.DiskIO{Device: "sda"}
+ got = hostDiskIOMetricResourceID(host, ioNoSMART, nil)
+ if got != "myhost:sda" {
+ t.Fatalf("no SMART, no proxmox: expected myhost:sda, got %q", got)
+ }
+
+ proxmoxDisks := []proxmoxDiskMatch{
+ {device: "sda", metricID: "SATA-SERIAL-456"},
+ }
+ got = hostDiskIOMetricResourceID(host, ioNoSMART, proxmoxDisks)
+ if got != "SATA-SERIAL-456" {
+ t.Fatalf("proxmox fallback: expected SATA-SERIAL-456, got %q", got)
+ }
+}
+
func TestApplyHostReportSkipsMetricsAndSMARTWritesInMockMode(t *testing.T) {
previous := mock.IsMockEnabled()
mustSetMockEnabled(t, true)