http-server-status/internal/pkg/checks/hdd.go
kekskurse 7643c96afb
All checks were successful
continuous-integration/drone/push Build is passing
Data
2021-09-20 13:55:47 +02:00

36 lines
No EOL
726 B
Go

package checks
import (
"github.com/rs/zerolog/log"
"github.com/shirou/gopsutil/disk"
)
type HDDConfig struct {
MaxPercent int `yaml:"max_percent"`
}
type HDD struct {
Config HDDConfig
}
func (h HDD) Execute() (ok bool, data interface{}, err error) {
success := true
parts, _ := disk.Partitions(true)
log.Debug().Int("max_percent", h.Config.MaxPercent).Msg("Execute HDD Check")
usage := make(map[string]float64)
for _, p := range parts {
device := p.Mountpoint
s, _ := disk.Usage(device)
usage[device] = s.UsedPercent
if s.UsedPercent > float64(h.Config.MaxPercent) {
success = false
//return false, parts,nil
}
}
return success, usage,nil
}
func (h HDD) Name() string {
return "Disc space"
}