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

36 lines
726 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/rs/zerolog/log"
"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
}
func (h HDD) Execute() (ok bool, data interface{}, err error) {
2021-09-20 11:55:47 +00:00
success := true
2021-09-20 09:28:00 +00:00
parts, _ := disk.Partitions(true)
2021-09-20 10:38:41 +00:00
log.Debug().Int("max_percent", h.Config.MaxPercent).Msg("Execute HDD Check")
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"
}