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 VM-correlated agent memory fallback
pulse-triage[bot]a4d5130ec69b
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 6a59869d1b..4511892bf7 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -17,6 +17,19 @@## Purpose+**Correlated VM memory fallback — issue #1962 (7 September 2026)**++The next Proxmox guest poll indexes live agent memory embedded in VM read views,+not only standalone host views. Keys retain the instance/node/VMID scope. This+restores the existing host-agent fallback when correlation removes the standalone+host row; it does not change preferred QEMU memory sources or platform metric+merge priority. Agent-source freshness and unavailable/invalid memory fail closed.+`TestCorrelatedGuestMemoryNextPoll` exercises real manual registry merging,+next-poll resolution, VM construction, card read-state projection, diagnostic+snapshots and actual memory-threshold evaluation, plus stale/offline/unavailable+samples and other-instance lookup. It is synthetic runtime proof, not a live+FreeBSD installation, automatic identity-match or browser receipt.+Container filesystem observations are native, resource-scoped reads. The shared`pkg/agents/filesystem` contract keeps measurement time, mountpoint, source,filesystem type and optional usage together. Unavailable reads have an errordiff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.mdindex ed965a09c9..f66a85ba8d 100644--- a/docs/release-control/v6/internal/subsystems/unified-resources.md+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md@@ -23,6 +23,18 @@ and sort the complete canonical change table while startup and ingestion wait.## Purpose+**VM-linked agent memory read — issue #1962 (7 September 2026)**++`VMView.LinkedAgentMemory` exposes a value-copy of the agent's own memory sample+for the poller's existing fallback. It must not read merged platform-priority+metrics or use aggregate VM liveness as agent freshness. Missing/non-online agent+source status, explicit agent staleness, unavailable usage and invalid capacity+or counters are rejected. Trusted zero usage remains valid. Registry freshness+policy remains authoritative; this accessor introduces no second timeout.+`TestVMViewLinkedAgentMemory` pins those boundaries; monitoring's+`TestCorrelatedGuestMemoryNextPoll` verifies the manually merged row through the+next-poll consumers. Existing host-list membership and metric priority are unchanged.+### Canonical Patrol and Assistant continuation, 2026-09-07Persisted action request identity is scoped to the trusted actor and exactdiff --git a/internal/monitoring/monitor_additional_test.go b/internal/monitoring/monitor_additional_test.goindex a98494ff1f..f6789035f2 100644--- a/internal/monitoring/monitor_additional_test.go+++ b/internal/monitoring/monitor_additional_test.go@@ -885,3 +885,102 @@ func TestApplyStorageFallbackAndRecordNodeMetrics_PersistsTemperatureHistory(t *t.Fatalf("temperature history = %+v, want one point at 64C", points)}}++// Exercise the registry's real manual merge, followed by the next guest poll's+// fallback lookup. A healthy platform row must not revive an offline agent.+func TestCorrelatedGuestMemoryNextPoll(t *testing.T) {+ for _, tc := range []struct {+ name, status string+ age time.Duration+ unavailable bool+ want uint64+ }{+ {name: "live", status: "online", want: 2800},+ {name: "offline", status: "offline", want: 8000},+ {name: "stale", status: "online", age: time.Hour, want: 8000},+ {name: "unavailable", status: "online", unavailable: true, want: 8000},+ } {+ t.Run(tc.name, func(t *testing.T) {+ now := time.Now()+ guestID := makeGuestID("pve-a", "node1", 111)+ store := unifiedresources.NewMemoryStore()+ if err := store.AddLink(unifiedresources.ResourceLink{ResourceA: "vm-test", ResourceB: "agent-test", PrimaryID: "agent-test"}); err != nil {+ t.Fatal(err)+ }+ registry := unifiedresources.NewRegistry(store)+ total, used := int64(8000), int64(8000)+ registry.IngestResources([]unifiedresources.Resource{+ {ID: "vm-test", Type: unifiedresources.ResourceTypeVM, Name: "firewall", Status: unifiedresources.StatusOnline, LastSeen: now,+ Sources: []unifiedresources.DataSource{unifiedresources.SourceProxmox},+ Proxmox: &unifiedresources.ProxmoxData{SourceID: guestID, Instance: "pve-a", NodeName: "node1", VMID: 111, RuntimeStatus: "running"},+ Metrics: &unifiedresources.ResourceMetrics{Memory: &unifiedresources.MetricValue{Total: &total, Used: &used, Percent: 100, Source: unifiedresources.SourceProxmox}}},+ {ID: "agent-test", Type: unifiedresources.ResourceTypeAgent, Name: "firewall-agent", Status: unifiedresources.ResourceStatus(tc.status), LastSeen: now.Add(-tc.age),+ Sources: []unifiedresources.DataSource{unifiedresources.SourceAgent},+ Agent: &unifiedresources.AgentData{AgentID: "agent-test", Stale: tc.status == "offline", Memory: &unifiedresources.AgentMemoryMeta{Total: 8000, Used: 2800, Free: 5200, UsageUnavailable: tc.unavailable}}},+ })+ if len(registry.VMs()) != 1 || len(registry.Hosts()) != 0 {+ t.Fatalf("expected one merged VM and no standalone hosts")+ }+ mon := &Monitor{state: models.NewState(), rateTracker: NewRateTracker(), config: &config.Config{}, resourceStore: unifiedresources.NewMonitorAdapter(registry)}+ prev := mon.previousGuestContextForInstance("pve-a")+ raw := VMMemoryRaw{}+ _, got, source := mon.resolveGuestStatusMemory(context.Background(), &stubPVEClient{}, "pve-a", "firewall", "node1", 111, guestID, &proxmox.VMStatus{MaxMem: 8000, Mem: 8100}, prev.hostAgentsByVMID, 8000, "", &raw)+ if got != tc.want {+ t.Fatalf("used=%d source=%s want=%d", got, source, tc.want)+ }+ if tc.want == 2800 && (source != "agent" || raw.HostAgentUsed != 2800 || raw.HostAgentTotal != 8000) {+ t.Fatalf("missing agent diagnostic evidence: %s %+v", source, raw)+ }+ if tc.want == 8000 && source != "status-mem" {+ t.Fatalf("unsafe fallback source %s", source)+ }+ vm, buildRaw, buildSource, _, _, ok := mon.buildVMFromClusterResource(context.Background(), "pve-a",+ proxmox.ClusterResource{Type: "qemu", Status: "running", Node: "node1", VMID: 111, Name: "firewall", MaxMem: 8000, Mem: 8100},+ &correlatedMemoryClient{}, guestID, prev.hostAgentsByVMID, nil)+ if !ok || vm.Memory.Used != int64(tc.want) || vm.Memory.Usage != float64(tc.want)/80 || buildSource != source || buildRaw.HostAgentUsed != raw.HostAgentUsed {+ t.Fatalf("builder disagrees with resolver: %+v source=%s raw=%+v", vm.Memory, buildSource, buildRaw)+ }+ projection := unifiedresources.NewRegistry(nil)+ projection.IngestSnapshot(models.StateSnapshot{VMs: []models.VM{vm}})+ if got := projection.VMs()[0].MemoryPercent(); got != vm.Memory.Usage {+ t.Fatalf("read-state card projection=%v want=%v", got, vm.Memory.Usage)+ }++ manager := alerts.NewManagerWithDataDir(t.TempDir())+ defer manager.Stop()+ cfg := manager.GetConfig()+ cfg.Enabled = true+ cfg.ActivationState = alerts.ActivationActive+ cfg.GuestDefaults = alerts.ThresholdConfig{Memory: &alerts.HysteresisThreshold{Trigger: 85, Clear: 80}}+ cfg.TimeThresholds = map[string]int{"guest": 0}+ manager.UpdateConfig(cfg)+ mon.alertManager = manager+ for i := 0; i < 2; i++ {+ if _, ok := mon.handleClusterVMResource(context.Background(), "pve-a", proxmox.ClusterResource{Type: "qemu", Status: "running", Node: "node1", VMID: 111, Name: "firewall", MaxMem: 8000, Mem: 8100}, guestID, &correlatedMemoryClient{}, nil, prev.hostAgentsByVMID); !ok {+ t.Fatal("poll handler skipped VM")+ }+ }+ snapshots := mon.GetDiagnosticSnapshots().Guests+ if len(snapshots) != 1 || snapshots[0].Memory.Usage != vm.Memory.Usage || snapshots[0].MemorySource != source {+ t.Fatalf("diagnostics disagree: %+v", snapshots)+ }+ active := manager.GetActiveAlerts()+ if tc.want == 2800 && len(active) != 0 {+ t.Fatalf("35 percent generated alerts: %+v", active)+ }+ if tc.want == 8000 && (len(active) != 1 || active[0].Value != 100) {+ t.Fatalf("100 percent did not generate matching alert: %+v", active)+ }+ other := mon.previousGuestContextForInstance("pve-b")+ if len(other.hostAgentsByVMID) != 0 {+ t.Fatal("correlated agent crossed instance boundary")+ }+ })+ }+}++type correlatedMemoryClient struct{ stubPVEClient }++func (*correlatedMemoryClient) GetVMStatus(context.Context, string, int) (*proxmox.VMStatus, error) {+ return &proxmox.VMStatus{MaxMem: 8000, Mem: 8100}, nil+}diff --git a/internal/monitoring/monitor_previous_state.go b/internal/monitoring/monitor_previous_state.goindex 9aa8340d38..86abbc1ac9 100644--- a/internal/monitoring/monitor_previous_state.go+++ b/internal/monitoring/monitor_previous_state.go@@ -43,6 +43,9 @@ func (m *Monitor) previousGuestContextForInstance(instanceName string) previousGguestID := makeGuestID(modelVM.Instance, modelVM.Node, modelVM.VMID)if guestID != "" {ctx.vmsByID[guestID] = modelVM+ if memory, ok := vm.LinkedAgentMemory(); ok {+ ctx.hostAgentsByVMID[guestID] = models.Host{LinkedVMID: guestID, Status: "online", Memory: memory}+ }}}diff --git a/internal/unifiedresources/views.go b/internal/unifiedresources/views.goindex dce859df18..b87f86f285 100644--- a/internal/unifiedresources/views.go+++ b/internal/unifiedresources/views.go@@ -75,6 +75,24 @@ type VMView struct{ r *Resource }func NewVMView(r *Resource) VMView { return VMView{r: r} }+// LinkedAgentMemory returns the agent's own sample, not the platform-priority+// merged metric. Freshness belongs to the agent source, not the VM row.+func (v VMView) LinkedAgentMemory() (models.Memory, bool) {+ if v.r == nil || v.r.Agent == nil || v.r.Agent.Stale || v.r.Agent.Memory == nil {+ return models.Memory{}, false+ }+ if status, ok := v.r.SourceStatus[SourceAgent]; !ok || status.Status != "online" {+ return models.Memory{}, false+ }+ m := v.r.Agent.Memory+ memory := models.Memory{Total: m.Total, Used: m.Used, Free: m.Free, Cache: m.Cache, UsageUnavailable: m.UsageUnavailable}+ if m.Total <= 0 {+ return models.Memory{}, false+ }+ memory.Usage = float64(m.Used) / float64(m.Total) * 100+ return memory, memory.HasKnownUsage()+}+func (v VMView) String() string { return fmt.Sprintf("VMView(%s, %q)", v.ID(), v.Name()) }func (v VMView) ID() string {diff --git a/internal/unifiedresources/views_test.go b/internal/unifiedresources/views_test.goindex d43cef49c6..f01847ae18 100644--- a/internal/unifiedresources/views_test.go+++ b/internal/unifiedresources/views_test.go@@ -2231,3 +2231,39 @@ func TestView_VMViewUsesProviderNeutralVirtualMachineFallback(t *testing.T) {t.Fatalf("CPUs() = %d, want 6", got)}}++func TestVMViewLinkedAgentMemory(t *testing.T) {+ for _, tc := range []struct {+ name string+ status string+ stale bool+ total, used int64+ unavailable bool+ want bool+ }{+ {name: "live", status: "online", total: 8000, used: 2800, want: true},+ {name: "trusted zero", status: "online", total: 8000, want: true},+ {name: "offline", status: "offline", total: 8000, used: 2800},+ {name: "stale source", status: "stale", total: 8000, used: 2800},+ {name: "stale agent", status: "online", stale: true, total: 8000, used: 2800},+ {name: "unknown source", total: 8000, used: 2800},+ {name: "negative", status: "online", total: 8000, used: -1},+ {name: "over capacity", status: "online", total: 8000, used: 8001},+ {name: "no capacity", status: "online"},+ {name: "unavailable", status: "online", total: 8000, used: 2800, unavailable: true},+ } {+ t.Run(tc.name, func(t *testing.T) {+ r := &Resource{Status: StatusOnline, Agent: &AgentData{Stale: tc.stale, Memory: &AgentMemoryMeta{Total: tc.total, Used: tc.used, UsageUnavailable: tc.unavailable}}, SourceStatus: map[DataSource]SourceStatus{SourceAgent: {Status: tc.status}}, Metrics: &ResourceMetrics{Memory: &MetricValue{Percent: 100}}}+ memory, ok := NewVMView(r).LinkedAgentMemory()+ if ok != tc.want {+ t.Fatalf("valid=%v want=%v memory=%+v", ok, tc.want, memory)+ }+ if ok && (memory.Used != tc.used || memory.Usage != float64(tc.used)/float64(tc.total)*100) {+ t.Fatalf("not agent memory: %+v", memory)+ }+ })+ }+ if _, ok := (VMView{}).LinkedAgentMemory(); ok {+ t.Fatal("nil view has memory")+ }+}