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

38 lines
709 B
Go
Raw Normal View History

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-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 HDD struct {
Config HDDConfig
2021-09-20 09:28:00 +00:00
}
func (h HDD) 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 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 {
2021-11-25 01:01:27 +00:00
return "DiscSpace"
2021-09-20 09:28:00 +00:00
}