Skip to content

Commit

Permalink
Refactor collector to use ticker for periodic data recording and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasbacsai committed Oct 15, 2024
1 parent 7e682b2 commit 696bbc9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func collector() {

cleanupTable("cpu_usage")
cleanupTable("memory_usage")
checkpoint()
vacuum()
}()
}
}
Expand Down
12 changes: 12 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ func getUnixTimeInMilliUTC() string {

func vacuum() {
go func() {
defer func() {
if r := recover(); r != nil {
log.Printf("Recovered from panic in vacuum: %v", r)
}
}()

_, err := db.Exec("VACUUM")
if err != nil {
log.Printf("Error vacuuming: %v", err)
Expand All @@ -22,6 +28,12 @@ func vacuum() {
}
func checkpoint() {
go func() {
defer func() {
if r := recover(); r != nil {
log.Printf("Recovered from panic in checkpoint: %v", r)
}
}()

_, err := db.Exec("CHECKPOINT")
if err != nil {
log.Printf("Error checkpointing: %v", err)
Expand Down

0 comments on commit 696bbc9

Please sign in to comment.