diff --git a/README.md b/README.md index 65be87d..107fbf5 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ The global configurations are: |key|value| |---|---| -|`check_interval`|Maximum frequency to run checks for each monitor| +|`check_interval`|Maximum frequency to run checks for each monitor (as duration, eg. 1m2s)| |`monitors`|List of all monitors. Detailed description below| |`alerts`|List of all alerts. Detailed description below| @@ -111,7 +111,7 @@ minitor -metrics -metrics-port 3000 ## Contributing -Whether you're looking to submit a patch or just tell me I broke something, you can contribute through the Github mirror and I can merge PRs back to the source repository. +Whether you're looking to submit a patch or tell me I broke something, you can contribute through the Github mirror and I can merge PRs back to the source repository. Primary Repo: https://git.iamthefij.com/iamthefij/minitor.git @@ -153,4 +153,3 @@ Future, potentially breaking changes - [ ] Async checking - [ ] Revisit metrics and see if they all make sense - [ ] Consider dropping `alert_up` and `alert_down` in favor of using Go templates that offer more control of messaging (Breaking) - - [ ] Use durations rather than seconds checked in event loop (Potentially breaking) diff --git a/config.go b/config.go index ef67de7..7d2d5b3 100644 --- a/config.go +++ b/config.go @@ -3,6 +3,7 @@ package main import ( "errors" "io/ioutil" + "time" "git.iamthefij.com/iamthefij/slog" "gopkg.in/yaml.v2" @@ -12,7 +13,7 @@ var errInvalidConfig = errors.New("Invalid configuration") // Config type is contains all provided user configuration type Config struct { - CheckInterval int64 `yaml:"check_interval"` + CheckInterval time.Duration `yaml:"check_interval"` Monitors []*Monitor Alerts map[string]*Alert } diff --git a/main.go b/main.go index 3df6d24..1eecd43 100644 --- a/main.go +++ b/main.go @@ -120,7 +120,6 @@ func main() { panic(err) } - sleepTime := time.Duration(config.CheckInterval) * time.Second - time.Sleep(sleepTime) + time.Sleep(config.CheckInterval) } } diff --git a/monitor.go b/monitor.go index 059d707..6aea6f3 100644 --- a/monitor.go +++ b/monitor.go @@ -11,9 +11,9 @@ import ( // Monitor represents a particular periodic check of a command type Monitor struct { //nolint:maligned // Config values - AlertAfter int16 `yaml:"alert_after"` - AlertEvery int16 `yaml:"alert_every"` - CheckInterval float64 `yaml:"check_interval"` + AlertAfter int16 `yaml:"alert_after"` + AlertEvery int16 `yaml:"alert_every"` + CheckInterval time.Duration `yaml:"check_interval"` Name string AlertDown []string `yaml:"alert_down"` AlertUp []string `yaml:"alert_up"` @@ -43,7 +43,7 @@ func (monitor Monitor) ShouldCheck() bool { return true } - sinceLastCheck := time.Since(monitor.lastCheck).Seconds() + sinceLastCheck := time.Since(monitor.lastCheck) return sinceLastCheck >= monitor.CheckInterval }