Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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