Add duration parsing for intervals
This commit is contained in:
parent
befea7375f
commit
bdf7355fa7
@ -54,7 +54,7 @@ The global configurations are:
|
|||||||
|
|
||||||
|key|value|
|
|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|
|
|`monitors`|List of all monitors. Detailed description below|
|
||||||
|`alerts`|List of all alerts. Detailed description below|
|
|`alerts`|List of all alerts. Detailed description below|
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ minitor -metrics -metrics-port 3000
|
|||||||
|
|
||||||
## Contributing
|
## 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
|
Primary Repo: https://git.iamthefij.com/iamthefij/minitor.git
|
||||||
|
|
||||||
@ -153,4 +153,3 @@ Future, potentially breaking changes
|
|||||||
- [ ] Async checking
|
- [ ] Async checking
|
||||||
- [ ] Revisit metrics and see if they all make sense
|
- [ ] 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)
|
- [ ] 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,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.iamthefij.com/iamthefij/slog"
|
"git.iamthefij.com/iamthefij/slog"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
@ -12,7 +13,7 @@ var errInvalidConfig = errors.New("Invalid configuration")
|
|||||||
|
|
||||||
// Config type is contains all provided user configuration
|
// Config type is contains all provided user configuration
|
||||||
type Config struct {
|
type Config struct {
|
||||||
CheckInterval int64 `yaml:"check_interval"`
|
CheckInterval time.Duration `yaml:"check_interval"`
|
||||||
Monitors []*Monitor
|
Monitors []*Monitor
|
||||||
Alerts map[string]*Alert
|
Alerts map[string]*Alert
|
||||||
}
|
}
|
||||||
|
3
main.go
3
main.go
@ -120,7 +120,6 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sleepTime := time.Duration(config.CheckInterval) * time.Second
|
time.Sleep(config.CheckInterval)
|
||||||
time.Sleep(sleepTime)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,9 @@ import (
|
|||||||
// Monitor represents a particular periodic check of a command
|
// Monitor represents a particular periodic check of a command
|
||||||
type Monitor struct { //nolint:maligned
|
type Monitor struct { //nolint:maligned
|
||||||
// Config values
|
// Config values
|
||||||
AlertAfter int16 `yaml:"alert_after"`
|
AlertAfter int16 `yaml:"alert_after"`
|
||||||
AlertEvery int16 `yaml:"alert_every"`
|
AlertEvery int16 `yaml:"alert_every"`
|
||||||
CheckInterval float64 `yaml:"check_interval"`
|
CheckInterval time.Duration `yaml:"check_interval"`
|
||||||
Name string
|
Name string
|
||||||
AlertDown []string `yaml:"alert_down"`
|
AlertDown []string `yaml:"alert_down"`
|
||||||
AlertUp []string `yaml:"alert_up"`
|
AlertUp []string `yaml:"alert_up"`
|
||||||
@ -43,7 +43,7 @@ func (monitor Monitor) ShouldCheck() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
sinceLastCheck := time.Since(monitor.lastCheck).Seconds()
|
sinceLastCheck := time.Since(monitor.lastCheck)
|
||||||
|
|
||||||
return sinceLastCheck >= monitor.CheckInterval
|
return sinceLastCheck >= monitor.CheckInterval
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user