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
Close the unclassified-node window in cross-instance node aggregation
[email protected]17117c32efae
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 3d71adebda..4e92d10855 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -113,9 +113,22 @@ match is not machine identity across sites that reuse RFC1918 ranges, soevery hostname- or IP-based agent match is rejected when the candidateagent's linked nodes live in a different named cluster or carry a differentTLS fingerprint, and a hostname-based match is also rejected when the node's-endpoint IP is absent from the candidate agent's reported IPs. Nodes with-empty cluster names keep merging into their cluster view so standalone and-not-yet-classified endpoint views of the same machine still fold together.+endpoint IP is absent from the candidate agent's reported IPs. Weak-evidence+folds across connection instances — a bare-hostname endpoint alias or a+shared linked-agent identity — additionally require positive same-machine+proof (matching non-empty cluster identity or matching TLS fingerprints)+whenever cluster identity is in play on either side, because node names+repeat across sites and host agents key on /etc/machine-id, which cloned+template deployments reuse across unrelated machines. An unclassified node+(empty cluster name) must never displace or fold into an established named+cluster slot on such evidence alone. Two views that are both unclassified+still dedup freely, and address-based endpoint aliases keep folding on the+contradiction checks alone, so standalone and not-yet-classified endpoint+views of the same machine still fold together. PVE polling must run cluster+membership detection before the cycle's node-state commit so a newly added+connection's nodes carry their cluster identity from the first state write+whenever detection succeeds, instead of transiting the aggregation layer+unclassified.Docker and Podman container CPU collection preserves the runtime-native rawper-core CPU percent, but monitoring-owned history and alert thresholdevaluation use host-capacity-normalized CPU percent when host CPU capacity isdiff --git a/internal/models/models.go b/internal/models/models.goindex 61afb6f2c9..db404ec233 100644--- a/internal/models/models.go+++ b/internal/models/models.go@@ -3464,6 +3464,40 @@ func nodeProviderIdentityConflicts(a, b Node) bool {return fpA == "" || fpA != fpB}+// nodeCrossViewMergeProven reports whether two node views carry positive+// same-machine evidence: the same connection instance, a matching non-empty+// cluster identity that survives the provider-conflict check, or matching+// TOFU-captured TLS fingerprints. Weak-evidence folds across instances - a+// bare-hostname endpoint alias or a shared agent identity - require this+// proof, because node names repeat across sites, private address ranges+// collide, and cloned template deployments reuse /etc/machine-id, which is+// exactly the identity host agents key on. A cluster connection's first polls+// can also land before membership detection classifies its nodes, and that+// empty-cluster-name window must not let another site's same-named node fold+// into (and overwrite) an established slot.+func nodeCrossViewMergeProven(a, b Node) bool {+ if normalizeNodeIdentityPart(a.Instance) == normalizeNodeIdentityPart(b.Instance) {+ return true+ }+ if nodeProviderIdentityConflicts(a, b) {+ return false+ }+ clusterA := normalizeNodeIdentityPart(a.ClusterName)+ clusterB := normalizeNodeIdentityPart(b.ClusterName)+ if clusterA == "" && clusterB == "" {+ // Two unclassified standalone views still dedup on the shared+ // evidence alone: with no cluster identity in play there is no+ // established cluster slot to steal.+ return true+ }+ if clusterA == clusterB {+ return true+ }+ fpA := normalizeNodeTLSFingerprint(a.TLSFingerprint)+ fpB := normalizeNodeTLSFingerprint(b.TLSFingerprint)+ return fpA != "" && fpA == fpB+}+func resolveNodeMergeKey(primaryKey string,node Node,@@ -3489,9 +3523,18 @@ func resolveNodeMergeKey(}// Two clusters can reuse node names (pve01 in cluster A and cluster B),// so an endpoint alias is only trustworthy when the cluster identities- // don't contradict each other.- if existing, exists := nodeMap[key]; exists && nodeProviderIdentityConflicts(existing, node) {- continue+ // don't contradict each other. A hostname-based alias is weaker still -+ // bare node names repeat across sites - so across instances it only+ // folds with positive same-machine proof; an address-based alias keeps+ // folding on the contradiction check alone so standalone views still+ // reach their cluster node.+ if existing, exists := nodeMap[key]; exists {+ if nodeProviderIdentityConflicts(existing, node) {+ continue+ }+ if strings.HasPrefix(alias, "endpoint-host:") && !nodeCrossViewMergeProven(existing, node) {+ continue+ }}if resolved != "" && resolved != key {return primaryKey@@ -3880,8 +3923,12 @@ func (s *State) UpdateNodesForInstance(instanceName string, nodes []Node) {if _, ambiguous := ambiguousLinkedHosts[node.LinkedAgentID]; !ambiguous {if linkedKey := linkedHostToKey[node.LinkedAgentID]; linkedKey != "" {// A shared agent identity must never collapse two different- // named clusters into one node slot.- if existing, ok := nodeMap[linkedKey]; !ok || !nodeProviderIdentityConflicts(existing, node) {+ // named clusters into one node slot - and because agents+ // key on /etc/machine-id, which cloned deployments reuse+ // across unrelated machines, a cross-instance fold needs+ // positive same-machine proof, not just the absence of a+ // contradiction.+ if existing, ok := nodeMap[linkedKey]; !ok || nodeCrossViewMergeProven(existing, node) {targetKey = linkedKey}}diff --git a/internal/models/state_host_test.go b/internal/models/state_host_test.goindex cf29d6ce62..da507a7729 100644--- a/internal/models/state_host_test.go+++ b/internal/models/state_host_test.go@@ -1890,3 +1890,176 @@ func TestUpdateNodesForInstanceSharedAgentLinkMergeGatedOnFingerprint(t *testingt.Fatalf("contradicting fingerprints: nodes = %#v, want 2", split.Nodes)}}++// A cluster connection's first polls can commit nodes before membership+// detection classifies them (ClusterName ""), and cloned template+// deployments reuse /etc/machine-id, collapsing two sites' agents into one+// identity (MSP support case: clusters enacon and rewo, both with pve01, on+// reused RFC1918 ranges). During that window the shared agent identity must+// not fold the unclassified node into the established cluster's slot.+func TestUpdateNodesForInstanceUnclassifiedNodeSharedAgentMustNotStealClusterSlot(t *testing.T) {+ state := &State{+ Hosts: []Host{+ {+ // One host row standing in for two physical pve01 machines+ // whose cloned machine-id collapsed them into one agent+ // identity; it currently reports the second site's address.+ ID: "host-cloned-machine-id",+ Hostname: "pve01",+ ReportIP: "192.168.1.11",+ NetworkInterfaces: []HostNetworkInterface{+ {Name: "eth0", Addresses: []string{"192.168.1.11/24"}},+ },+ },+ },+ Nodes: []Node{+ {+ ID: "enacon-pve01",+ Name: "pve01",+ Instance: "enacon",+ ClusterName: "enacon",+ IsClusterMember: true,+ Host: "https://192.168.16.11:8006",+ LinkedAgentID: "host-cloned-machine-id",+ Status: "online",+ },+ },+ }++ state.UpdateNodesForInstance("rewo", []Node{+ {+ ID: "rewo-pve01",+ Name: "pve01",+ Instance: "rewo",+ // Membership detection has not classified this connection yet.+ ClusterName: "",+ Host: "https://192.168.1.11:8006",+ Status: "online",+ },+ })++ if len(state.Nodes) != 2 {+ t.Fatalf("nodes = %#v, want 2 (unclassified node must not fold into the enacon slot)", state.Nodes)+ }+ byID := make(map[string]Node)+ for _, node := range state.Nodes {+ byID[node.ID] = node+ }+ enacon, ok := byID["enacon-pve01"]+ if !ok {+ t.Fatalf("enacon-pve01 was clobbered, nodes = %#v", state.Nodes)+ }+ if enacon.ClusterName != "enacon" {+ t.Fatalf("enacon-pve01 ClusterName = %q, want enacon", enacon.ClusterName)+ }+ if _, ok := byID["rewo-pve01"]; !ok {+ t.Fatalf("rewo-pve01 missing, nodes = %#v", state.Nodes)+ }+}++// When TLS settings degrade both connections' node endpoints to the bare+// node name, the endpoint-host alias is identical across sites. An+// unclassified node (empty cluster name, e.g. during the first-poll+// membership window) must not ride that weak alias into another instance's+// established cluster slot.+func TestUpdateNodesForInstanceEndpointHostAliasRequiresProofForUnclassifiedNodes(t *testing.T) {+ state := &State{+ Nodes: []Node{+ {+ ID: "enacon-pve01",+ Name: "pve01",+ Instance: "enacon",+ ClusterName: "enacon",+ IsClusterMember: true,+ Host: "https://pve01:8006",+ Status: "online",+ },+ },+ }++ state.UpdateNodesForInstance("rewo", []Node{+ {+ ID: "rewo-pve01",+ Name: "pve01",+ Instance: "rewo",+ ClusterName: "",+ Host: "https://pve01:8006",+ Status: "online",+ },+ })++ if len(state.Nodes) != 2 {+ t.Fatalf("nodes = %#v, want 2 (bare-hostname alias must not fold an unclassified cross-instance node)", state.Nodes)+ }+}++// The legitimate standalone-into-cluster fold must survive the weak-evidence+// tightening: a standalone connection view dialing the same address as the+// cluster's endpoint record still folds via the address alias, and a+// fingerprint-proven view still folds via the shared agent link.+func TestUpdateNodesForInstanceStandaloneViewStillFoldsIntoClusterNode(t *testing.T) {+ byAddress := &State{+ Nodes: []Node{+ {+ ID: "enacon-pve01",+ Name: "pve01",+ Instance: "enacon",+ ClusterName: "enacon",+ IsClusterMember: true,+ Host: "https://192.168.16.11:8006",+ Status: "online",+ },+ },+ }+ byAddress.UpdateNodesForInstance("pve01-direct", []Node{+ {+ ID: "direct-pve01",+ Name: "pve01",+ Instance: "pve01-direct",+ Host: "https://192.168.16.11:8006",+ Status: "online",+ },+ })+ if len(byAddress.Nodes) != 1 {+ t.Fatalf("address alias: nodes = %#v, want 1 (same-address standalone view folds)", byAddress.Nodes)+ }++ byAgent := &State{+ Hosts: []Host{+ {+ ID: "host-pve01",+ Hostname: "pve01",+ ReportIP: "192.168.16.11",+ NetworkInterfaces: []HostNetworkInterface{+ {Name: "eth0", Addresses: []string{"192.168.16.11/24"}},+ },+ },+ },+ Nodes: []Node{+ {+ ID: "enacon-pve01",+ Name: "pve01",+ Instance: "enacon",+ ClusterName: "enacon",+ IsClusterMember: true,+ Host: "https://pve01:8006",+ TLSFingerprint: "AA:AA:AA:AA",+ LinkedAgentID: "host-pve01",+ Status: "online",+ },+ },+ }+ byAgent.UpdateNodesForInstance("pve01-direct", []Node{+ {+ ID: "direct-pve01",+ Name: "pve01",+ Instance: "pve01-direct",+ Host: "https://192.168.16.11:8006",+ TLSFingerprint: "aaaaaaaa",+ Status: "online",+ },+ })+ if len(byAgent.Nodes) != 1 {+ t.Fatalf("agent link: nodes = %#v, want 1 (fingerprint-proven view folds via shared agent)", byAgent.Nodes)+ }+}diff --git a/internal/monitoring/monitor_pve.go b/internal/monitoring/monitor_pve.goindex 1edc33ccc9..245c13f6d4 100644--- a/internal/monitoring/monitor_pve.go+++ b/internal/monitoring/monitor_pve.go@@ -1402,6 +1402,18 @@ func (m *Monitor) pollPVEInstance(ctx context.Context, instanceName string, clieclient = updatedClientm.refreshPVETagColors(ctx, instanceName, client)+ // Detect cluster membership BEFORE the first node-state commit. A newly+ // added connection whose add-time detection failed (#437) would otherwise+ // publish its nodes with an empty cluster name, and unclassified nodes are+ // exactly what the aggregation guards must treat as weak identity - the+ // window let a second site's same-named node bind to (and overwrite) an+ // established cluster's slot. Re-fetch the config afterwards because+ // detection persists onto m.config while getInstanceConfig returns a copy.+ m.detectClusterMembership(ctx, instanceName, instanceCfg, client)+ if refreshedCfg := m.getInstanceConfig(instanceName); refreshedCfg != nil {+ instanceCfg = refreshedCfg+ }+// Check if client is a ClusterClient to determine health statusconnectionHealthStr := m.updatePVEConnectionHealth(ctx, instanceName, client)@@ -1470,9 +1482,9 @@ func (m *Monitor) pollPVEInstance(ctx context.Context, instanceName string, cliemodelNodes = m.applyStorageFallbackAndRecordNodeMetrics(instanceName, client, modelNodes, nodeDiskSources, localStorageByNode)- // Periodically re-check cluster status for nodes marked as standalone- // This addresses issue #437 where clusters aren't detected on first attempt- m.detectClusterMembership(ctx, instanceName, instanceCfg, client)+ // Cluster membership detection runs earlier in this cycle, before the+ // node-state commit, so newly detected identity applies to this poll's+ // nodes rather than the next one's.// Update cluster endpoint online status if this is a clusterm.updateClusterEndpointStatus(instanceName, instanceCfg, client, modelNodes)diff --git a/internal/monitoring/monitor_pve_membership_order_test.go b/internal/monitoring/monitor_pve_membership_order_test.gonew file mode 100644index 0000000000..36be9c898c--- /dev/null+++ b/internal/monitoring/monitor_pve_membership_order_test.go@@ -0,0 +1,94 @@+package monitoring++import (+ "context"+ "testing"+ "time"++ "github.com/rcourtman/pulse-go-rewrite/internal/alerts"+ "github.com/rcourtman/pulse-go-rewrite/internal/config"+ "github.com/rcourtman/pulse-go-rewrite/internal/models"+ "github.com/rcourtman/pulse-go-rewrite/internal/notifications"+ "github.com/rcourtman/pulse-go-rewrite/pkg/proxmox"+)++// Cluster membership detection must run before the poll cycle's node-state+// commit. A newly added connection whose add-time detection failed (#437)+// otherwise publishes its nodes with an empty cluster name, and that+// unclassified window is what let a second site's same-named node bind into+// an established cluster's slot (MSP support case).+func TestPollPVEInstanceCommitsClusterIdentityOnFirstPoll(t *testing.T) {+ originalDetect := detectMonitorPVECluster+ t.Cleanup(func() { detectMonitorPVECluster = originalDetect })+ detectMonitorPVECluster = func(clientConfig proxmox.ClientConfig, existingEndpoints []config.ClusterEndpoint) (bool, string, []config.ClusterEndpoint) {+ return true, "rewo", []config.ClusterEndpoint{+ {NodeID: "node/pve01", NodeName: "pve01", Host: "https://192.168.1.11:8006", IP: "192.168.1.11", Online: true, LastSeen: time.Now()},+ }+ }++ m := &Monitor{+ config: &config.Config{+ PVEInstances: []config.PVEInstance{+ // Standalone-shaped: add-time cluster detection failed.+ {Name: "rewo", Host: "https://192.168.1.11:8006"},+ },+ },+ state: models.NewState(),+ pveClients: make(map[string]PVEClientInterface),+ nodeLastOnline: make(map[string]time.Time),+ nodeSnapshots: make(map[string]NodeMemorySnapshot),+ guestSnapshots: make(map[string]GuestMemorySnapshot),+ nodeRRDMemCache: make(map[string]rrdMemCacheEntry),+ metricsHistory: NewMetricsHistory(32, time.Hour),+ guestMetadataCache: make(map[string]guestMetadataCacheEntry),+ guestMetadataLimiter: make(map[string]time.Time),+ lastClusterCheck: make(map[string]time.Time),+ lastPhysicalDiskPoll: make(map[string]time.Time),+ lastPVEBackupPoll: make(map[string]time.Time),+ lastPBSBackupPoll: make(map[string]time.Time),+ authFailures: make(map[string]int),+ lastAuthAttempt: make(map[string]time.Time),+ pollStatusMap: make(map[string]*pollStatus),+ nodePendingUpdatesCache: make(map[string]pendingUpdatesCache),+ instanceInfoCache: make(map[string]*instanceInfo),+ lastOutcome: make(map[string]taskOutcome),+ failureCounts: make(map[string]int),+ removedDockerHosts: make(map[string]time.Time),+ dockerTokenBindings: make(map[string]string),+ dockerCommands: make(map[string]*dockerHostCommand),+ dockerCommandIndex: make(map[string]string),+ guestAgentFSInfoTimeout: defaultGuestAgentFSInfoTimeout,+ guestAgentNetworkTimeout: defaultGuestAgentNetworkTimeout,+ guestAgentOSInfoTimeout: defaultGuestAgentOSInfoTimeout,+ guestAgentVersionTimeout: defaultGuestAgentVersionTimeout,+ guestAgentRetries: defaultGuestAgentRetries,+ alertManager: alerts.NewManager(),+ notificationMgr: notifications.NewNotificationManager(""),+ }+ defer m.alertManager.Stop()+ defer m.notificationMgr.Stop()++ mockClient := &mockPVEClientExtended{+ nodes: []proxmox.Node{+ {Node: "pve01", Status: "online"},+ },+ }++ ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)+ defer cancel()+ m.pollPVEInstance(ctx, "rewo", mockClient)++ if len(m.state.Nodes) != 1 {+ t.Fatalf("nodes = %#v, want 1", m.state.Nodes)+ }+ node := m.state.Nodes[0]+ if node.Name != "pve01" {+ t.Fatalf("node = %#v, want pve01", node)+ }+ if node.ClusterName != "rewo" {+ t.Fatalf("first poll committed ClusterName = %q, want rewo (membership detection must precede the node-state commit)", node.ClusterName)+ }+ if !node.IsClusterMember {+ t.Fatalf("first poll committed IsClusterMember = false, want true")+ }+}