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
fix(resources): resolve agent metrics targets to the host agent ID for merged hosts
rcourtman8ce834cc5900
diff --git a/internal/unifiedresources/metrics_targets.go b/internal/unifiedresources/metrics_targets.goindex 2e9dd3cf33..5865ccc48e 100644--- a/internal/unifiedresources/metrics_targets.go+++ b/internal/unifiedresources/metrics_targets.go@@ -20,13 +20,20 @@ func BuildMetricsTarget(resource Resource, sourceTargets []SourceTarget) *Metricswitch CanonicalResourceType(resource.Type) {case ResourceTypeAgent:- if st, ok := bySource[SourceProxmox]; ok {+ // The agent source must win over platform sources (Proxmox/VMware):+ // real-mode agent metrics are written under the host agent ID+ // (monitor_agents.go writes "agent"/host.ID, the same ID ingestHost+ // registers for SourceAgent), so a merged node+agent resource must+ // advertise that key. Preferring the platform source ID here would+ // point store readers (reports, drawer history) at an "agent"-typed+ // key nothing ever writes.+ if st, ok := bySource[SourceAgent]; ok {return &MetricsTarget{ResourceType: "agent", ResourceID: st.SourceID}}- if st, ok := bySource[SourceVMware]; ok {+ if st, ok := bySource[SourceProxmox]; ok {return &MetricsTarget{ResourceType: "agent", ResourceID: st.SourceID}}- if st, ok := bySource[SourceAgent]; ok {+ if st, ok := bySource[SourceVMware]; ok {return &MetricsTarget{ResourceType: "agent", ResourceID: st.SourceID}}if st, ok := bySource[SourceTrueNAS]; ok {diff --git a/internal/unifiedresources/metrics_targets_test.go b/internal/unifiedresources/metrics_targets_test.goindex d9180196dc..16af9e1adf 100644--- a/internal/unifiedresources/metrics_targets_test.go+++ b/internal/unifiedresources/metrics_targets_test.go@@ -76,6 +76,31 @@ func TestBuildMetricsTarget_UsesCanonicalAgentTypeForInfrastructureFamilies(t *t}}+func TestBuildMetricsTarget_AgentSourceWinsForMergedHostResources(t *testing.T) {+ // Real-mode agent metrics are stored under the host agent ID (the+ // monitor_agents.go writer keys "agent" rows by host.ID, which is also+ // the SourceAgent ingest key). A host that is simultaneously a Proxmox+ // node (or VMware host) must still resolve its metrics target to the+ // agent key, or store readers query an ID nothing writes.+ target := BuildMetricsTarget(+ Resource{Type: ResourceTypeAgent},+ []SourceTarget{+ {Source: SourceProxmox, SourceID: "homelab-delly"},+ {Source: SourceVMware, SourceID: "vc-1:host:host-101"},+ {Source: SourceAgent, SourceID: "7d465a78-80b8-4255-999c-88224ae57b4f"},+ },+ )+ if target == nil {+ t.Fatal("BuildMetricsTarget() returned nil")+ }+ if target.ResourceType != "agent" {+ t.Fatalf("ResourceType = %q, want agent", target.ResourceType)+ }+ if target.ResourceID != "7d465a78-80b8-4255-999c-88224ae57b4f" {+ t.Fatalf("ResourceID = %q, want the agent source ID (the metrics-store write key)", target.ResourceID)+ }+}+func TestMetricsFromUnraidDiskCapacityUsesNativeCapacityFields(t *testing.T) {metrics := metricsFromUnraidDiskCapacity(1_000, 650, 65)if metrics == nil || metrics.Disk == nil {diff --git a/internal/unifiedresources/registry_test.go b/internal/unifiedresources/registry_test.goindex de852a8aa7..e43c748260 100644--- a/internal/unifiedresources/registry_test.go+++ b/internal/unifiedresources/registry_test.go@@ -357,8 +357,10 @@ func TestResourceRegistry_IngestResourcesRebuildsSourceMappingsForMetricsTargetsif target == nil {t.Fatal("expected seeded unified agent to rebuild a metrics target")}- if target.ResourceType != "agent" || target.ResourceID != "homelab-delly" {- t.Fatalf("metrics target = %+v, want agent/homelab-delly", target)+ // The agent source ID wins over the proxmox node ID: it is the host.ID+ // key the agent metrics writer stores rows under.+ if target.ResourceType != "agent" || target.ResourceID != "agent-source-delly" {+ t.Fatalf("metrics target = %+v, want agent/agent-source-delly", target)}targets := rr.SourceTargets("agent-dashboard-1")@@ -1659,6 +1661,70 @@ func TestResourceRegistry_IngestSnapshotParentsClusterNamedProxmoxGuestsToMerged}}+func TestResourceRegistry_MergedNodeAgentMetricsTargetMatchesAgentStoreWriteKey(t *testing.T) {+ // Real-mode agent metrics land in the metrics store keyed by host.ID+ // (monitor_agents.go: m.metricsStore.Write("agent", host.ID, ...), the+ // write key is pinned by a canonical guardrail in internal/monitoring).+ // The registry's metrics target for the merged node+agent resource must+ // resolve to that same key, or every store reader that trusts the+ // target — performance reports via MetricsResourceID, the drawer+ // history endpoint — queries an ID with zero rows.+ rr := NewRegistry(nil)+ now := time.Date(2026, 6, 10, 10, 0, 0, 0, time.UTC)++ rr.IngestSnapshot(models.StateSnapshot{+ Nodes: []models.Node{+ {+ ID: "homelab-delly",+ Name: "delly",+ Instance: "delly",+ ClusterName: "homelab",+ IsClusterMember: true,+ Host: "https://10.0.0.9:8006",+ LinkedAgentID: "host-1",+ Status: "online",+ LastSeen: now,+ },+ },+ Hosts: []models.Host{+ {+ ID: "host-1",+ Hostname: "delly.local",+ MachineID: "machine-delly",+ ReportIP: "10.0.0.9",+ Status: "online",+ LastSeen: now,+ LinkedNodeID: "homelab-delly",+ NetworkInterfaces: []models.HostNetworkInterface{+ {Name: "eth0", MAC: "00:11:22:33:44:66", Addresses: []string{"10.0.0.9/24"}},+ },+ },+ },+ })++ agents := rr.ListByType(ResourceTypeAgent)+ if len(agents) != 1 {+ t.Fatalf("expected 1 merged delly resource, got %d", len(agents))+ }+ resource := agents[0]++ targets := rr.SourceTargets(resource.ID)+ if len(targets) != 2 {+ t.Fatalf("expected merged proxmox+agent source targets, got %+v", targets)+ }++ target := BuildMetricsTargetForRegistry(rr, resource.ID)+ if target == nil {+ t.Fatal("BuildMetricsTargetForRegistry() returned nil")+ }+ if target.ResourceType != "agent" {+ t.Fatalf("ResourceType = %q, want agent", target.ResourceType)+ }+ if target.ResourceID != "host-1" {+ t.Fatalf("ResourceID = %q, want host-1 (the host.ID key the agent metrics writer uses)", target.ResourceID)+ }+}+func TestResourceRegistry_ManualNodeMergeRewritesProxmoxGuestParentAndActionAgent(t *testing.T) {store := NewMemoryStore()if err := store.AddLink(ResourceLink{