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-11-29 05:02:41 +00:00
|
|
|
Enabled bool `yaml:"enabled"`
|
2021-09-20 10:38:41 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2021-09-20 11:19:05 +00:00
|
|
|
func (h Load) Execute() (ok bool, data interface{}, err error) {
|
2021-11-29 05:02:41 +00:00
|
|
|
if h.Config.Enabled == false {
|
|
|
|
return true, nil, nil
|
|
|
|
}
|
2021-09-20 09:28:00 +00:00
|
|
|
load, err := loadavg.Get()
|
2021-09-20 10:38:41 +00:00
|
|
|
if load.Loadavg1 > h.Config.MaxLoad1 {
|
2021-09-20 11:19:05 +00:00
|
|
|
return false,load, nil
|
2021-09-20 09:28:00 +00:00
|
|
|
}
|
|
|
|
|
2021-09-20 10:38:41 +00:00
|
|
|
if load.Loadavg5 > h.Config.MaxLoad5 {
|
2021-09-20 11:19:05 +00:00
|
|
|
return false, load, nil
|
2021-09-20 09:28:00 +00:00
|
|
|
}
|
|
|
|
|
2021-09-20 10:38:41 +00:00
|
|
|
if load.Loadavg15 > h.Config.MaxLoad15 {
|
2021-09-20 11:19:05 +00:00
|
|
|
return false, load,nil
|
2021-09-20 09:28:00 +00:00
|
|
|
}
|
|
|
|
|
2021-09-20 11:19:05 +00:00
|
|
|
return true,load, nil
|
2021-09-20 09:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h Load) Name() string {
|
2021-11-25 01:01:27 +00:00
|
|
|
return "SystemLoad"
|
2021-09-20 09:28:00 +00:00
|
|
|
}
|