Created
March 25, 2021 09:09
-
-
Save seidler2547/762fb4c6d1cfa333f9f730eb017c47ac to your computer and use it in GitHub Desktop.
Useful Icinga/Nagios Linux Memory check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/awk -E | |
BEGIN { | |
while ((getline <"/proc/meminfo") > 0 ) { | |
gsub(/:/,""); | |
gsub(/\(/,"_"); | |
gsub(/\)/,""); | |
a[$1]=$2; | |
u[$1]=toupper($3); | |
} | |
swapfactor=(ENVIRON["swapfactor"]~/^[0-9]+$/)?ENVIRON["swapfactor"]:0.5; | |
critical=(ENVIRON["critical"]~/^[0-9]+$/)?ENVIRON["critical"]:10; | |
warning=(ENVIRON["warning"]~/^[0-9]+$/)?ENVIRON["warning"]:20; | |
} | |
END { | |
ma=a["MemAvailable"]; | |
mt=a["MemTotal"]; | |
sf=a["SwapFree"]; | |
if (mt<10000 || ma<10) exit 3; | |
mr=100*(ma+(sf*swapfactor))/mt; | |
ec=0; | |
printf "Memory "; | |
if (mr<critical) { printf "CRITICAL"; ec=2; } else | |
if (mr<warning) { printf "WARNING"; ec=1; } else | |
printf "OK"; | |
printf ", %.1f%% (%d/%d MB + %d MB swap) available|",(ma*100/mt),(ma/1024),(mt/1024),(sf/1024); | |
for (k in a) printf k"="a[k]u[k]";;; "; | |
print ""; | |
exit ec; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object CheckCommand "mem_full" { | |
command = [ "/var/lib/nagios/check_mem_full", ] | |
env = { | |
swapfactor = "$memory_swapfactor$" | |
warning = "$memory_warning$" | |
critical = "$memory_critical$" | |
} | |
arguments = { | |
} | |
vars.memory_swapfactor = "" | |
vars.memory_warning = "" | |
vars.memory_critical = "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment