From 9eecf946f8dd6a68b435c419f3282076853d9bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Thu, 30 May 2024 13:31:51 +0200 Subject: [PATCH] Configurable interval for nodata checks --- config.go | 3 ++- main.go | 6 +++++- nodata.go | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index 150fa1d..6ac26a3 100644 --- a/config.go +++ b/config.go @@ -1,5 +1,6 @@ package main type SmonConfiguration struct { - LogFile string + LogFile string + NodataInterval int `json:"nodata_interval"` // in seconds } diff --git a/main.go b/main.go index 859e59f..085ea5c 100644 --- a/main.go +++ b/main.go @@ -38,6 +38,7 @@ var ( parsedTemplates map[string]*template.Template componentFilenames []string notificationManager notification.Manager + smonConf SmonConfiguration //go:embed sql sqlFS embed.FS @@ -88,7 +89,6 @@ func main() { // {{{ os.Exit(1) } - smonConf := SmonConfiguration{} j, _ := json.Marshal(service.Config.Application) json.Unmarshal(j, &smonConf) logFile, err = os.OpenFile(smonConf.LogFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600) @@ -96,6 +96,10 @@ func main() { // {{{ logger.Error("application", "error", err) return } + if smonConf.NodataInterval < 10 { + logger.Error("application → nodata_interval has to be larger or equal to 10.") + return + } service.SetDatabase(sqlProvider) service.SetStaticFS(staticFS, "static") diff --git a/nodata.go b/nodata.go index a6cba54..ea09de9 100644 --- a/nodata.go +++ b/nodata.go @@ -25,7 +25,7 @@ func nodataLoop() { var err error // TODO - should be configurable - ticker := time.NewTicker(time.Second * 5) + ticker := time.NewTicker(time.Second * time.Duration(smonConf.NodataInterval)) for { <-ticker.C datapoints, err = nodataDatapoints()