From 8157c222f4cbcd52e06367f2c16a7e9a7b0620f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= <26327373+vkucera@users.noreply.github.com> Date: Mon, 23 Mar 2026 22:49:43 +0100 Subject: [PATCH] Tag only users with high memory consumption --- monitor_system.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/monitor_system.sh b/monitor_system.sh index f224230..2ec8dc5 100755 --- a/monitor_system.sh +++ b/monitor_system.sh @@ -48,11 +48,11 @@ check_memory() { if [[ "$HARD" -eq 1 ]]; then logfile="${FILE_BASE}/memory_full" memory_min=$((MEMORY_LIMIT_HARD * memory_total / 100)) - message="${TITLE_WARNING}@all Available memory is almost **EXHAUSTED**: $((memory_available / 1048576)) GiB (threshold $((memory_min / 1048576)) GiB)" + message="${TITLE_WARNING}Available memory is almost **EXHAUSTED**: $((memory_available / 1048576)) GiB (threshold $((memory_min / 1048576)) GiB)" else logfile="${FILE_BASE}/memory_getting_full" memory_min=$((MEMORY_LIMIT_SOFT * memory_total / 100)) - message="${TITLE_WARNING}@all Available memory is low: $((memory_available / 1048576)) GiB (threshold $((memory_min / 1048576)) GiB)" + message="${TITLE_WARNING}Available memory is low: $((memory_available / 1048576)) GiB (threshold $((memory_min / 1048576)) GiB)" fi if ((memory_available >= memory_min)); then rm -f "${logfile}" @@ -62,9 +62,12 @@ check_memory() { return 0 fi date +"%F_%H-%M-%S" > "${logfile}" + table="$(ps S -e --no-headers -o user:20,pss | awk '{m[$1] += $2; m["total"] += $2} END{for(u in m) if (m[u] > 10 * 1048576) {print u, m[u]}}' | sort -rnk 2 | awk '{printf "| %s | %.0f |\\n", $1, $2 / 1048576}')" + users="$(echo -e "$table" | awk '(NR > 1 && $0 != "") {users[$2] = 1} END{for (u in users) {printf "@%s ", u}}')" local text="${message}\n" + text+="Please check. ${users}\n" text+="\n| user | usage [GiB] |\n|---|---|\n" - text+="$(ps S -e --no-headers -o user:20,pss | awk '{m[$1] += $2; m["total"] += $2} END{for(u in m) {print u, m[u]}}' | sort -rnk 2 | head -5 | awk '{printf "| %s | %.0f |\\n", $1, $2 / 1048576}')" + text+="$table" notify_mattermost "$text" }