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
Serve fresh alert snapshots from monitor state reads
rcourtman96e6745737f7
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 7020e83c41..2d04d16f7f 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -238,6 +238,12 @@ not by reading `GetMonitor()`'s default-org compatibility shim.Consumer packages already use `ReadState`, but the monitoring core still hasdual truth between unified resources and `StateSnapshot`. This is the mainremaining architecture-coherence lane.+Alert arrays are the explicit freshness exception inside that remaining dual+truth. Monitoring APIs that still serve `StateSnapshot` must project+`ActiveAlerts` and `RecentlyResolved` from the live alert manager at read time+instead of trusting the cached snapshot fields, so externally served alert+counts and recently resolved incidents do not lag behind acknowledgement,+resolve, or clear operations between explicit sync points.The container entrypoint in `docker-entrypoint.sh` now also lives under thisboundary. Hosted or managed tenant bootstrap changes must preserve safe startupwhen immutable read-only mounts are layered into `/etc/pulse`; the entrypointdiff --git a/internal/monitoring/canonical_guardrails_test.go b/internal/monitoring/canonical_guardrails_test.goindex fda09603bd..e91d00c1fa 100644--- a/internal/monitoring/canonical_guardrails_test.go+++ b/internal/monitoring/canonical_guardrails_test.go@@ -73,6 +73,24 @@ func TestNoGetStateResourceArrayRegression(t *testing.T) {}}+func TestGetStateRefreshesLiveAlertSnapshots(t *testing.T) {+ data, err := os.ReadFile("monitor.go")+ if err != nil {+ t.Fatalf("failed to read monitor.go: %v", err)+ }+ source := string(data)++ for _, snippet := range []string{+ "state := m.state.GetSnapshot()",+ "state.ActiveAlerts = m.activeAlertsSnapshot()",+ "state.RecentlyResolved = m.recentlyResolvedAlertsSnapshot()",+ } {+ if !strings.Contains(source, snippet) {+ t.Fatalf("monitor.go must contain %q", snippet)+ }+ }+}+func TestMonitoringRuntimeAvoidsLegacyMockPartialHelpers(t *testing.T) {forbiddenSnippets := []string{"mock.GetMockState(",diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.goindex af363dbfe4..be227126a1 100644--- a/internal/monitoring/monitor.go+++ b/internal/monitoring/monitor.go@@ -2708,7 +2708,14 @@ func (m *Monitor) GetState() models.StateSnapshot {if m.state == nil {return models.StateSnapshot{}}- return m.state.GetSnapshot()++ state := m.state.GetSnapshot()+ // Keep externally served alert arrays aligned with the live alert manager+ // even between explicit sync points, so APIs do not expose stale alert+ // counts or recently resolved incidents from cached state.+ state.ActiveAlerts = m.activeAlertsSnapshot()+ state.RecentlyResolved = m.recentlyResolvedAlertsSnapshot()+ return state}// ReadSnapshot returns a snapshot of the current infrastructure state,diff --git a/internal/monitoring/monitor_extra_coverage_test.go b/internal/monitoring/monitor_extra_coverage_test.goindex 29dc3016c4..10759b308d 100644--- a/internal/monitoring/monitor_extra_coverage_test.go+++ b/internal/monitoring/monitor_extra_coverage_test.go@@ -37,6 +37,52 @@ func TestMonitor_GetConnectionStatuses_MockMode_Extra(t *testing.T) {}}+func TestMonitor_GetStateRefreshesAlertSnapshots(t *testing.T) {+ m := &Monitor{+ state: models.NewState(),+ alertManager: alerts.NewManager(),+ }+ defer m.alertManager.Stop()++ m.state.UpdateActiveAlerts([]models.Alert{{+ ID: "stale-alert",+ ResourceID: "vm-1",+ Type: "cpu",+ Level: "warning",+ Message: "stale",+ StartTime: time.Now(),+ }})+ m.state.UpdateRecentlyResolved([]models.ResolvedAlert{{+ Alert: models.Alert{+ ID: "stale-resolved",+ Type: "cpu",+ ResourceID: "vm-1",+ ResourceName: "vm-1",+ Message: "stale resolved",+ },+ ResolvedTime: time.Now(),+ }})+ m.alertManager.ClearActiveAlerts()++ state := m.GetState()+ if len(state.ActiveAlerts) != 0 {+ t.Fatalf("expected GetState to drop stale state alerts, got %d", len(state.ActiveAlerts))+ }+ if len(state.RecentlyResolved) != 0 {+ t.Fatalf("expected GetState to drop stale state recently resolved alerts, got %d", len(state.RecentlyResolved))+ }++ host := models.DockerHost{ID: "docker-host-1", DisplayName: "docker-host-1"}+ m.alertManager.HandleDockerHostOffline(host)+ m.alertManager.HandleDockerHostOffline(host)+ m.alertManager.HandleDockerHostOffline(host)++ state = m.GetState()+ if len(state.ActiveAlerts) == 0 {+ t.Fatal("expected GetState to include current alert-manager alerts")+ }+}+func TestMonitor_Cleanup_Extra(t *testing.T) {m := &Monitor{nodeSnapshots: make(map[string]NodeMemorySnapshot),