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

33 lines
589 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, err error) {
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 09:28:00 +00:00
for _, p := range parts {
device := p.Mountpoint
s, _ := disk.Usage(device)
2021-09-20 10:38:41 +00:00
if s.UsedPercent > float64(h.Config.MaxPercent) {
2021-09-20 09:28:00 +00:00
return false, nil
}
}
return true, nil
}
func (h HDD) Name() string {
return "Disc space"
}