43 lines
No EOL
822 B
Go
43 lines
No EOL
822 B
Go
package checks
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/mackerelio/go-osstat/memory"
|
|
)
|
|
|
|
type MemoryConfig struct {
|
|
Max float64 `yaml:"max"`
|
|
MaxSwap float64 `yaml:"max_swap"`
|
|
}
|
|
|
|
type Memory struct {
|
|
Config MemoryConfig
|
|
}
|
|
|
|
func (h Memory) Execute() (ok bool, data interface{}, err error) {
|
|
memory, err := memory.Get()
|
|
fmt.Println(memory)
|
|
p := float64(100) / float64(memory.Total) * float64(memory.Used)
|
|
ps := float64(100) / float64(memory.SwapTotal) * float64(memory.SwapUsed)
|
|
res := make(map[string]interface{})
|
|
res["row"] = memory
|
|
res["ram"] = p
|
|
res["swap"] = ps
|
|
if memory.SwapTotal == 0 {
|
|
res["swap"] = 100
|
|
}
|
|
|
|
fmt.Println(ps)
|
|
if p > h.Config.Max {
|
|
return false, res, nil
|
|
}
|
|
if ps > h.Config.MaxSwap {
|
|
return false, res, nil
|
|
}
|
|
|
|
return true, res,nil
|
|
}
|
|
|
|
func (h Memory) Name() string {
|
|
return "Memory usage"
|
|
} |