Skip to content

Instantly share code, notes, and snippets.

@seidler2547
Created March 25, 2021 09:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seidler2547/762fb4c6d1cfa333f9f730eb017c47ac to your computer and use it in GitHub Desktop.
Save seidler2547/762fb4c6d1cfa333f9f730eb017c47ac to your computer and use it in GitHub Desktop.
Useful Icinga/Nagios Linux Memory check
#!/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;
}
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