From 27929b8039934c5141c8d1beedd132f2bf9a4e28 Mon Sep 17 00:00:00 2001 From: kekskurse Date: Mon, 20 Sep 2021 23:22:02 +0200 Subject: [PATCH] fix memory swap issue --- internal/pkg/checks/memory.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/pkg/checks/memory.go b/internal/pkg/checks/memory.go index fcdba5e..f6cf2c1 100644 --- a/internal/pkg/checks/memory.go +++ b/internal/pkg/checks/memory.go @@ -1,6 +1,7 @@ package checks import ( + "fmt" "github.com/mackerelio/go-osstat/memory" ) @@ -15,12 +16,18 @@ type Memory struct { 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 }