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 PBS backup memory retention
rcourtmanfce431717613
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 9db2f4d1c4..b2add17308 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -31,7 +31,12 @@ PBS backup snapshot refresh is a bounded monitoring hot path: group-levelsnapshot fetches must run through the fixed worker pool in`internal/monitoring/monitor_backups.go`, reuse cached snapshots on per-groupfetch failures, and must not allocate one goroutine or buffered result slot per-backup group in large PBS datastores.+backup group in large PBS datastores. PBS backup group cache metadata must be+pruned to the retained group set after a completed poll, while preserving cache+metadata only for groups still observed or intentionally reused after transient+datastore failures. Recovery-point ingestion started by backup polling must be+serialized and coalesced so slow store writes cannot retain one full backup+point batch per poll cycle.Removed host-agent reconnect blocks are identity-scoped: matching may use thecanonical host ID or token-qualified machine/hostname continuity, but must neverblock a distinct live host by hostname alone.@@ -103,6 +108,7 @@ threshold value.53. `internal/monitoring/platform_poller_shared.go`54. `internal/monitoring/monitor_backups.go`55. `internal/monitoring/resource_stale_thresholds.go`+56. `internal/monitoring/recovery_ingest.go`## Shared Boundaries@@ -214,7 +220,10 @@ threshold value.package worker-pool constant and stream requests through workers instead ofcreating one goroutine per backup group; per-group API failures may reusecached snapshots, but the polling loop must keep memory proportional to the- worker count rather than datastore cardinality.+ worker count rather than datastore cardinality. Per-group cache timestamps+ must be removed when successful group discovery no longer retains that+ group, and recovery-store ingestion must be a bounded latest-batch pipeline+ rather than an untracked goroutine per poll.12. Add or change agentless availability monitoring only through thepoll-provider path. `internal/monitoring/availability_poller.go` owns ICMP,TCP, and HTTP probes, provider health, scheduler task construction, anddiff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.goindex cd78325bd6..c17acfe0b8 100644--- a/internal/monitoring/monitor.go+++ b/internal/monitoring/monitor.go@@ -25,6 +25,7 @@ import ("github.com/rcourtman/pulse-go-rewrite/internal/models""github.com/rcourtman/pulse-go-rewrite/internal/monitoring/errors""github.com/rcourtman/pulse-go-rewrite/internal/notifications"+ "github.com/rcourtman/pulse-go-rewrite/internal/recovery"recoverymanager "github.com/rcourtman/pulse-go-rewrite/internal/recovery/manager""github.com/rcourtman/pulse-go-rewrite/internal/system""github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"@@ -1049,6 +1050,9 @@ type Monitor struct {resourceStore ResourceStoreInterface // Optional unified resource store for polling optimizationsupplementalProviders map[unifiedresources.DataSource]MonitorSupplementalRecordsProviderrecoveryManager *recoverymanager.Manager // Optional recovery store manager for backup rollups+ recoveryIngestMu sync.Mutex+ recoveryIngestRunning bool+ recoveryIngestPending []recovery.RecoveryPointmockMetricsCancel context.CancelFuncmockMetricsWg sync.WaitGroupdockerChecker DockerChecker // Optional Docker checker for LXC containersdiff --git a/internal/monitoring/monitor_backups.go b/internal/monitoring/monitor_backups.goindex 0a99082e9c..f432673c6d 100644--- a/internal/monitoring/monitor_backups.go+++ b/internal/monitoring/monitor_backups.go@@ -1358,6 +1358,7 @@ func (m *Monitor) pollPBSBackups(ctx context.Context, instanceName string, clienexistingGroups := m.buildPBSBackupCache(instanceName)var allBackups []models.PBSBackup+ retainedGroups := make(map[pbsBackupGroupKey]struct{}, len(existingGroups))datastoreCount := len(datastores) // Number of datastores to querydatastoreFetches := 0 // Number of successful datastore fetchesdatastoreErrors := 0 // Number of failed datastore fetches@@ -1426,6 +1427,7 @@ func (m *Monitor) pollPBSBackups(ctx context.Context, instanceName string, clienif group.BackupCount == 0 {continue}+ retainedGroups[key] = struct{}{}lastBackupTime := time.Unix(group.LastBackup, 0)hasCachedData := len(cached.snapshots) > 0@@ -1510,6 +1512,7 @@ func (m *Monitor) pollPBSBackups(ctx context.Context, instanceName string, cliencontinue}allBackups = append(allBackups, entry.snapshots...)+ retainedGroups[key] = struct{}{}}}datastoreErrors++@@ -1532,6 +1535,8 @@ func (m *Monitor) pollPBSBackups(ctx context.Context, instanceName string, clienreturn}+ m.prunePBSBackupCacheTimes(instanceName, retainedGroups)+// Update statem.state.UpdatePBSBackups(instanceName, allBackups)@@ -1602,6 +1607,28 @@ func (m *Monitor) setPBSBackupCacheTime(instanceName string, key pbsBackupGroupKm.pbsBackupCacheTime[instanceName][key] = t}+func (m *Monitor) prunePBSBackupCacheTimes(instanceName string, retained map[pbsBackupGroupKey]struct{}) {+ m.mu.Lock()+ defer m.mu.Unlock()++ if m.pbsBackupCacheTime == nil {+ return+ }+ perGroup := m.pbsBackupCacheTime[instanceName]+ if len(perGroup) == 0 {+ return+ }++ for key := range perGroup {+ if _, ok := retained[key]; !ok {+ delete(perGroup, key)+ }+ }+ if len(perGroup) == 0 {+ delete(m.pbsBackupCacheTime, instanceName)+ }+}+func normalizePBSNamespacePath(ns string) string {if ns == "/" {return ""diff --git a/internal/monitoring/monitor_backups_readstate_test.go b/internal/monitoring/monitor_backups_readstate_test.goindex 748eaa6422..8ddf6ef4c3 100644--- a/internal/monitoring/monitor_backups_readstate_test.go+++ b/internal/monitoring/monitor_backups_readstate_test.go@@ -230,6 +230,95 @@ func TestFetchPBSBackupSnapshotsUsesBoundedWorkerPool(t *testing.T) {}}+func TestPollPBSBackupsPrunesCacheTimesForDeletedGroups(t *testing.T) {+ t.Parallel()++ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ if strings.Contains(r.URL.Path, "/admin/datastore/archive/groups") {+ _, _ = w.Write([]byte(`{"data":[{"backup-type":"vm","backup-id":"100","last-backup":1700000000,"backup-count":1}]}`))+ return+ }+ http.NotFound(w, r)+ }))+ defer server.Close()++ client, err := pbs.NewClient(pbs.ClientConfig{+ Host: server.URL,+ TokenName: "root@pam!token",+ TokenValue: "secret",+ })+ if err != nil {+ t.Fatalf("failed to create PBS client: %v", err)+ }++ keepKey := pbsBackupGroupKey{+ datastore: "archive",+ namespace: "",+ backupType: "vm",+ backupID: "100",+ }+ staleKey := pbsBackupGroupKey{+ datastore: "archive",+ namespace: "",+ backupType: "vm",+ backupID: "999",+ }++ m := &Monitor{+ state: models.NewState(),+ pbsBackupCacheTime: map[string]map[pbsBackupGroupKey]time.Time{+ "pbs1": {+ keepKey: time.Now(),+ staleKey: time.Now(),+ },+ },+ }+ m.state.UpdatePBSBackups("pbs1", []models.PBSBackup{+ {+ ID: "pbs-pbs1-archive--vm-100-1700000000",+ Instance: "pbs1",+ Datastore: "archive",+ Namespace: "",+ BackupType: "vm",+ VMID: "100",+ BackupTime: time.Unix(1700000000, 0),+ },+ {+ ID: "pbs-pbs1-archive--vm-999-1690000000",+ Instance: "pbs1",+ Datastore: "archive",+ Namespace: "",+ BackupType: "vm",+ VMID: "999",+ BackupTime: time.Unix(1690000000, 0),+ },+ })++ m.pollPBSBackups(context.Background(), "pbs1", client, []models.PBSDatastore{+ {Name: "archive"},+ })++ m.mu.RLock()+ perGroup := m.pbsBackupCacheTime["pbs1"]+ _, kept := perGroup[keepKey]+ _, stale := perGroup[staleKey]+ m.mu.RUnlock()++ if !kept {+ t.Fatal("expected current PBS group cache time to be retained")+ }+ if stale {+ t.Fatal("expected deleted PBS group cache time to be pruned")+ }++ snapshot := m.state.GetSnapshot()+ for _, backup := range snapshot.PBSBackups {+ if backup.Instance == "pbs1" && backup.VMID == "999" {+ t.Fatalf("expected stale backup to be removed with cache time, found: %+v", backup)+ }+ }+}+func TestMonitorPollGuestSnapshots_UsesCanonicalReadState(t *testing.T) {m := &Monitor{state: models.NewState(),diff --git a/internal/monitoring/recovery_ingest.go b/internal/monitoring/recovery_ingest.goindex ea9f304a55..75e2432f44 100644--- a/internal/monitoring/recovery_ingest.go+++ b/internal/monitoring/recovery_ingest.go@@ -16,12 +16,43 @@ func (m *Monitor) ingestRecoveryPointsAsync(points []recovery.RecoveryPoint) {if m == nil || len(points) == 0 {return}- go func() {++ m.recoveryIngestMu.Lock()+ if m.recoveryIngestRunning {+ m.recoveryIngestPending = points+ m.recoveryIngestMu.Unlock()+ log.Debug().+ Int("points", len(points)).+ Msg("Coalesced recovery point ingest behind active batch")+ return+ }+ m.recoveryIngestRunning = true+ m.recoveryIngestMu.Unlock()++ go m.runRecoveryPointIngestLoop(points)+}++func (m *Monitor) runRecoveryPointIngestLoop(points []recovery.RecoveryPoint) {+ for len(points) > 0 {// SQLite upserts are usually quick, but allow a bit of time for large batches.ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)- defer cancel()m.ingestRecoveryPointsBestEffort(ctx, points)- }()+ cancel()++ m.recoveryIngestMu.Lock()+ if len(m.recoveryIngestPending) == 0 {+ m.recoveryIngestRunning = false+ m.recoveryIngestMu.Unlock()+ return+ }+ points = m.recoveryIngestPending+ m.recoveryIngestPending = nil+ m.recoveryIngestMu.Unlock()+ }++ m.recoveryIngestMu.Lock()+ m.recoveryIngestRunning = false+ m.recoveryIngestMu.Unlock()}func (m *Monitor) ingestRecoveryPointsBestEffort(ctx context.Context, points []recovery.RecoveryPoint) {