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

30 lines
540 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 14:27:05 +00:00
res := make(map[string]interface{})
res["row"] = memory
res["ram"] = p
2021-09-20 10:38:41 +00:00
if p > h.Config.Max {
2021-09-20 14:27:05 +00:00
return false, res, nil
2021-09-20 09:28:00 +00:00
}
2021-09-20 14:27:05 +00:00
return true, res,nil
2021-09-20 09:28:00 +00:00
}
func (h Memory) Name() string {
return "Memory usage"
}