From 7594ba6bd763505aff077205301790ae1db8d573 Mon Sep 17 00:00:00 2001 From: Chl Date: Thu, 25 Apr 2024 19:14:03 +0200 Subject: [PATCH] nagios: another enhancement for check_linux_memory2 --- nagios/check_linux_memory2.sh | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/nagios/check_linux_memory2.sh b/nagios/check_linux_memory2.sh index f0bf4c4..5c27142 100755 --- a/nagios/check_linux_memory2.sh +++ b/nagios/check_linux_memory2.sh @@ -33,6 +33,7 @@ Options: -n = Don't Include cached memory as free memory when calculating your percentage free -K = Don't check the OutOfMemory Kill counter -k [0-9999] = Threshold for OOMKill alert (default: 0) + -A = Don't check awk capabilities (as of 2024: mawk can't printf an integer over 2^31) EOF } @@ -50,6 +51,7 @@ invalid_type() { while test -n "$1"; do case $1 in --help) print_help ; exit 0 ;; + -A) AWK_CHECK=0 ;; -h) print_help ; exit 0 ;; -w) WARN="$2"; shift ;; -c) CRIT="$2"; shift ;; @@ -70,8 +72,18 @@ done [ -z "$DIV" ] && DIV=M [ -z "$FC" ] && FC=0 [ -z "$DISABLE_OOMKILL" ] && DISABLE_OOMKILL="" +[ -z "$AWK_CHECK" ] && AWK_CHECK=1 [ -z "$THRESHOLD_OOMKILL" ] && THRESHOLD_OOMKILL=0 +############################################## +## Check awk capabilities +############################################## + +if [ "$AWK_CHECK" -gt 0 ] && [ "$( awk 'BEGIN{ printf "%ld", 3000000000 }' )" != "3000000000" ]; then + echo "UNKNOWN this version of awk is not able to display big numbers." + exit 3 +fi + ############################################## ## Check user input ############################################## @@ -139,7 +151,18 @@ END { if ( nc != 1 ) { free=free+cache+buff } if ( oomkill > threshold_oomkill ) { result="CRITICAL - Out of memory kills detected" ; xit="2" } } { - print xit" MEMORY "result" - "freeperct"% Free - Total:"tot/divnum div" Active:"active/divnum div" Inactive:"inactive/divnum div" Buffers:"buff/divnum div" Cached:"cache/divnum div" "oomkill_display" |Active="active"B;0;0;0 Buffers="buff"B;0;0;0 Cached="cache"B;0;0;0 Free="free"B;"warn";"crit";0 Inactive="inactive"B;0;0;0"oomkill_perfdata + printf "%d MEMORY %s - %.2f%% Free - Total:%.1f%s", xit, result, freeperct, tot/divnum, div + printf " Active:%.1f%s", active/divnum, div + printf " Inactive:%.1f%s", inactive/divnum, div + printf " Buffers:%.1f%s", buff/divnum, div + printf " Cached:%.1f%s", cache/divnum, div + printf "%s", oomkill_display + printf " |Active=%ldB;;;0;%ld", active, tot + printf " Buffers=%ldB;;;0;%ld", buff, tot + printf " Cached=%ldB;;;0;%ld", cache, tot + printf " Free=%ldB;%ld;%ld;0;%ld", free, warn, crit, tot + printf " Inactive=%ldB;;;0;%ld", inactive, tot + printf "%s", oomkill_perfdata } }' "$MEMINFO" "$OOMKILLINFO" )