http-server-status/internal/pkg/checks/hdd.go
kekskurse 554593a045
All checks were successful
continuous-integration/drone/push Build is passing
Need to enabled checks
2021-11-29 06:02:41 +01:00

38 lines
No EOL
709 B
Go

package checks
import (
"github.com/shirou/gopsutil/disk"
)
type HDDConfig struct {
MaxPercent int `yaml:"max_percent"`
Enabled bool `yaml:"enabled"`
}
type HDD struct {
Config HDDConfig
}
func (h HDD) Execute() (ok bool, data interface{}, err error) {
if h.Config.Enabled == false {
return true, nil, nil
}
success := true
parts, _ := disk.Partitions(false)
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 "DiscSpace"
}