2021-09-20 09:28:00 +00:00
|
|
|
package checks
|
|
|
|
|
|
|
|
import (
|
2021-09-20 21:22:02 +00:00
|
|
|
"fmt"
|
2021-09-20 09:28:00 +00:00
|
|
|
"github.com/mackerelio/go-osstat/memory"
|
|
|
|
)
|
|
|
|
|
2021-09-20 11:19:05 +00:00
|
|
|
type MemoryConfig struct {
|
2021-09-20 10:38:41 +00:00
|
|
|
Max float64 `yaml:"max"`
|
2021-09-20 14:45:34 +00:00
|
|
|
MaxSwap float64 `yaml:"max_swap"`
|
2021-09-20 10:38:41 +00:00
|
|
|
}
|
2021-09-20 09:28:00 +00:00
|
|
|
|
2021-09-20 10:38:41 +00:00
|
|
|
type Memory struct {
|
2021-09-20 11:19:05 +00:00
|
|
|
Config MemoryConfig
|
2021-09-20 09:28:00 +00:00
|
|
|
}
|
|
|
|
|
2021-09-20 11:19:05 +00:00
|
|
|
func (h Memory) Execute() (ok bool, data interface{}, err error) {
|
2021-09-20 09:28:00 +00:00
|
|
|
memory, err := memory.Get()
|
2021-09-20 21:22:02 +00:00
|
|
|
fmt.Println(memory)
|
2021-09-20 09:28:00 +00:00
|
|
|
p := float64(100) / float64(memory.Total) * float64(memory.Used)
|
2021-09-20 14:45:34 +00:00
|
|
|
ps := float64(100) / float64(memory.SwapTotal) * float64(memory.SwapUsed)
|
2021-09-20 14:27:05 +00:00
|
|
|
res := make(map[string]interface{})
|
|
|
|
res["row"] = memory
|
|
|
|
res["ram"] = p
|
2021-09-20 14:45:34 +00:00
|
|
|
res["swap"] = ps
|
2021-09-20 21:22:02 +00:00
|
|
|
if memory.SwapTotal == 0 {
|
|
|
|
res["swap"] = 100
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(ps)
|
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:45:34 +00:00
|
|
|
if ps > h.Config.MaxSwap {
|
|
|
|
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 {
|
2021-11-25 01:01:27 +00:00
|
|
|
return "MemoryUsage"
|
2021-09-20 09:28:00 +00:00
|
|
|
}
|