Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

fix: prevent metrics.db bloat with automatic vacuum and WAL checkpointing

rcourtman284bdd7ade24
diff --git a/pkg/metrics/store.go b/pkg/metrics/store.go
index 3b6d79d69e..99e38f1822 100644
--- a/pkg/metrics/store.go
+++ b/pkg/metrics/store.go
@@ -108,6 +108,8 @@ func NewStore(config StoreConfig) (*Store, error) {
"busy_timeout(30000)",
"journal_mode(WAL)",
"synchronous(NORMAL)",
+ "auto_vacuum(INCREMENTAL)",
+ "wal_autocheckpoint(1000)",
},
}.Encode()
db, err := sql.Open("sqlite", dsn)
@@ -135,6 +137,10 @@ func NewStore(config StoreConfig) (*Store, error) {
return nil, fmt.Errorf("failed to initialize schema: %w", err)
}
+ // Clean up stale data from previous runs before starting the background worker.
+ // This prevents accumulation if Pulse was restarted before hourly retention ran.
+ store.runRetention()
+
// Start background workers
go store.backgroundWorker()
@@ -799,6 +805,16 @@ func (s *Store) runRetention() {
Int64("deleted", totalDeleted).
Dur("duration", time.Since(start)).
Msg("Metrics retention cleanup completed")
+
+ // Reclaim disk space from deleted rows. Without this, the database
+ // file never shrinks — a setup with 50+ resources can bloat to 5GB+
+ // while only holding ~60MB of live data.
+ if _, err := s.db.Exec(`PRAGMA incremental_vacuum(5000)`); err != nil {
+ log.Debug().Err(err).Msg("Incremental vacuum failed")
+ }
+ if _, err := s.db.Exec(`PRAGMA wal_checkpoint(TRUNCATE)`); err != nil {
+ log.Debug().Err(err).Msg("WAL checkpoint failed")
+ }
}
}