Created
October 8, 2014 14:01
-
-
Save dasgoll/a106c042e0ed282cf98b to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Nagios plugin to check memory consumption | |
# Excludes Swap and Caches so only the real memory consumption is considered | |
# set default values for the thresholds | |
WARN=90 | |
CRIT=95 | |
STATE_OK=0 | |
STATE_WARN=1 | |
STATE_CRITICAL=2 | |
while getopts "c:w:h" ARG; do | |
case $ARG in | |
w) WARN=$OPTARG;; | |
c) CRIT=$OPTARG;; | |
h) echo "Usage: $0 -w <warning threshold> -c <critical threshold>"; exit;; | |
esac | |
done | |
MEM_TOTAL=`free | fgrep "Mem:" | awk '{print $2}'`; | |
MEM_USED=`free | fgrep "/+ buffers/cache" | awk '{print $3}'`; | |
PERCENTAGE=$(($MEM_USED*100/$MEM_TOTAL)) | |
echo "$PERCENTAGE% ($((($MEM_USED)/1024)) of $((MEM_TOTAL/1024)) MB) used"; | |
if [ $PERCENTAGE -gt $CRIT ]; then | |
exit $STATE_CRITICAL; | |
elif [ $PERCENTAGE -gt $WARN ]; then | |
exit $STATE_WARN; | |
else | |
exit $STATE_OK; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment