From 96ee36556920822443fe7e1d6045567acf620bf0 Mon Sep 17 00:00:00 2001 From: kekskurse Date: Mon, 20 Sep 2021 16:45:34 +0200 Subject: [PATCH] add swap --- config.yml | 1 + internal/pkg/checks/memory.go | 6 ++++++ template/index.html | 5 ++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/config.yml b/config.yml index ba4ff73..011bd31 100644 --- a/config.yml +++ b/config.yml @@ -10,3 +10,4 @@ checks: max_load_15: 5 memory: max: 100 + max_swap: 80 diff --git a/internal/pkg/checks/memory.go b/internal/pkg/checks/memory.go index 97cac53..fcdba5e 100644 --- a/internal/pkg/checks/memory.go +++ b/internal/pkg/checks/memory.go @@ -6,6 +6,7 @@ import ( type MemoryConfig struct { Max float64 `yaml:"max"` + MaxSwap float64 `yaml:"max_swap"` } type Memory struct { @@ -15,12 +16,17 @@ type Memory struct { func (h Memory) Execute() (ok bool, data interface{}, err error) { memory, err := memory.Get() 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 p > h.Config.Max { return false, res, nil } + if ps > h.Config.MaxSwap { + return false, res, nil + } return true, res,nil } diff --git a/template/index.html b/template/index.html index d237671..27249d5 100644 --- a/template/index.html +++ b/template/index.html @@ -51,6 +51,8 @@ if(data.responseText != "") { handleData(data) } + + setTimeout("getData();", 10000); }); } @@ -88,13 +90,14 @@ $("#rampercent").empty() $("#rampercent").append('Ram
' +o.Checks["Memory usage"].data["ram"]+ '%
'); + $("#rampercent").append('Swap
' +o.Checks["Memory usage"].data["swap"]+ '%
'); console.log(keys) console.log(o.Checks["Disc space"].success) - setTimeout("getData();", 10000); + } getData();