From d3094421ba6ed067f92d22553869409ed68b36fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Sch=C3=A4ferdiek?= Date: Tue, 21 Jan 2020 08:09:10 +0100 Subject: [PATCH] Use total-used for memory usage indication instead of allocated and cached memory --- usr/local/bin/memory_usage_alert | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/usr/local/bin/memory_usage_alert b/usr/local/bin/memory_usage_alert index 40c0837..6ee3be0 100755 --- a/usr/local/bin/memory_usage_alert +++ b/usr/local/bin/memory_usage_alert @@ -27,7 +27,7 @@ set -e; HOSTNAME=$(hostname) SUBJECT="[memory $HOSTNAME] memory is low" MEMORY_USAGE_ALERT_MAIL_ADDRESS=""; -MEMORY_USAGE_ALERT_THRESHOLD=128; +MEMORY_USAGE_ALERT_THRESHOLD=512; # check for config file source_config() { @@ -52,7 +52,9 @@ source_config() { source_config "$1" "$HOME/.memory_usage_alert.conf" # DO NOT TOUCH BELOW -free=$(free -mt | grep Total | awk '{print $4}') +total=$(free -mt | grep Total | awk '{print $2}') +used=$(free -mt | grep Total | awk '{print $3}') +free=$(($total-$used)) if [[ "$free" -le $MEMORY_USAGE_ALERT_THRESHOLD ]]; then ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head >/tmp/top_proccesses_consuming_memory.txt