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 disk metric spikes when guest agent intermittently fails (#1319)

rcourtmanabbd0df6091e
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go
index e840f7bd60..a485e11929 100644
--- a/internal/monitoring/monitor.go
+++ b/internal/monitoring/monitor.go
@@ -7218,6 +7218,16 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
}
}
+ // Build a lookup for previous disk data so we can carry it forward when the
+ // guest agent call fails (prevents disk usage flickering 57% → 0% → 57%).
+ // Refs: #1319
+ prevDiskByGuestID := make(map[string]models.Disk, len(prevInstanceVMs))
+ for _, pvm := range prevInstanceVMs {
+ if pvm.Disk.Usage > 0 {
+ prevDiskByGuestID[pvm.ID] = pvm.Disk
+ }
+ }
+
var allVMs []models.VM
var allContainers []models.Container
@@ -7738,6 +7748,29 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
})
}
+ // Carry forward previous disk data when the guest agent was expected
+ // but failed to provide data this cycle. Proxmox cluster/resources
+ // always returns 0 for VM disk, so without the guest agent we'd show
+ // 0% or "allocated only", causing chart spikes when the agent
+ // intermittently times out. Refs: #1319
+ // Also triggers when GetVMStatus itself failed (agentEnabled stays
+ // false but the VM had real disk data last cycle).
+ if res.Status == "running" && res.Type == "qemu" && diskUsage <= 0 {
+ if prev, ok := prevDiskByGuestID[guestID]; ok && prev.Usage > 0 && prev.Total > 0 && prev.Used >= 0 && prev.Used <= prev.Total {
+ diskTotal = uint64(prev.Total)
+ diskUsed = uint64(prev.Used)
+ diskFree = diskTotal - diskUsed
+ diskUsage = prev.Usage
+ individualDisks = nil // Don't carry forward stale per-disk breakdown
+ log.Debug().
+ Str("instance", instanceName).
+ Str("vm", res.Name).
+ Int("vmid", res.VMID).
+ Float64("prevUsage", prev.Usage).
+ Msg("Guest agent disk query failed; carrying forward previous disk data")
+ }
+ }
+
// Last-chance MemInfo fallback: use Total-Used only after RRD/agent
// attempts, so those more reliable cache-aware sources get priority.
if res.Status == "running" && memAvailable == 0 && memInfoTotalMinusUsed > 0 {
diff --git a/internal/monitoring/monitor_polling.go b/internal/monitoring/monitor_polling.go
index 1a540c0bc0..0ccedcecfe 100644
--- a/internal/monitoring/monitor_polling.go
+++ b/internal/monitoring/monitor_polling.go
@@ -220,6 +220,14 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, clu
// a memory fallback before the inflated status.Mem value. Refs: #1270
prevState := m.GetState()
prevInstanceVMs := filterVMsByInstance(prevState.VMs, instanceName)
+ // Build a lookup for previous disk data so we can carry it forward when the
+ // guest agent call fails (prevents disk usage flickering 57% → 0% → 57%).
+ prevDiskByGuestID := make(map[string]models.Disk, len(prevInstanceVMs))
+ for _, pvm := range prevInstanceVMs {
+ if pvm.Disk.Usage > 0 {
+ prevDiskByGuestID[pvm.ID] = pvm.Disk
+ }
+ }
vmIDToHostAgent := make(map[string]models.Host)
for _, h := range prevState.Hosts {
if h.LinkedVMID != "" && h.Status == "online" && h.Memory.Total > 0 {
@@ -766,6 +774,33 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, clu
diskStatusReason = "no-status"
}
+ // Carry forward previous disk data when the guest agent failed this cycle.
+ // Proxmox cluster/resources always returns 0 for disk usage, so without
+ // the guest agent we'd show 0% or "allocated only", causing chart spikes
+ // when the agent intermittently times out. Refs: #1319
+ // Only carry forward for transient failures — not when the agent is
+ // permanently disabled or absent, as those won't self-resolve.
+ if vm.Status == "running" && diskUsage <= 0 && diskStatusReason != "" &&
+ diskStatusReason != "vm-stopped" && diskStatusReason != "agent-disabled" && diskStatusReason != "no-agent" {
+ if prev, ok := prevDiskByGuestID[guestID]; ok && prev.Usage > 0 && prev.Total > 0 && prev.Used >= 0 && prev.Used <= prev.Total {
+ diskTotal = uint64(prev.Total)
+ diskUsed = uint64(prev.Used)
+ diskFree = diskTotal - diskUsed
+ diskUsage = prev.Usage
+ individualDisks = nil // Don't carry forward stale per-disk breakdown
+ if logging.IsLevelEnabled(zerolog.DebugLevel) {
+ log.Debug().
+ Str("instance", instanceName).
+ Str("vm", vm.Name).
+ Int("vmid", vm.VMID).
+ Str("reason", diskStatusReason).
+ Float64("prevUsage", prev.Usage).
+ Msg("Guest agent disk query failed; carrying forward previous disk data")
+ }
+ diskStatusReason = "prev-" + diskStatusReason
+ }
+ }
+
memTotalBytes := clampToInt64(memTotal)
memUsedBytes := clampToInt64(memUsed)
if memTotalBytes > 0 && memUsedBytes > memTotalBytes {