add swap
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Kekskurse 2021-09-20 16:45:34 +02:00
parent b5196312d2
commit 96ee365569
Signed by: kekskurse
GPG key ID: 728ACCB59341E7E4
3 changed files with 11 additions and 1 deletions

View file

@ -10,3 +10,4 @@ checks:
max_load_15: 5 max_load_15: 5
memory: memory:
max: 100 max: 100
max_swap: 80

View file

@ -6,6 +6,7 @@ import (
type MemoryConfig struct { type MemoryConfig struct {
Max float64 `yaml:"max"` Max float64 `yaml:"max"`
MaxSwap float64 `yaml:"max_swap"`
} }
type Memory struct { type Memory struct {
@ -15,12 +16,17 @@ type Memory struct {
func (h Memory) Execute() (ok bool, data interface{}, err error) { func (h Memory) Execute() (ok bool, data interface{}, err error) {
memory, err := memory.Get() memory, err := memory.Get()
p := float64(100) / float64(memory.Total) * float64(memory.Used) p := float64(100) / float64(memory.Total) * float64(memory.Used)
ps := float64(100) / float64(memory.SwapTotal) * float64(memory.SwapUsed)
res := make(map[string]interface{}) res := make(map[string]interface{})
res["row"] = memory res["row"] = memory
res["ram"] = p res["ram"] = p
res["swap"] = ps
if p > h.Config.Max { if p > h.Config.Max {
return false, res, nil return false, res, nil
} }
if ps > h.Config.MaxSwap {
return false, res, nil
}
return true, res,nil return true, res,nil
} }

View file

@ -51,6 +51,8 @@
if(data.responseText != "") { if(data.responseText != "") {
handleData(data) handleData(data)
} }
setTimeout("getData();", 10000);
}); });
} }
@ -88,13 +90,14 @@
$("#rampercent").empty() $("#rampercent").empty()
$("#rampercent").append('<b>Ram</b><br><div class="progress"><div class="progress-bar" role="progressbar" style="width: '+o.Checks["Memory usage"].data["ram"]+'%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">' +o.Checks["Memory usage"].data["ram"]+ '%</div></div>'); $("#rampercent").append('<b>Ram</b><br><div class="progress"><div class="progress-bar" role="progressbar" style="width: '+o.Checks["Memory usage"].data["ram"]+'%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">' +o.Checks["Memory usage"].data["ram"]+ '%</div></div>');
$("#rampercent").append('<b>Swap</b><br><div class="progress"><div class="progress-bar" role="progressbar" style="width: '+o.Checks["Memory usage"].data["swap"]+'%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">' +o.Checks["Memory usage"].data["swap"]+ '%</div></div>');
console.log(keys) console.log(keys)
console.log(o.Checks["Disc space"].success) console.log(o.Checks["Disc space"].success)
setTimeout("getData();", 10000);
} }
getData(); getData();
</script> </script>