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 linked host-agent disk inventory for guest VMs
rcourtman242c4b432d6c
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 11b5447a7a..cc431fcdb0 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -252,6 +252,12 @@ reports stale or zero I/O totals. `internal/monitoring/monitor_pve.go`,path before LXC rate calculation and must reuse the same prefetched statussnapshot for metadata enrichment instead of paying disconnected metric andmetadata status reads that can diverge.+That same guest-monitoring boundary also owns linked host-agent precedence for+Proxmox VMs. When a VM has a live linked Pulse host agent, the canonical disk+inventory and aggregate disk summary must prefer that linked host-agent disk+collection over the narrower QEMU guest-agent filesystem list, so VM overview+surfaces keep the richer inside-guest storage truth instead of silently+regressing to mount-only visibility.That same mock-runtime boundary also owns update cadence. Demo and previewenvironments may slow the configured tick interval to reduce visual churn, butthat cadence must flow through the shared mock update loop and smoothing modeldiff --git a/internal/models/disk_summary.go b/internal/models/disk_summary.goindex 0518a2f497..c1e0b0d160 100644--- a/internal/models/disk_summary.go+++ b/internal/models/disk_summary.go@@ -23,3 +23,43 @@ func SummaryDisk(disks []Disk) (Disk, bool) {return Disk{}, false}++// AggregateDisk rolls a disk collection into one capacity summary.+// This is used when the canonical source of truth is a full disk inventory+// rather than one distinguished root filesystem.+func AggregateDisk(disks []Disk) (Disk, bool) {+ var total int64+ var used int64+ found := false++ for _, disk := range disks {+ if disk.Total <= 0 {+ continue+ }+ found = true+ total += disk.Total+ if disk.Used > 0 {+ used += disk.Used+ }+ }++ if !found || total <= 0 {+ return Disk{}, false+ }++ if used > total {+ used = total+ }++ usage := 0.0+ if total > 0 {+ usage = (float64(used) / float64(total)) * 100+ }++ return Disk{+ Total: total,+ Used: used,+ Free: total - used,+ Usage: usage,+ }, true+}diff --git a/internal/models/disk_summary_test.go b/internal/models/disk_summary_test.goindex 189ce7f9f2..4a779cfd03 100644--- a/internal/models/disk_summary_test.go+++ b/internal/models/disk_summary_test.go@@ -45,3 +45,44 @@ func TestSummaryDiskReturnsFalseWhenNoUsableDiskExists(t *testing.T) {t.Fatal("expected no summary disk for zero-capacity disks")}}++func TestAggregateDiskSumsVisibleDisks(t *testing.T) {+ disks := []Disk{+ {Mountpoint: "/", Total: 100, Used: 40},+ {Mountpoint: "/mnt/datastore/repo-a", Total: 300, Used: 120},+ {Mountpoint: "/mnt/datastore/repo-b", Total: 600, Used: 360},+ }++ got, ok := AggregateDisk(disks)+ if !ok {+ t.Fatal("expected aggregate disk")+ }+ if got.Total != 1000 || got.Used != 520 || got.Free != 480 {+ t.Fatalf("aggregate disk = %+v, want total=1000 used=520 free=480", got)+ }+ if got.Usage != 52 {+ t.Fatalf("aggregate usage = %v, want 52", got.Usage)+ }+}++func TestAggregateDiskIgnoresZeroCapacityEntries(t *testing.T) {+ got, ok := AggregateDisk([]Disk{+ {Mountpoint: "/boot", Total: 0, Used: 0},+ {Mountpoint: "/", Total: 100, Used: 25},+ })+ if !ok {+ t.Fatal("expected aggregate disk")+ }+ if got.Total != 100 || got.Used != 25 || got.Free != 75 {+ t.Fatalf("aggregate disk = %+v, want total=100 used=25 free=75", got)+ }+}++func TestAggregateDiskReturnsFalseWhenNoUsableDiskExists(t *testing.T) {+ if _, ok := AggregateDisk(nil); ok {+ t.Fatal("expected no aggregate disk for nil input")+ }+ if _, ok := AggregateDisk([]Disk{{Mountpoint: "/", Total: 0}}); ok {+ t.Fatal("expected no aggregate disk for zero-capacity disks")+ }+}diff --git a/internal/monitoring/canonical_guardrails_test.go b/internal/monitoring/canonical_guardrails_test.goindex 9c5fc08824..965519a899 100644--- a/internal/monitoring/canonical_guardrails_test.go+++ b/internal/monitoring/canonical_guardrails_test.go@@ -385,6 +385,37 @@ func TestProxmoxGuestDiskCarryForwardUsesCanonicalStabilityHelper(t *testing.T)}}+func TestProxmoxGuestDiskInventoryPrefersCanonicalLinkedHostAgentSource(t *testing.T) {+ requiredSnippets := map[string][]string{+ "guest_host_agent_fallback.go": {+ "func resolveGuestDiskFromLinkedHostAgent(guestID string, vmIDToHostAgent map[string]models.Host) (models.Disk, []models.Disk, bool) {",+ "summary, ok := models.AggregateDisk(host.Disks)",+ "func preferLinkedHostAgentDiskInventory(",+ },+ "monitor_pve_guest_builders.go": {+ "preferLinkedHostAgentDiskInventory(",+ `Msg("QEMU disk: preferring linked Pulse host agent disk inventory")`,+ },+ "monitor_polling_vm.go": {+ "preferLinkedHostAgentDiskInventory(",+ `Msg("QEMU disk: preferring linked Pulse host agent disk inventory")`,+ },+ }++ 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 TestStoragePollingUsesCanonicalPoolMetadataForZFSAttachment(t *testing.T) {data, err := os.ReadFile("monitor_polling_storage.go")if err != nil {diff --git a/internal/monitoring/guest_host_agent_fallback.go b/internal/monitoring/guest_host_agent_fallback.goindex 5acd7ef8f7..eb56124039 100644--- a/internal/monitoring/guest_host_agent_fallback.go+++ b/internal/monitoring/guest_host_agent_fallback.go@@ -12,7 +12,7 @@ func resolveGuestDiskFromLinkedHostAgent(guestID string, vmIDToHostAgent map[strreturn models.Disk{}, nil, false}- summary, ok := models.SummaryDisk(host.Disks)+ summary, ok := models.AggregateDisk(host.Disks)if !ok {return models.Disk{}, nil, false}@@ -28,3 +28,21 @@ func resolveGuestDiskFromLinkedHostAgent(guestID string, vmIDToHostAgent map[strDevice: summary.Device,}, disks, true}++func preferLinkedHostAgentDiskInventory(+ guestID string,+ vmIDToHostAgent map[string]models.Host,+ diskTotal uint64,+ diskUsed uint64,+ diskFree uint64,+ diskUsage float64,+ individualDisks []models.Disk,+ diskStatusReason string,+) (uint64, uint64, uint64, float64, []models.Disk, string, bool) {+ summary, hostDisks, ok := resolveGuestDiskFromLinkedHostAgent(guestID, vmIDToHostAgent)+ if !ok || summary.Total <= 0 {+ return diskTotal, diskUsed, diskFree, diskUsage, individualDisks, diskStatusReason, false+ }++ return uint64(summary.Total), uint64(summary.Used), uint64(summary.Free), summary.Usage, hostDisks, "", true+}diff --git a/internal/monitoring/memory_source_catalog_test.go b/internal/monitoring/memory_source_catalog_test.goindex fd4b8546f4..7ae11d9a50 100644--- a/internal/monitoring/memory_source_catalog_test.go+++ b/internal/monitoring/memory_source_catalog_test.go@@ -147,3 +147,23 @@ func TestMockVMPollingDefersMemoryHistoryToCanonicalSampler(t *testing.T) {}}}++func TestPollVMPrefersCanonicalLinkedHostAgentDiskInventory(t *testing.T) {+ t.Parallel()++ data, err := os.ReadFile("monitor_polling_vm.go")+ if err != nil {+ t.Fatalf("failed to read monitor_polling_vm.go: %v", err)+ }+ source := string(data)++ for _, snippet := range []string{+ "preferLinkedHostAgentDiskInventory(",+ `Bool("guestAgentDiskAvailable", diskFromAgent)`,+ `Msg("QEMU disk: preferring linked Pulse host agent disk inventory")`,+ } {+ if !strings.Contains(source, snippet) {+ t.Fatalf("monitor_polling_vm.go must contain %q", snippet)+ }+ }+}diff --git a/internal/monitoring/monitor_extra_coverage_test.go b/internal/monitoring/monitor_extra_coverage_test.goindex 8af36be6f5..acf387b1cb 100644--- a/internal/monitoring/monitor_extra_coverage_test.go+++ b/internal/monitoring/monitor_extra_coverage_test.go@@ -1522,6 +1522,64 @@ func TestBuildVMFromClusterResource_UsesLinkedHostAgentDiskFallback(t *testing.T}}+func TestBuildVMFromClusterResource_PrefersLinkedHostAgentDiskInventoryOverGuestAgentFilesystems(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: []proxmox.VMFileSystem{+ {Mountpoint: "/", Type: "ext4", TotalBytes: 100, UsedBytes: 40, Disk: "/dev/vda1"},+ {Mountpoint: "/mnt/datastore/repo-a", Type: "ext4", TotalBytes: 300, UsedBytes: 120, Disk: "/dev/vdb1"},+ },+ }+ guestID := makeGuestID("cluster-a", "node-a", 101)++ vm, _, _, _, _, ok := monitor.buildVMFromClusterResource(+ context.Background(),+ "cluster-a",+ proxmox.ClusterResource{+ Type: "qemu",+ Node: "node-a",+ Name: "pbs-vm",+ Status: "running",+ VMID: 101,+ MaxCPU: 4,+ MaxMem: 8192,+ MaxDisk: 400,+ },+ client,+ guestID,+ map[string]models.Host{+ guestID: {+ ID: "host-1",+ LinkedVMID: guestID,+ Status: "online",+ Disks: []models.Disk{+ {Total: 100, Used: 40, Free: 60, Usage: 40, Mountpoint: "/", Type: "ext4", Device: "/dev/vda1"},+ {Total: 300, Used: 120, Free: 180, Usage: 40, Mountpoint: "/mnt/datastore/repo-a", Type: "ext4", Device: "/dev/vdb1"},+ {Total: 600, Used: 360, Free: 240, Usage: 60, Mountpoint: "/mnt/datastore/repo-b", Type: "zfs", Device: "/dev/vdc1"},+ },+ },+ },+ nil,+ )+ if !ok {+ t.Fatal("expected VM to be built")+ }+ if vm.Disk.Total != 1000 || vm.Disk.Used != 520 || vm.Disk.Free != 480 || vm.Disk.Usage != 52 {+ t.Fatalf("expected linked host aggregate disk summary to win, got %+v", vm.Disk)+ }+ if len(vm.Disks) != 3 || vm.Disks[2].Mountpoint != "/mnt/datastore/repo-b" {+ t.Fatalf("expected linked host inventory to win, got %+v", vm.Disks)+ }+}+func TestBuildVMFromClusterResource_MarksDiskUnknownWhenGuestFilesystemDataIsUnavailable(t *testing.T) {monitor := &Monitor{rateTracker: NewRateTracker(),@@ -1707,6 +1765,90 @@ func TestPollVMsWithNodes_CarriesForwardPreviousDiskSnapshot(t *testing.T) {}}+func TestPollVMsWithNodes_PrefersLinkedHostAgentDiskInventoryOverGuestAgentFilesystems(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()++ guestID := makeGuestID("pve1", "node1", 100)+ registry := unifiedresources.NewRegistry(nil)+ registry.IngestSnapshot(models.StateSnapshot{+ Hosts: []models.Host{+ {+ ID: "host-1",+ Hostname: "pbs01",+ Status: "online",+ LinkedVMID: guestID,+ LastSeen: time.Now(),+ Disks: []models.Disk{+ {Total: 100, Used: 40, Free: 60, Usage: 40, Mountpoint: "/", Type: "ext4", Device: "/dev/vda1"},+ {Total: 300, Used: 120, Free: 180, Usage: 40, Mountpoint: "/mnt/datastore/repo-a", Type: "ext4", Device: "/dev/vdb1"},+ {Total: 600, Used: 360, Free: 240, Usage: 60, Mountpoint: "/mnt/datastore/repo-b", Type: "zfs", Device: "/dev/vdc1"},+ },+ },+ },+ })+ m.resourceStore = unifiedresources.NewMonitorAdapter(registry)++ client := &mockPVEClientExtra{+ vms: []proxmox.VM{+ {VMID: 100, Name: "pbs-vm", Node: "node1", Status: "running", MaxMem: 8 * 1024, Mem: 4 * 1024, MaxDisk: 400},+ },+ vmStatus: &proxmox.VMStatus{+ Status: "running",+ Agent: proxmox.VMAgentField{Value: 1},+ MaxMem: 8 * 1024,+ Mem: 4 * 1024,+ },+ fsInfo: []proxmox.VMFileSystem{+ {Mountpoint: "/", Type: "ext4", TotalBytes: 100, UsedBytes: 40, Disk: "/dev/vda1"},+ {Mountpoint: "/mnt/datastore/repo-a", Type: "ext4", TotalBytes: 300, UsedBytes: 120, Disk: "/dev/vdb1"},+ },+ }++ 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.Total != 1000 || vm.Disk.Used != 520 || vm.Disk.Free != 480 || vm.Disk.Usage != 52 {+ t.Fatalf("expected linked host aggregate disk summary to win, got %+v", vm.Disk)+ }+ if len(vm.Disks) != 3 || vm.Disks[2].Mountpoint != "/mnt/datastore/repo-b" {+ t.Fatalf("expected linked host inventory to win, got %+v", vm.Disks)+ }+ if vm.DiskStatusReason != "" {+ t.Fatalf("expected empty 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 c36fc85595..a04964573a 100644--- a/internal/monitoring/monitor_polling_vm.go+++ b/internal/monitoring/monitor_polling_vm.go@@ -451,21 +451,27 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, clu}}- if vm.Status == "running" && !diskFromAgent {- if hostDisk, hostDisks, ok := resolveGuestDiskFromLinkedHostAgent(guestID, vmIDToHostAgent); ok && hostDisk.Total > 0 {- diskTotal = uint64(hostDisk.Total)- diskUsed = uint64(hostDisk.Used)- diskFree = uint64(hostDisk.Free)- diskUsage = hostDisk.Usage- individualDisks = hostDisks- diskStatusReason = ""+ if vm.Status == "running" {+ var preferred bool+ diskTotal, diskUsed, diskFree, diskUsage, individualDisks, diskStatusReason, preferred = preferLinkedHostAgentDiskInventory(+ guestID,+ vmIDToHostAgent,+ diskTotal,+ diskUsed,+ diskFree,+ diskUsage,+ individualDisks,+ diskStatusReason,+ )+ if preferred {log.Debug().Str("instance", instanceName).Str("vm", vm.Name).Str("node", n.Node).Int("vmid", vm.VMID).- Float64("usage", hostDisk.Usage).- Msg("QEMU disk: using linked Pulse host agent disk summary")+ Bool("guestAgentDiskAvailable", diskFromAgent).+ Float64("usage", diskUsage).+ Msg("QEMU disk: preferring linked Pulse host agent disk inventory")}}diskTotal, diskUsed, diskFree, diskUsage, individualDisks, diskStatusReason = stabilizeGuestLowTrustDisk(diff --git a/internal/monitoring/monitor_pve_guest_builders.go b/internal/monitoring/monitor_pve_guest_builders.goindex cf43b5f67b..05ad017d42 100644--- a/internal/monitoring/monitor_pve_guest_builders.go+++ b/internal/monitoring/monitor_pve_guest_builders.go@@ -120,22 +120,6 @@ func (m *Monitor) applyVMStatusDetails(Msg("VM does not have guest agent enabled in config")}- if res.Status == "running" && !state.diskFromAgent {- if hostDisk, hostDisks, ok := resolveGuestDiskFromLinkedHostAgent(guestID, vmIDToHostAgent); ok && hostDisk.Total > 0 {- state.diskTotal = uint64(hostDisk.Total)- state.diskUsed = uint64(hostDisk.Used)- state.diskFree = uint64(hostDisk.Free)- state.diskUsage = hostDisk.Usage- state.individualDisks = hostDisks- state.diskStatusReason = ""- log.Debug().- Str("instance", instanceName).- Str("vm", res.Name).- Int("vmid", res.VMID).- Float64("usage", hostDisk.Usage).- Msg("QEMU disk: using linked Pulse host agent disk summary")- }- }}func (m *Monitor) buildVMFromClusterResource(@@ -256,6 +240,27 @@ func (m *Monitor) buildVMFromClusterResource(state.individualDisks = fsDisks}}++ var preferred bool+ state.diskTotal, state.diskUsed, state.diskFree, state.diskUsage, state.individualDisks, state.diskStatusReason, preferred = preferLinkedHostAgentDiskInventory(+ guestID,+ vmIDToHostAgent,+ state.diskTotal,+ state.diskUsed,+ state.diskFree,+ state.diskUsage,+ state.individualDisks,+ state.diskStatusReason,+ )+ if preferred {+ log.Debug().+ Str("instance", instanceName).+ Str("vm", res.Name).+ Int("vmid", res.VMID).+ Bool("guestAgentDiskAvailable", state.diskFromAgent).+ Float64("usage", state.diskUsage).+ Msg("QEMU disk: preferring linked Pulse host agent disk inventory")+ }}sampleTime := time.Now()