From 856e26edcfdd9cc38fa00371376fd7a88cebcc82 Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Thu, 4 Oct 2018 14:25:40 +0300 Subject: [PATCH] Periodically flush stats.json --- app.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app.go b/app.go index ce6bd2f7..6f5d31ea 100644 --- a/app.go +++ b/app.go @@ -9,6 +9,7 @@ import ( "os/signal" "path/filepath" "strconv" + "time" "github.com/gobuffalo/packr" ) @@ -132,6 +133,16 @@ func main() { os.Exit(1) }() + go func() { + for range time.Tick(time.Hour * 24) { + err := writeStats() + if err != nil { + log.Printf("Couldn't write stats: %s", err) + // try later on next iteration, don't abort + } + } + }() + address := net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) runStatsCollectors()