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

27 lines
472 B
Go
Raw Normal View History

2021-09-20 09:28:00 +00:00
package checks
import (
"github.com/mackerelio/go-osstat/memory"
)
type MemoryConfig struct {
2021-09-20 10:38:41 +00:00
Max float64 `yaml:"max"`
}
2021-09-20 09:28:00 +00:00
2021-09-20 10:38:41 +00:00
type Memory struct {
Config MemoryConfig
2021-09-20 09:28:00 +00:00
}
func (h Memory) Execute() (ok bool, data interface{}, err error) {
2021-09-20 09:28:00 +00:00
memory, err := memory.Get()
p := float64(100) / float64(memory.Total) * float64(memory.Used)
2021-09-20 10:38:41 +00:00
if p > h.Config.Max {
2021-09-20 11:55:47 +00:00
return false, memory, nil
2021-09-20 09:28:00 +00:00
}
2021-09-20 11:55:47 +00:00
return true, memory,nil
2021-09-20 09:28:00 +00:00
}
func (h Memory) Name() string {
return "Memory usage"
}