-
Notifications
You must be signed in to change notification settings - Fork 116
/
check_memory.sh
executable file
·61 lines (49 loc) · 1.35 KB
/
check_memory.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
# Origninal from http://blog.vergiss-blackjack.de/wp-uploads/2010/04/check_memory.txt
# Modified by Jon Schipp
# Nagios plugin to check memory consumption
# Excludes Swap and Caches so only the real memory consumption is considered
# Nagios Exit Codes
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
# set default values for the thresholds
WARN=90
CRIT=95
usage()
{
cat <<EOF
Check memory consumption excluding swap and cache to determine real usage.
Options:
-c Critical threshold as percentage (0-100) (def: 95)
-w Warning threshold as percentage (0-100) (def: 90)
Usage: $0 -w 90 -c 95
EOF
}
while getopts "c:w:h" ARG;
do
case $ARG in
w) WARN=$OPTARG
;;
c) CRIT=$OPTARG
;;
h) usage
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))
RESULT=$(echo "${PERCENTAGE}% ($((($MEM_USED)/1024)) of $((MEM_TOTAL/1024)) MB) used")
if [ $PERCENTAGE -gt $CRIT ]; then
echo "CRITICAL: $RESULT"
exit $CRITICAL;
elif [ $PERCENTAGE -gt $WARN ]; then
echo "WARNING: $RESULT"
exit $WARNING;
else
echo "OK: $RESULT"
exit $OK;
fi