-
Notifications
You must be signed in to change notification settings - Fork 5
/
check_mem.sh
103 lines (83 loc) · 1.94 KB
/
check_mem.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
#
# evaluate free system memory from Linux based systems
#
# Date: 2007-11-12
# Author: Thomas Borger - ESG
#
# Percent Version - MAB - mab@mab.net
#
#
#
# the memory check is done with following command line:
# free -m | grep buffers/cache | awk '{ print $4 }'
# get arguments
while getopts 'w:c:hp' OPT; do
case $OPT in
w) int_warn=$OPTARG;;
c) int_crit=$OPTARG;;
h) hlp="yes";;
p) perform="yes";;
*) unknown="yes";;
esac
done
# usage
HELP="
usage: $0 [ -w value -c value -p -h ]
syntax:
-w --> Warning % value
-c --> Critical % value
-p --> print out performance data
-h --> print this help screen
"
if [ "$hlp" = "yes" -o $# -lt 1 ]; then
echo "$HELP"
exit 0
fi
# get free memory
TMEM=`free -m | grep Mem | awk '{ print $2 }'`
FMEM=`free -m | grep buffers/cache | awk '{ print $4 }'`
FMEMpc=$(($FMEM * 100 / $TMEM))
# output with or without performance data
if [ "$perform" = "yes" ]; then
OUTPUTP="free system memory: ${FMEM}MB (${FMEMpc}%) | 'free_memory'=${FMEM}M;;;0,${TMEM} 'percent_free'=${FMEMpc}%;$int_warn;$int_crit;;"
else
OUTPUT="free system memory: ${FMEM}MB (${FMEMpc}%)"
fi
if [ -n "$int_warn" -a -n "$int_crit" ]; then
err=0
if (( $FMEMpc <= $int_warn )); then
err=1
elif (( $FMEMpc <= $int_crit )); then
err=2
fi
if (( $err == 0 )); then
if [ "$perform" = "yes" ]; then
echo -n "OK - $OUTPUTP"
exit "$err"
else
echo -n "OK - $OUTPUT"
exit "$err"
fi
elif (( $err == 1 )); then
if [ "$perform" = "yes" ]; then
echo -n "WARNING - $OUTPUTP"
exit "$err"
else
echo -n "WARNING - $OUTOUT"
exit "$err"
fi
elif (( $err == 2 )); then
if [ "$perform" = "yes" ]; then
echo -n "CRITICAL - $OUTPUTP"
exit "$err"
else
echo -n "CRITICAL - $OUTPUT"
exit "$err"
fi
fi
else
echo -n "no output from plugin"
exit 3
fi
exit