check-health: reverse logic for RAM (free -> utilization)...

... to bring it in sync with CPU utilization.

Also make the output more verbose, at least for the warning.

---- ✂️ ----
🗃️📈️ Health warning: RAM utilization

The RAM utilization on MikroTik is at 81%!

total:          64 MiB
used:           52 MiB
free:           11 MiB
---- ✂️ ----
🗃️📉️ Health recovery: RAM utilization

The RAM utilization on MikroTik decreased to 65%.
---- ✂️ ----
This commit is contained in:
Christian Hesse 2023-10-24 16:26:14 +02:00
parent d4e5194a65
commit ff35f0c87f
6 changed files with 20 additions and 19 deletions

View file

@ -12,8 +12,8 @@
:global CheckHealthCPUUtilization; :global CheckHealthCPUUtilization;
:global CheckHealthCPUUtilizationNotified; :global CheckHealthCPUUtilizationNotified;
:global CheckHealthFreeRAMNotified;
:global CheckHealthLast; :global CheckHealthLast;
:global CheckHealthRAMUtilizationNotified;
:global CheckHealthTemperature; :global CheckHealthTemperature;
:global CheckHealthTemperatureDeviation; :global CheckHealthTemperatureDeviation;
:global CheckHealthTemperatureNotified; :global CheckHealthTemperatureNotified;
@ -52,20 +52,21 @@ $ScriptLock $0;
:set CheckHealthCPUUtilizationNotified false; :set CheckHealthCPUUtilizationNotified false;
} }
:local CheckHealthFreeRAM ($Resource->"free-memory" * 100 / $Resource->"total-memory"); :local CheckHealthRAMUtilization (($Resource->"total-memory" - $Resource->"free-memory") * 100 / $Resource->"total-memory");
:if ($CheckHealthFreeRAM < 20 && $CheckHealthFreeRAMNotified != true) do={ :if ($CheckHealthRAMUtilization >=80 && $CheckHealthRAMUtilizationNotified != true) do={
$SendNotification2 ({ origin=$0; \ $SendNotification2 ({ origin=$0; \
subject=([ $SymbolForNotification "card-file-box,chart-decreasing" ] . "Health warning: free RAM"); \ subject=([ $SymbolForNotification "card-file-box,chart-increasing" ] . "Health warning: RAM utilization"); \
message=("The available free RAM on " . $Identity . " is at " . $CheckHealthFreeRAM . "% (" . \ message=("The RAM utilization on " . $Identity . " is at " . $CheckHealthRAMUtilization . "%!\n\n" . \
($Resource->"free-memory" / 1024 / 1024) . "MiB)!") }); [ $FormatLine "total" (($Resource->"total-memory" / 1024 / 1024) . " MiB") ] . "\n" . \
:set CheckHealthFreeRAMNotified true; [ $FormatLine "used" ((($Resource->"total-memory" - $Resource->"free-memory") / 1024 / 1024) . " MiB") ] . "\n" . \
[ $FormatLine "free" (($Resource->"free-memory" / 1024 / 1024) . " MiB") ]) });
:set CheckHealthRAMUtilizationNotified true;
} }
:if ($CheckHealthFreeRAM > 30 && $CheckHealthFreeRAMNotified = true) do={ :if ($CheckHealthRAMUtilization < 70 && $CheckHealthRAMUtilizationNotified = true) do={
$SendNotification2 ({ origin=$0; \ $SendNotification2 ({ origin=$0; \
subject=([ $SymbolForNotification "card-file-box,chart-increasing" ] . "Health recovery: free RAM"); \ subject=([ $SymbolForNotification "card-file-box,chart-decreasing" ] . "Health recovery: RAM utilization"); \
message=("The available free RAM on " . $Identity . " increased to " . $CheckHealthFreeRAM . "% (" . \ message=("The RAM utilization on " . $Identity . " decreased to " . $CheckHealthRAMUtilization . "%.") });
($Resource->"free-memory" / 1024 / 1024) . "MiB).") }); :set CheckHealthRAMUtilizationNotified false;
:set CheckHealthFreeRAMNotified false;
} }
:if ([ :len [ /system/health/find ] ] = 0) do={ :if ([ :len [ /system/health/find ] ] = 0) do={

View file

@ -13,7 +13,7 @@ This script is run from scheduler periodically, sending notification on
health related events: health related events:
* high CPU utilization * high CPU utilization
* low available free RAM * high RAM utilization (low available RAM)
* voltage jumps up or down more than configured threshold * voltage jumps up or down more than configured threshold
* voltage drops below hard lower limit * voltage drops below hard lower limit
* power supply failed or recovered * power supply failed or recovered
@ -21,9 +21,9 @@ health related events:
Note that bad initial state will not trigger an event. Note that bad initial state will not trigger an event.
Monitoring CPU utilization and available free RAM works on all devices. Monitoring CPU and RAM utilization (available processing and memory
Other than that only sensors available in hardware can be checked. See what resources) works on all devices. Other than that only sensors available
your hardware supports: in hardware can be checked. See what your hardware supports:
/system/health/print; /system/health/print;
@ -34,10 +34,10 @@ your hardware supports:
![check-health notification cpu utilization high](check-health.d/notification-01-cpu-utilization-high.avif) ![check-health notification cpu utilization high](check-health.d/notification-01-cpu-utilization-high.avif)
![check-health notification cpu utilization ok](check-health.d/notification-02-cpu-utilization-ok.avif) ![check-health notification cpu utilization ok](check-health.d/notification-02-cpu-utilization-ok.avif)
#### Available free RAM #### RAM utilization (low available RAM)
![check-health notification free ram low](check-health.d/notification-03-free-ram-low.avif) ![check-health notification ram utilization high](check-health.d/notification-03-ram-utilization-high.avif)
![check-health notification free ram ok](check-health.d/notification-04-free-ram-ok.avif) ![check-health notification ram utilization ok](check-health.d/notification-04-ram-utilization-ok.avif)
#### Voltage #### Voltage