http-server-status/internal/pkg/checks/load.go

36 lines
599 B
Go
Raw Normal View History

2021-09-20 09:28:00 +00:00
package checks
import (
"github.com/mackerelio/go-osstat/loadavg"
)
2021-09-20 10:38:41 +00:00
type LoadConfig struct {
MaxLoad1 float64 `yaml:"max_load_1"`
MaxLoad5 float64 `yaml:"max_load_5"`
MaxLoad15 float64 `yaml:"max_load_15"`
}
2021-09-20 09:28:00 +00:00
2021-09-20 10:38:41 +00:00
type Load struct {
Config LoadConfig
2021-09-20 09:28:00 +00:00
}
func (h Load) Execute() (ok bool, err error) {
load, err := loadavg.Get()
2021-09-20 10:38:41 +00:00
if load.Loadavg1 > h.Config.MaxLoad1 {
2021-09-20 09:28:00 +00:00
return false, nil
}
2021-09-20 10:38:41 +00:00
if load.Loadavg5 > h.Config.MaxLoad5 {
2021-09-20 09:28:00 +00:00
return false, nil
}
2021-09-20 10:38:41 +00:00
if load.Loadavg15 > h.Config.MaxLoad15 {
2021-09-20 09:28:00 +00:00
return false, nil
}
return true, nil
}
func (h Load) Name() string {
return "System Load"
}