Browse Source

Add duration parsing for intervals

duration-intervals
IamTheFij 1 month ago
parent
commit
bdf7355fa7
  1. 5
      README.md
  2. 3
      config.go
  3. 3
      main.go
  4. 8
      monitor.go

5
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)

3
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
}

3
main.go

@ -120,7 +120,6 @@ func main() {
panic(err)
}
sleepTime := time.Duration(config.CheckInterval) * time.Second
time.Sleep(sleepTime)
time.Sleep(config.CheckInterval)
}
}

8
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
}

Loading…
Cancel
Save