Created
November 16, 2012 17:55
-
-
Save amartinj/4089425 to your computer and use it in GitHub Desktop.
Nagios3 plugin to check free memory
This file contains 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
#!/bin/sh | |
TOTAL="`free -m | grep Mem | sed -r 's/\s+/ /g' | cut -f2 -d' '`" | |
FREE="`free -m | grep Mem | sed -r 's/\s+/ /g' | cut -f4 -d' '`" | |
FREEP="`echo "$FREE*100/$TOTAL" | bc`" | |
usage(){ | |
cat << EOF | |
usage: $0 options | |
This script tells how much of memory is available | |
OPTIONS: | |
-h Show this message | |
-c critical percentage of free memory | |
-w warning percentage of free memory | |
EOF | |
} | |
while getopts "hw:c:" OPTION | |
do | |
case $OPTION in | |
h) | |
usage() | |
exit | |
;; | |
w) | |
WARNING=$OPTARG | |
;; | |
c) | |
CRITICAL=$OPTARG | |
;; | |
esac | |
done | |
[ -z $WARNING ] && echo "MEM UNKNOWN - Need to pas -w option" && exit 3 | |
[ -z $CRITICAL ] && echo "MEM UNKNOWN - Need to pass -c option" && exit 3 | |
[ $WARNING -le $CRITICAL ] && echo "MEM UNKNOWN - -c has to be less than -w" && exit 3 | |
STATUS="OK" | |
[ $FREEP -le $WARNING ] && STATUS="WARNING" | |
[ $FREEP -le $CRITICAL ] && STATUS="CRITICAL" | |
echo "MEM $STATUS - $FREEP% free ($FREE MB out of $TOTAL MB) |mem=${FREE}MB;$WARNING;$CRITICAL;0;$TOTAL" | |
[ $STATUS = "OK" ] && exit 0 | |
[ $STATUS = "WARNING" ] && exit 1 | |
[ $STATUS = "CRITICAL" ] && exit 2 | |
exit3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment