-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathcheck_proc_pmem
65 lines (55 loc) · 1.36 KB
/
check_proc_pmem
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
#!/usr/bin/env bash
# Nagios plugin to check process group memory consumption
# Origin:
# @see http://unix.stackexchange.com/questions/233944/how-to-view-summaric-memory-usage-of-groups-of-commands-instead-of-processes
# @see https://github.com/jonschipp/nagios-plugins/blob/master/check_memory.sh
# Nagios Exit Codes
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
# set default values for the thresholds
WARN=80
CRIT=90
usage()
{
cat <<EOF
Check memory consumption by process group.
Options:
-c Critical threshold as percentage (0-100) (def: 90)
-w Warning threshold as percentage (0-100) (def: 80)
Usage: $0 -p procname -w 90 -c 95
Example: $0 -p httpd -w 30 -c 40
EOF
}
while getopts "p:c:w:h" ARG;
do
case $ARG in
p) PROCNAME=$OPTARG
;;
w) WARN=$OPTARG
;;
c) CRIT=$OPTARG
;;
h) usage
exit
;;
esac
done
if [ -z $PROCNAME ]; then
usage
exit
fi
PERCENTAGE=`ps -C $PROCNAME --no-headers -o pmem | xargs | sed -e 's/ /+/g' | bc`
INTPERCENTAGE=${PERCENTAGE/.*/}
RESULT="$PROCNAME uses ${PERCENTAGE}% of memory"
if [ $INTPERCENTAGE -ge $CRIT ]; then
echo "CRITICAL: $RESULT"
exit $CRITICAL;
elif [ $INTPERCENTAGE -ge $WARN ]; then
echo "WARNING: $RESULT"
exit $WARNING;
else
echo "OK: $RESULT"
exit $OK;
fi