forked from skyscrapers/monitoring-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_unicorn_memory
executable file
·58 lines (52 loc) · 1.93 KB
/
check_unicorn_memory
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
#!/bin/bash
## check_unicorn_memory.sh for check_unicorn_memory_compat in /Users/scalp/nagios/check_unicorn_memory
##
## Made by Anthony Scalisi
## <[email protected]>
##
## Started on Wed May 30 11:55:22 2012 Anthony Scalisi
## Last update Wed Oct 24 16:34:13 2012 Anthony Scalisi
##
OK_STATE=0
WARNING_STATE=1
CRITICAL_STATE=2
UNKNOWN_STATE=3
EXPECTED_ARGS=4
E_BADARGS=65
pid_file="`find /var/www -name *.pid`"
pids_folder="`dirname $pid_file`"
if [[ "$#" -ne "$EXPECTED_ARGS" || "$1" != '-w' || "$3" != '-c' ]]; then
echo "Usage: `basename $0` -w worker_memory_MiB -c worker_memory_MiB"
exit ${UNKNOWN_STATE}
elif [[ "$4" -lt "$2" ]]; then
echo "UNKNOWN - Critical value < Warning value. Please verify parameters."
exit ${UNKNOWN_STATE}
elif [[ "$2" -le 0 || "$4" -le 0 ]]; then
echo "UNKNOWN - Warning or Critical values can't be negative. Please verify parameters."
exit ${UNKNOWN_STATE}
fi
if [[ -s $pids_folder/unicorn.pid ]]; then
pid_master=(`cat $pids_folder/unicorn.pid`)
pids=(`ps awx | egrep "unicorn*" | egrep -v "grep|tail|nagios|nano|vi|$pid_master" | awk '{print $1}' | tr '\n' ' '`)
else
pids=(`ps awx | egrep "unicorn*" | egrep -v "grep|tail|nagios|nano|vi" | awk '{print $1}' | tr '\n' ' '`)
fi
if [[ -s $pids_folder/unicorn.pid ]]; then
for i in ${pids[@]}; do
mem=`/usr/bin/pmap ${pids[$count]} | tail -n 1 | awk '{print $2}' | sed 's/K/ \/ 1000/;s/G/ * 1000/' | bc`
if [[ "$mem" -ge $2 && "$mem" -lt $4 ]]; then
echo "WARNING - Unicorn worker memory high : $mem mb"
exit ${WARNING_STATE}
elif [[ "$mem" -ge $2 && "$mem" -ge $4 ]]; then
echo "CRITICAL - Unicorn worker memory too high : $mem mb"
exit ${CRITICAL_STATE}
else
(( count++ ))
fi
done
echo "OK - Unicorn worker memory usage : $mem mb"
exit ${OK_STATE}
else
echo "UNKNOWN - No Unicorn processes found."
exit ${UNKNOWN_STATE}
fi