2021-09-20 09:28:00 +00:00
|
|
|
package checks
|
|
|
|
|
2021-09-20 10:38:41 +00:00
|
|
|
import (
|
|
|
|
"github.com/shirou/gopsutil/disk"
|
|
|
|
)
|
2021-09-20 09:28:00 +00:00
|
|
|
|
2021-09-20 10:38:41 +00:00
|
|
|
type HDDConfig struct {
|
|
|
|
MaxPercent int `yaml:"max_percent"`
|
|
|
|
}
|
2021-09-20 09:28:00 +00:00
|
|
|
|
2021-09-20 10:38:41 +00:00
|
|
|
type HDD struct {
|
|
|
|
Config HDDConfig
|
2021-09-20 09:28:00 +00:00
|
|
|
}
|
|
|
|
|
2021-09-20 11:19:05 +00:00
|
|
|
func (h HDD) Execute() (ok bool, data interface{}, err error) {
|
2021-09-20 11:55:47 +00:00
|
|
|
success := true
|
2021-09-20 12:06:11 +00:00
|
|
|
parts, _ := disk.Partitions(false)
|
2021-09-20 11:55:47 +00:00
|
|
|
usage := make(map[string]float64)
|
2021-09-20 09:28:00 +00:00
|
|
|
for _, p := range parts {
|
|
|
|
device := p.Mountpoint
|
|
|
|
s, _ := disk.Usage(device)
|
2021-09-20 11:55:47 +00:00
|
|
|
usage[device] = s.UsedPercent
|
2021-09-20 10:38:41 +00:00
|
|
|
if s.UsedPercent > float64(h.Config.MaxPercent) {
|
2021-09-20 11:55:47 +00:00
|
|
|
success = false
|
|
|
|
//return false, parts,nil
|
2021-09-20 09:28:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-20 11:55:47 +00:00
|
|
|
return success, usage,nil
|
2021-09-20 09:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h HDD) Name() string {
|
|
|
|
return "Disc space"
|
|
|
|
}
|