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
Stabilize transient Proxmox VM disk fallbacks
rcourtmand2f8300d655e
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 3cb0ececfc..e026636707 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -45,6 +45,7 @@ truth for live infrastructure data.21. `internal/monitoring/monitor_polling_vm.go`22. `internal/monitoring/monitor_pve_guest_builders.go`23. `internal/monitoring/monitor_pve_guest_poll.go`+24. `internal/monitoring/guest_disk_stability.go`## Shared Boundaries@@ -431,6 +432,13 @@ signal is sufficient healthy evidence for that decision even before disk ornetwork enrichment finishes, and the preserved result must be recorded with anexplicit snapshot note so diagnostics can distinguish deliberate stabilizationfrom ordinary fallback.+Guest-disk continuity now follows the same canonical rule. The shared VM+polling paths must classify guest-agent disk failures consistently, surface the+resulting disk-status reason on the VM model, and only carry forward previous+disk usage when the last VM snapshot is still recent guest-agent truth rather+than an already carried-forward fallback. That keeps transient guest-agent or+status-call failures from regressing a VM back to misleading allocated-disk+data while still avoiding indefinite replay of stale disk summaries.That compatibility boundary also applies to historical snapshot labels that maystill exist in tests, live in-memory state, or pre-canonical diagnostic paths:legacy aliases such as `rrd-available`, `rrd-data`, `node-status-available`,diff --git a/internal/monitoring/canonical_guardrails_test.go b/internal/monitoring/canonical_guardrails_test.goindex 921fc97367..a50188abd0 100644--- a/internal/monitoring/canonical_guardrails_test.go+++ b/internal/monitoring/canonical_guardrails_test.go@@ -188,6 +188,38 @@ func TestProxmoxGuestMemoryCarryForwardUsesCanonicalSnapshotStability(t *testing}}+func TestProxmoxGuestDiskCarryForwardUsesCanonicalStabilityHelper(t *testing.T) {+ requiredSnippets := map[string][]string{+ "guest_disk_stability.go": {+ "func stabilizeGuestLowTrustDisk(",+ "func classifyGuestAgentDiskStatusError(err error) string {",+ `return total, used, free, prev.Disk.Usage, cloneGuestDisks(prev.Disks), "prev-" + diskStatusReason`,+ },+ "monitor_pve_guest_builders.go": {+ "state.diskTotal, state.diskUsed, state.diskFree, state.diskUsage, state.individualDisks, state.diskStatusReason = stabilizeGuestLowTrustDisk(",+ "DiskStatusReason: state.diskStatusReason,",+ "return nil, classifyGuestAgentDiskStatusError(err), false",+ },+ "monitor_polling_vm.go": {+ "diskStatusReason = classifyGuestAgentDiskStatusError(err)",+ "diskTotal, diskUsed, diskFree, diskUsage, individualDisks, diskStatusReason = stabilizeGuestLowTrustDisk(",+ },+ }++ for file, snippets := range requiredSnippets {+ data, err := os.ReadFile(file)+ if err != nil {+ t.Fatalf("failed to read %s: %v", file, err)+ }+ source := string(data)+ for _, snippet := range snippets {+ if !strings.Contains(source, snippet) {+ t.Fatalf("%s must contain %q", file, snippet)+ }+ }+ }+}+func TestMonitoringRuntimeAvoidsLegacyMockPartialHelpers(t *testing.T) {forbiddenSnippets := []string{"mock.GetMockState(",diff --git a/internal/monitoring/guest_disk_stability.go b/internal/monitoring/guest_disk_stability.gonew file mode 100644index 0000000000..f6586b8b01--- /dev/null+++ b/internal/monitoring/guest_disk_stability.go@@ -0,0 +1,84 @@+package monitoring++import (+ "strings"+ "time"++ "github.com/rcourtman/pulse-go-rewrite/internal/models"+)++func cloneGuestDisks(src []models.Disk) []models.Disk {+ if len(src) == 0 {+ return nil+ }+ return append([]models.Disk(nil), src...)+}++func classifyGuestAgentDiskStatusError(err error) string {+ if err == nil {+ return ""+ }++ errStr := err.Error()+ errStrLower := strings.ToLower(errStr)++ switch {+ case strings.Contains(errStr, "QEMU guest agent is not running"):+ return "agent-not-running"+ case strings.Contains(errStr, "timeout") || strings.Contains(errStr, "deadline exceeded"):+ return "agent-timeout"+ case strings.Contains(errStr, "500") && (strings.Contains(errStr, "not running") || strings.Contains(errStr, "not available")):+ return "agent-not-running"+ case (strings.Contains(errStr, "403") || strings.Contains(errStr, "401")) &&+ (strings.Contains(errStrLower, "permission") || strings.Contains(errStrLower, "forbidden") || strings.Contains(errStrLower, "not allowed")):+ return "permission-denied"+ case strings.Contains(errStr, "500"):+ return "agent-not-running"+ default:+ return "agent-error"+ }+}++func shouldCarryForwardQEMUDisk(reason string) bool {+ switch reason {+ case "", "vm-stopped", "agent-disabled", "no-agent":+ return false+ default:+ return true+ }+}++func stabilizeGuestLowTrustDisk(+ prev *models.VM,+ status string,+ diskTotal uint64,+ diskUsed uint64,+ diskFree uint64,+ diskUsage float64,+ individualDisks []models.Disk,+ diskStatusReason string,+ diskFromAgent bool,+ now time.Time,+) (uint64, uint64, uint64, float64, []models.Disk, string) {+ if status != "running" || diskFromAgent || !shouldCarryForwardQEMUDisk(diskStatusReason) {+ return diskTotal, diskUsed, diskFree, diskUsage, individualDisks, diskStatusReason+ }+ if prev == nil || prev.Type != "qemu" || !hasRecentGuestAgentEvidence(prev, now) {+ return diskTotal, diskUsed, diskFree, diskUsage, individualDisks, diskStatusReason+ }+ if strings.HasPrefix(prev.DiskStatusReason, "prev-") {+ return diskTotal, diskUsed, diskFree, diskUsage, individualDisks, diskStatusReason+ }+ if prev.Disk.Total <= 0 || prev.Disk.Used < 0 || prev.Disk.Used > prev.Disk.Total || prev.Disk.Usage < 0 {+ return diskTotal, diskUsed, diskFree, diskUsage, individualDisks, diskStatusReason+ }++ total := uint64(prev.Disk.Total)+ used := uint64(prev.Disk.Used)+ free := total - used+ if prev.Disk.Free >= 0 && prev.Disk.Free <= prev.Disk.Total {+ free = uint64(prev.Disk.Free)+ }++ return total, used, free, prev.Disk.Usage, cloneGuestDisks(prev.Disks), "prev-" + diskStatusReason+}diff --git a/internal/monitoring/guest_disk_stability_test.go b/internal/monitoring/guest_disk_stability_test.gonew file mode 100644index 0000000000..b265c38e41--- /dev/null+++ b/internal/monitoring/guest_disk_stability_test.go@@ -0,0 +1,93 @@+package monitoring++import (+ "testing"+ "time"++ "github.com/rcourtman/pulse-go-rewrite/internal/models"+)++func TestStabilizeGuestLowTrustDiskCarriesForwardPreviousSnapshot(t *testing.T) {+ now := time.Now()+ prev := &models.VM{+ Type: "qemu",+ Status: "running",+ LastSeen: now.Add(-time.Minute),+ AgentVersion: "8.2.0",+ Disk: models.Disk{+ Total: 1000,+ Used: 400,+ Free: 600,+ Usage: 40,+ },+ Disks: []models.Disk{+ {Total: 1000, Used: 400, Free: 600, Usage: 40, Mountpoint: "/", Type: "ext4", Device: "/dev/vda"},+ },+ }++ total, used, free, usage, disks, reason := stabilizeGuestLowTrustDisk(+ prev,+ "running",+ 1000,+ 0,+ 1000,+ -1,+ nil,+ "no-filesystems",+ false,+ now,+ )++ if total != 1000 || used != 400 || free != 600 || usage != 40 {+ t.Fatalf("unexpected carried-forward disk summary: total=%d used=%d free=%d usage=%.2f", total, used, free, usage)+ }+ if len(disks) != 1 || disks[0].Device != "/dev/vda" {+ t.Fatalf("expected previous disks to be cloned, got %#v", disks)+ }+ if reason != "prev-no-filesystems" {+ t.Fatalf("reason = %q, want prev-no-filesystems", reason)+ }+}++func TestStabilizeGuestLowTrustDiskRejectsPreviouslyCarriedForwardSnapshot(t *testing.T) {+ now := time.Now()+ prev := &models.VM{+ Type: "qemu",+ Status: "running",+ LastSeen: now.Add(-time.Minute),+ AgentVersion: "8.2.0",+ DiskStatusReason: "prev-no-filesystems",+ Disk: models.Disk{+ Total: 1000,+ Used: 400,+ Free: 600,+ Usage: 40,+ },+ Disks: []models.Disk{+ {Total: 1000, Used: 400, Free: 600, Usage: 40, Mountpoint: "/", Type: "ext4", Device: "/dev/vda"},+ },+ }++ total, used, free, usage, disks, reason := stabilizeGuestLowTrustDisk(+ prev,+ "running",+ 1000,+ 0,+ 1000,+ -1,+ nil,+ "no-filesystems",+ false,+ now,+ )++ if total != 1000 || used != 0 || free != 1000 || usage != -1 {+ t.Fatalf("expected current low-trust values to remain, got total=%d used=%d free=%d usage=%.2f", total, used, free, usage)+ }+ if disks != nil {+ t.Fatalf("expected no disks to be carried forward, got %#v", disks)+ }+ if reason != "no-filesystems" {+ t.Fatalf("reason = %q, want no-filesystems", reason)+ }+}diff --git a/internal/monitoring/memory_trust_characterization_test.go b/internal/monitoring/memory_trust_characterization_test.goindex bf6598767a..f717c459ed 100644--- a/internal/monitoring/memory_trust_characterization_test.go+++ b/internal/monitoring/memory_trust_characterization_test.go@@ -3,7 +3,9 @@ package monitoringimport ("context""testing"+ "time"+ "github.com/rcourtman/pulse-go-rewrite/internal/mock""github.com/rcourtman/pulse-go-rewrite/internal/models""github.com/rcourtman/pulse-go-rewrite/pkg/proxmox")@@ -185,6 +187,48 @@ func TestPollPVENodePreservesPreviousSnapshotDuringTransientFallback(t *testing.}}+func TestGuestDiskTrustCharacterizationCarriesForwardRecentSnapshot(t *testing.T) {+ now := time.Now()+ prev := &models.VM{+ Type: "qemu",+ Status: "running",+ LastSeen: now.Add(-time.Minute),+ AgentVersion: "8.2.0",+ Disk: models.Disk{+ Total: 1000,+ Used: 400,+ Free: 600,+ Usage: 40,+ },+ Disks: []models.Disk{+ {Total: 1000, Used: 400, Free: 600, Usage: 40, Mountpoint: "/", Type: "ext4", Device: "/dev/vda"},+ },+ }++ total, used, free, usage, disks, reason := stabilizeGuestLowTrustDisk(+ prev,+ "running",+ 1000,+ 0,+ 1000,+ -1,+ nil,+ "no-filesystems",+ false,+ now,+ )++ if total != 1000 || used != 400 || free != 600 || usage != 40 {+ t.Fatalf("unexpected carried-forward disk summary: total=%d used=%d free=%d usage=%.2f", total, used, free, usage)+ }+ if len(disks) != 1 || disks[0].Device != "/dev/vda" {+ t.Fatalf("expected previous individual disks to be preserved, got %#v", disks)+ }+ if reason != "prev-no-filesystems" {+ t.Fatalf("reason = %q, want prev-no-filesystems", reason)+ }+}+func TestHandleClusterVMResourceMemoryTrustCharacterization(t *testing.T) {t.Setenv("PULSE_DATA_DIR", t.TempDir())@@ -477,6 +521,87 @@ func TestPollVMsWithNodesMemoryTrustCharacterization(t *testing.T) {}}+func TestPollVMsWithNodes_SkipsNativeGuestMetricWritesInMockMode(t *testing.T) {+ t.Setenv("PULSE_DATA_DIR", t.TempDir())++ previous := mock.IsMockEnabled()+ mock.SetEnabled(true)+ t.Cleanup(func() { mock.SetEnabled(previous) })++ mon := newTestPVEMonitor("test")+ defer mon.alertManager.Stop()+ defer mon.notificationMgr.Stop()++ client := &vmMemoryTrustStubClient{+ stubPVEClient: &stubPVEClient{},+ vms: []proxmox.VM{{+ VMID: 101,+ Name: "vm-101",+ Node: "node1",+ Status: "running",+ MaxMem: 8 * 1024,+ Mem: 3 * 1024,+ CPUs: 2,+ CPU: 0.42,+ }},+ vmStatus: &proxmox.VMStatus{+ Status: "running",+ MaxMem: 8 * 1024,+ Mem: 3 * 1024,+ Agent: proxmox.VMAgentField{Value: 1},+ },+ }++ nodes := []proxmox.Node{{Node: "node1", Status: "online"}}+ nodeEffectiveStatus := map[string]string{"node1": "online"}+ mon.pollVMsWithNodes(context.Background(), "test", "", false, client, nodes, nodeEffectiveStatus)++ vms := mon.state.GetSnapshot().VMs+ if len(vms) != 1 {+ t.Fatalf("expected 1 VM, got %d", len(vms))+ }++ if got := mon.metricsHistory.GetGuestMetrics(vms[0].ID, "cpu", time.Hour); len(got) != 0 {+ t.Fatalf("expected mock mode to skip native VM metrics history writes, got %+v", got)+ }+ if got := mon.metricsHistory.GetGuestMetrics(vms[0].ID, "memory", time.Hour); len(got) != 0 {+ t.Fatalf("expected mock mode to skip native VM memory history writes, got %+v", got)+ }+}++func TestRecordGuestMetric_SkipsNativeWritesInMockMode(t *testing.T) {+ t.Setenv("PULSE_DATA_DIR", t.TempDir())++ previous := mock.IsMockEnabled()+ mock.SetEnabled(true)+ t.Cleanup(func() { mock.SetEnabled(previous) })++ mon := newTestPVEMonitor("test")+ defer mon.alertManager.Stop()+ defer mon.notificationMgr.Stop()++ now := time.Now().UTC()+ mon.recordGuestMetric(+ "vm",+ "test:node1:101",+ 42,+ 48,+ 51,+ 1024,+ 512,+ 256,+ 128,+ now,+ )++ if got := mon.metricsHistory.GetGuestMetrics("test:node1:101", "cpu", time.Hour); len(got) != 0 {+ t.Fatalf("expected mock mode to skip helper cpu history writes, got %+v", got)+ }+ if got := mon.metricsHistory.GetGuestMetrics("test:node1:101", "memory", time.Hour); len(got) != 0 {+ t.Fatalf("expected mock mode to skip helper memory history writes, got %+v", got)+ }+}+func TestHandleClusterContainerResourceMemoryTrustCharacterization(t *testing.T) {t.Setenv("PULSE_DATA_DIR", t.TempDir())diff --git a/internal/monitoring/monitor_extra_coverage_test.go b/internal/monitoring/monitor_extra_coverage_test.goindex 6988a42289..574588b0b5 100644--- a/internal/monitoring/monitor_extra_coverage_test.go+++ b/internal/monitoring/monitor_extra_coverage_test.go@@ -487,6 +487,7 @@ type mockPVEClientExtra struct {vmStatus *proxmox.VMStatusvmStatusErr errorfsInfo []proxmox.VMFileSystem+ fsInfoErr errornetIfaces []proxmox.VMNetworkInterfaceagentInfo map[string]interface{}agentVersion string@@ -508,6 +509,9 @@ func (m *mockPVEClientExtra) GetVMStatus(ctx context.Context, node string, vmid}func (m *mockPVEClientExtra) GetVMFSInfo(ctx context.Context, node string, vmid int) ([]proxmox.VMFileSystem, error) {+ if m.fsInfoErr != nil {+ return nil, m.fsInfoErr+ }return m.fsInfo, nil}@@ -1068,7 +1072,7 @@ func TestMonitor_PreviousGuestContextForInstance_Extra(t *testing.T) {registry := unifiedresources.NewRegistry(nil)registry.IngestSnapshot(models.StateSnapshot{VMs: []models.VM{- {ID: "vm-1", Instance: "pve1", VMID: 101, Name: "vm1"},+ {ID: "vm-1", Instance: "pve1", VMID: 101, Name: "vm1", Disk: models.Disk{Total: 100, Used: 40, Free: 60, Usage: 40}},{ID: "vm-2", Instance: "pve2", VMID: 202, Name: "vm2"},},Containers: []models.Container{@@ -1093,6 +1097,9 @@ func TestMonitor_PreviousGuestContextForInstance_Extra(t *testing.T) {if len(prev.vmsByID) != 2 || prev.vmsByID[canonicalID].VMID != 101 || prev.vmsByID[makeGuestID("pve1", "", 101)].VMID != 101 {t.Fatalf("expected previous VM lookup to be indexed by canonical and runtime guest IDs, got %#v", prev.vmsByID)}+ if prev.vmsByID[canonicalID].Disk.Total != 100 || prev.vmsByID[canonicalID].Disk.Used != 40 {+ t.Fatalf("expected previous VM projection to preserve aggregate disk summary, got %#v", prev.vmsByID[canonicalID].Disk)+ }if len(prev.containers) != 2 {t.Fatalf("expected only pve1 containers, got %#v", prev.containers)}@@ -1511,6 +1518,191 @@ func TestBuildVMFromClusterResource_UsesLinkedHostAgentDiskFallback(t *testing.T}}+func TestBuildVMFromClusterResource_MarksDiskUnknownWhenGuestFilesystemDataIsUnavailable(t *testing.T) {+ monitor := &Monitor{+ rateTracker: NewRateTracker(),+ guestMetadataCache: make(map[string]guestMetadataCacheEntry),+ guestMetadataLimiter: make(map[string]time.Time),+ }+ client := &mockPVEClientExtra{+ vmStatus: &proxmox.VMStatus{+ Status: "running",+ Agent: proxmox.VMAgentField{Value: 1},+ },+ fsInfo: nil,+ }++ vm, _, _, _, _, ok := monitor.buildVMFromClusterResource(+ context.Background(),+ "cluster-a",+ proxmox.ClusterResource{+ Type: "qemu",+ Node: "node-a",+ Name: "app-vm",+ Status: "running",+ VMID: 101,+ MaxCPU: 4,+ MaxMem: 8192,+ MaxDisk: 1000,+ },+ client,+ makeGuestID("cluster-a", "node-a", 101),+ nil,+ nil,+ )+ if !ok {+ t.Fatal("expected VM to be built")+ }+ if vm.Disk.Usage != -1 {+ t.Fatalf("expected unknown disk usage, got %.2f", vm.Disk.Usage)+ }+ if vm.DiskStatusReason != "no-filesystems" {+ t.Fatalf("expected no-filesystems disk status reason, got %q", vm.DiskStatusReason)+ }+}++func TestBuildVMFromClusterResource_CarriesForwardPreviousDiskSnapshot(t *testing.T) {+ monitor := &Monitor{+ rateTracker: NewRateTracker(),+ guestMetadataCache: make(map[string]guestMetadataCacheEntry),+ guestMetadataLimiter: make(map[string]time.Time),+ }+ client := &mockPVEClientExtra{+ vmStatusErr: fmt.Errorf("API error 500: timeout"),+ fsInfo: nil,+ }+ guestID := makeGuestID("cluster-a", "node-a", 101)+ prevVM := &models.VM{+ ID: guestID,+ Instance: "cluster-a",+ Node: "node-a",+ VMID: 101,+ Name: "app-vm",+ Type: "qemu",+ Status: "running",+ LastSeen: time.Now(),+ AgentVersion: "8.2.0",+ Disk: models.Disk{+ Total: 1000,+ Used: 400,+ Free: 600,+ Usage: 40,+ },+ Disks: []models.Disk{+ {Total: 1000, Used: 400, Free: 600, Usage: 40, Mountpoint: "/", Type: "ext4", Device: "/dev/vda"},+ },+ }++ vm, _, _, _, _, ok := monitor.buildVMFromClusterResource(+ context.Background(),+ "cluster-a",+ proxmox.ClusterResource{+ Type: "qemu",+ Node: "node-a",+ Name: "app-vm",+ Status: "running",+ VMID: 101,+ MaxCPU: 4,+ MaxMem: 8192,+ MaxDisk: 1000,+ },+ client,+ guestID,+ nil,+ prevVM,+ )+ if !ok {+ t.Fatal("expected VM to be built")+ }+ if vm.Disk.Usage != 40 {+ t.Fatalf("expected previous disk usage to be carried forward, got %.2f", vm.Disk.Usage)+ }+ if len(vm.Disks) != 1 || vm.Disks[0].Device != "/dev/vda" {+ t.Fatalf("expected previous individual disks to be preserved, got %#v", vm.Disks)+ }+ if vm.DiskStatusReason != "prev-no-filesystems" {+ t.Fatalf("expected carried-forward disk status reason, got %q", vm.DiskStatusReason)+ }+}++func TestPollVMsWithNodes_CarriesForwardPreviousDiskSnapshot(t *testing.T) {+ t.Setenv("PULSE_DATA_DIR", t.TempDir())++ m := &Monitor{+ state: models.NewState(),+ guestAgentFSInfoTimeout: time.Second,+ guestAgentRetries: 1,+ guestAgentNetworkTimeout: time.Second,+ guestAgentOSInfoTimeout: time.Second,+ guestAgentVersionTimeout: time.Second,+ guestMetadataCache: make(map[string]guestMetadataCacheEntry),+ guestMetadataLimiter: make(map[string]time.Time),+ rateTracker: NewRateTracker(),+ metricsHistory: NewMetricsHistory(100, time.Hour),+ alertManager: alerts.NewManager(),+ stalenessTracker: NewStalenessTracker(nil),+ nodeRRDMemCache: make(map[string]rrdMemCacheEntry),+ vmRRDMemCache: make(map[string]rrdMemCacheEntry),+ }+ defer m.alertManager.Stop()++ registry := unifiedresources.NewRegistry(nil)+ guestID := makeGuestID("pve1", "node1", 100)+ registry.IngestSnapshot(models.StateSnapshot{+ VMs: []models.VM{+ {+ ID: guestID,+ VMID: 100,+ Name: "vm100",+ Node: "node1",+ Instance: "pve1",+ Type: "qemu",+ Status: "running",+ AgentVersion: "8.2.0",+ Disk: models.Disk{Total: 1000, Used: 400, Free: 600, Usage: 40},+ Disks: []models.Disk{{Total: 1000, Used: 400, Free: 600, Usage: 40, Mountpoint: "/", Type: "ext4", Device: "/dev/vda"}},+ LastSeen: time.Now(),+ IPAddresses: []string{"192.168.1.50"},+ },+ },+ })+ m.resourceStore = unifiedresources.NewMonitorAdapter(registry)++ client := &mockPVEClientExtra{+ vms: []proxmox.VM{+ {VMID: 100, Name: "vm100", Node: "node1", Status: "running", MaxMem: 8 * 1024, Mem: 4 * 1024, MaxDisk: 1000},+ },+ vmStatusErr: fmt.Errorf("API error 500: timeout"),+ fsInfo: nil,+ }++ m.pollVMsWithNodes(+ context.Background(),+ "pve1",+ "",+ false,+ client,+ []proxmox.Node{{Node: "node1", Status: "online"}},+ map[string]string{"node1": "online"},+ )++ state := m.GetState()+ if len(state.VMs) != 1 {+ t.Fatalf("expected 1 VM, got %d", len(state.VMs))+ }++ vm := state.VMs[0]+ if vm.Disk.Usage != 40 {+ t.Fatalf("expected previous disk usage to be carried forward, got %.2f", vm.Disk.Usage)+ }+ if len(vm.Disks) != 1 || vm.Disks[0].Device != "/dev/vda" {+ t.Fatalf("expected previous individual disks to be preserved, got %#v", vm.Disks)+ }+ if vm.DiskStatusReason != "prev-no-filesystems" {+ t.Fatalf("expected carried-forward disk status reason, got %q", vm.DiskStatusReason)+ }+}+func TestMonitor_PreviousNodesForInstance_Extra(t *testing.T) {m := &Monitor{state: models.NewState(),diff --git a/internal/monitoring/monitor_polling_vm.go b/internal/monitoring/monitor_polling_vm.goindex e3f816caa3..b3fd603cd5 100644--- a/internal/monitoring/monitor_polling_vm.go+++ b/internal/monitoring/monitor_polling_vm.go@@ -279,7 +279,6 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, cluif err != nil {// Handle errorserrStr := err.Error()- errStrLower := strings.ToLower(errStr)log.Warn().Str("instance", instanceName).Str("vm", vm.Name).@@ -287,47 +286,21 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, cluStr("error", errStr).Msg("Failed to get VM filesystem info from guest agent")- // Classify the error type for better user messaging- // Order matters: check most specific patterns first- if strings.Contains(errStr, "QEMU guest agent is not running") {- diskStatusReason = "agent-not-running"+ diskStatusReason = classifyGuestAgentDiskStatusError(err)++ switch diskStatusReason {+ case "agent-not-running":log.Info().Str("instance", instanceName).Str("vm", vm.Name).Int("vmid", vm.VMID).Msg("Guest agent enabled in VM config but not running inside guest OS. Install and start qemu-guest-agent in the VM")- } else if strings.Contains(errStr, "timeout") {- diskStatusReason = "agent-timeout"- } else if strings.Contains(errStr, "500") && (strings.Contains(errStr, "not running") || strings.Contains(errStr, "not available")) {- // Proxmox API error 500 with "not running"/"not available" indicates guest agent issue, not permissions- // This commonly happens when guest agent is not installed or not running- diskStatusReason = "agent-not-running"- log.Info().- Str("instance", instanceName).- Str("vm", vm.Name).- Int("vmid", vm.VMID).- Msg("Guest agent communication failed (API error 500). Install and start qemu-guest-agent in the VM")- } else if (strings.Contains(errStr, "403") || strings.Contains(errStr, "401")) &&- (strings.Contains(errStrLower, "permission") || strings.Contains(errStrLower, "forbidden") || strings.Contains(errStrLower, "not allowed")) {- // Only treat as permission-denied if we get explicit auth/permission error codes (401/403)- // This distinguishes actual permission issues from guest agent unavailability- diskStatusReason = "permission-denied"+ case "permission-denied":log.Warn().Str("instance", instanceName).Str("vm", vm.Name).Int("vmid", vm.VMID).Msg("Permission denied accessing guest agent. Verify Pulse user has VM.Monitor (PVE 8) or VM.Audit+VM.GuestAgent.Audit (PVE 9) permissions")- } else if strings.Contains(errStr, "500") {- // Generic 500 error without clear indicators - likely agent unavailable- // Refs #596: Proxmox returns 500 errors when guest agent isn't installed/running- diskStatusReason = "agent-not-running"- log.Info().- Str("instance", instanceName).- Str("vm", vm.Name).- Int("vmid", vm.VMID).- Msg("Failed to communicate with guest agent (API error 500). This usually means qemu-guest-agent is not installed or not running in the VM")- } else {- diskStatusReason = "agent-error"}} else if len(fsInfo) == 0 {diskStatusReason = "no-filesystems"@@ -495,6 +468,18 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, cluMsg("QEMU disk: using linked Pulse host agent disk summary")}}+ diskTotal, diskUsed, diskFree, diskUsage, individualDisks, diskStatusReason = stabilizeGuestLowTrustDisk(+ prevVM,+ vm.Status,+ diskTotal,+ diskUsed,+ diskFree,+ diskUsage,+ individualDisks,+ diskStatusReason,+ diskFromAgent,+ sampleTime,+ )prevSnapshot := m.previousGuestSnapshot(instanceName, "qemu", n.Node, vm.VMID)memUsed, memorySource, snapshotNotes := stabilizeGuestLowTrustMemory(diff --git a/internal/monitoring/monitor_previous_state.go b/internal/monitoring/monitor_previous_state.goindex 200dd7923f..b8ce0bfa9f 100644--- a/internal/monitoring/monitor_previous_state.go+++ b/internal/monitoring/monitor_previous_state.go@@ -94,17 +94,23 @@ func previousVMFromView(vm *unifiedresources.VMView) models.VM {return models.VM{}}return models.VM{- ID: vm.ID(),- Instance: vm.Instance(),- Node: vm.Node(),- VMID: vm.VMID(),- Name: vm.Name(),- Type: "qemu",- Status: string(vm.Status()),- IPAddresses: vm.IPAddresses(),- OSName: vm.OSName(),- OSVersion: vm.OSVersion(),- AgentVersion: vm.AgentVersion(),+ ID: vm.ID(),+ Instance: vm.Instance(),+ Node: vm.Node(),+ VMID: vm.VMID(),+ Name: vm.Name(),+ Type: "qemu",+ Status: string(vm.Status()),+ IPAddresses: vm.IPAddresses(),+ OSName: vm.OSName(),+ OSVersion: vm.OSVersion(),+ AgentVersion: vm.AgentVersion(),+ Disk: models.Disk{+ Used: vm.DiskUsed(),+ Total: vm.DiskTotal(),+ Free: max(0, vm.DiskTotal()-vm.DiskUsed()),+ Usage: vm.DiskPercent(),+ },NetworkInterfaces: guestNetworkInterfacesFromReadStateView(vm.NetworkInterfaces()),Disks: guestDisksFromReadStateView(vm.Disks()),DiskStatusReason: vm.DiskStatusReason(),diff --git a/internal/monitoring/monitor_pve_guest_builders.go b/internal/monitoring/monitor_pve_guest_builders.goindex dee03134f0..cf43b5f67b 100644--- a/internal/monitoring/monitor_pve_guest_builders.go+++ b/internal/monitoring/monitor_pve_guest_builders.go@@ -26,6 +26,7 @@ type vmBuildState struct {diskFree uint64diskUsage float64diskFromAgent bool+ diskStatusReason stringindividualDisks []models.DiskipAddresses []stringnetworkInterfaces []models.GuestNetworkInterface@@ -93,7 +94,7 @@ func (m *Monitor) applyVMStatusDetails(// Prefer guest agent data over cluster/resources data for accuracyif status.Agent.Value > 0 {var fsDisks []models.Disk- state.diskTotal, state.diskUsed, state.diskFree, state.diskUsage, fsDisks, state.diskFromAgent = m.updateVMDisksFromGuestAgentFSInfo(+ state.diskTotal, state.diskUsed, state.diskFree, state.diskUsage, fsDisks, state.diskFromAgent, state.diskStatusReason = m.updateVMDisksFromGuestAgentFSInfo(ctx,instanceName,res,@@ -110,6 +111,7 @@ func (m *Monitor) applyVMStatusDetails(if state.diskTotal > 0 {state.diskUsage = -1 // Show as allocated size}+ state.diskStatusReason = "agent-disabled"log.Debug().Str("instance", instanceName).Str("vm", res.Name).@@ -125,6 +127,7 @@ func (m *Monitor) applyVMStatusDetails(state.diskFree = uint64(hostDisk.Free)state.diskUsage = hostDisk.Usagestate.individualDisks = hostDisks+ state.diskStatusReason = ""log.Debug().Str("instance", instanceName).Str("vm", res.Name).@@ -174,6 +177,10 @@ func (m *Monitor) buildVMFromClusterResource(if res.Type == "qemu" && state.diskUsed == 0 && state.diskTotal > 0 && res.Status == "running" {state.diskUsage = -1}+ if res.Status != "running" && state.diskTotal > 0 {+ state.diskUsage = -1+ state.diskStatusReason = "vm-stopped"+ }// For running VMs, always try to get filesystem info from guest agent// The cluster/resources endpoint often returns 0 or incorrect values for disk usage@@ -182,6 +189,9 @@ func (m *Monitor) buildVMFromClusterResource(// First check if agent is enabled by getting VM statusstatus, err := client.GetVMStatus(ctx, res.Node, res.VMID)if err != nil {+ if state.diskTotal > 0 {+ state.diskStatusReason = "no-status"+ }log.Debug().Err(err).Str("instance", instanceName).@@ -191,6 +201,9 @@ func (m *Monitor) buildVMFromClusterResource(} else if status != nil {m.applyVMStatusDetails(ctx, instanceName, res, client, guestID, vmIDToHostAgent, status, &state)} else {+ if state.diskTotal > 0 {+ state.diskStatusReason = "no-status"+ }// No vmStatus available - keep cluster/resources datalog.Debug().Str("instance", instanceName).@@ -230,7 +243,7 @@ func (m *Monitor) buildVMFromClusterResource(}var fsDisks []models.Disk- state.diskTotal, state.diskUsed, state.diskFree, state.diskUsage, fsDisks, state.diskFromAgent = m.updateVMDisksFromGuestAgentFSInfo(+ state.diskTotal, state.diskUsed, state.diskFree, state.diskUsage, fsDisks, state.diskFromAgent, state.diskStatusReason = m.updateVMDisksFromGuestAgentFSInfo(ctx,instanceName,res,@@ -245,6 +258,20 @@ func (m *Monitor) buildVMFromClusterResource(}}+ sampleTime := time.Now()+ state.diskTotal, state.diskUsed, state.diskFree, state.diskUsage, state.individualDisks, state.diskStatusReason = stabilizeGuestLowTrustDisk(+ prevVM,+ res.Status,+ state.diskTotal,+ state.diskUsed,+ state.diskFree,+ state.diskUsage,+ state.individualDisks,+ state.diskStatusReason,+ state.diskFromAgent,+ sampleTime,+ )+if res.Status != "running" {state.memorySource = "powered-off"state.memUsed = 0@@ -255,7 +282,6 @@ func (m *Monitor) buildVMFromClusterResource(memFree = state.memTotal - state.memUsed}- sampleTime := time.Now()var snapshotNotes []stringstate.memUsed, state.memorySource, snapshotNotes = stabilizeGuestLowTrustMemory(prevSnapshot,@@ -319,6 +345,7 @@ func (m *Monitor) buildVMFromClusterResource(Usage: state.diskUsage,},Disks: state.individualDisks,+ DiskStatusReason: state.diskStatusReason,IPAddresses: state.ipAddresses,OSName: state.osName,OSVersion: state.osVersion,@@ -361,7 +388,7 @@ type vmFSInfoSummary struct {includedFS []string}-func (m *Monitor) fetchVMFSInfo(ctx context.Context, instanceName string, res proxmox.ClusterResource, client PVEClientInterface) ([]proxmox.VMFileSystem, bool) {+func (m *Monitor) fetchVMFSInfo(ctx context.Context, instanceName string, res proxmox.ClusterResource, client PVEClientInterface) ([]proxmox.VMFileSystem, string, bool) {// Use retry logic for guest agent calls to handle transient timeouts (refs #630)fsInfoRaw, err := m.retryGuestAgentCall(ctx, m.guestAgentFSInfoTimeout, m.guestAgentRetries, func(ctx context.Context) (interface{}, error) {return client.GetVMFSInfo(ctx, res.Node, res.VMID)@@ -426,7 +453,7 @@ func (m *Monitor) fetchVMFSInfo(ctx context.Context, instanceName string, res prInt("vmid", res.VMID).Msg("Failed to get filesystem info from guest agent")}- return nil, false+ return nil, classifyGuestAgentDiskStatusError(err), false}if len(fsInfo) == 0 {log.Info().@@ -434,9 +461,9 @@ func (m *Monitor) fetchVMFSInfo(ctx context.Context, instanceName string, res prStr("vm", res.Name).Int("vmid", res.VMID).Msg("Guest agent returned no filesystem info - agent may need restart or VM may have no mounted filesystems")- return nil, false+ return nil, "no-filesystems", false}- return fsInfo, true+ return fsInfo, "", true}func (m *Monitor) summarizeVMFSInfo(instanceName string, res proxmox.ClusterResource, fsInfo []proxmox.VMFileSystem) vmFSInfoSummary {@@ -597,16 +624,16 @@ func (m *Monitor) updateVMDisksFromGuestAgentFSInfo(diskTotal uint64,diskUsed uint64,diskUsage float64,-) (uint64, uint64, uint64, float64, []models.Disk, bool) {+) (uint64, uint64, uint64, float64, []models.Disk, bool, string) {log.Debug().Str("instance", instanceName).Str("vm", res.Name).Int("vmid", res.VMID).Msg("Guest agent enabled, querying filesystem info for accurate disk usage")- fsInfo, ok := m.fetchVMFSInfo(ctx, instanceName, res, client)+ fsInfo, diskStatusReason, ok := m.fetchVMFSInfo(ctx, instanceName, res, client)if !ok {- return diskTotal, diskUsed, diskTotal - diskUsed, diskUsage, nil, false+ return diskTotal, diskUsed, diskTotal - diskUsed, diskUsage, nil, false, diskStatusReason}log.Debug().@@ -655,7 +682,7 @@ func (m *Monitor) updateVMDisksFromGuestAgentFSInfo(Uint64("old_disk", res.Disk).Uint64("old_maxdisk", res.MaxDisk).Msg("Using guest agent data for accurate disk usage (replacing cluster/resources data)")- return diskTotal, diskUsed, diskTotal - diskUsed, diskUsage, summary.individualDisks, true+ return diskTotal, diskUsed, diskTotal - diskUsed, diskUsage, summary.individualDisks, true, ""}// Only special filesystems found - show allocated disk size instead@@ -668,5 +695,5 @@ func (m *Monitor) updateVMDisksFromGuestAgentFSInfo(Int("filesystems_found", len(fsInfo)).Msg("Guest agent provided filesystem info but no usable filesystems found (all were special mounts)")- return diskTotal, diskUsed, diskTotal - diskUsed, diskUsage, nil, false+ return diskTotal, diskUsed, diskTotal - diskUsed, diskUsage, nil, false, "special-filesystems-only"}