This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
check_unicorn
executable file
·54 lines (49 loc) · 1.9 KB
/
check_unicorn
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
#!/bin/bash
## check_unicorn.sh for check_unicorn in /Users/fresh/nagios/check_unicorn
##
## Made by Anthony Scalisi
## <scalisi.a@gmail.com>
##
## Started on Mon May 28 15:25:47 2012 Anthony Scalisi
## Last update Mon May 28 18:58:21 2012 Anthony Scalisi
##
OK_STATE=0
WARNING_STATE=1
CRITICAL_STATE=2
UNKNOWN_STATE=3
EXPECTED_ARGS=2
if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` [number of workers minimum] [number of workers maximum]"
exit ${UNKNOWN_STATE}
fi
check_master=`ps awx | egrep "(unicorn|unicorn_rails) master" | grep -v grep`
check_workers=`ps awx | egrep "(unicorn|unicorn_rails) worker" | grep -v grep`
count_master=`ps awx | egrep "(unicorn|unicorn_rails) master" | grep -v grep | wc -l`
count_workers=`ps awx | egrep "(unicorn|unicorn_rails) worker" | grep -v grep | wc -l`
if [[ "$count_master" -eq 1 ]]; then
if [[ "$count_workers" -eq "$1" ]]; then
echo "OK - $count_workers unicorn workers running"
exit ${OK_STATE}
else
if [[ "$count_workers" -gt "$2" ]]; then
echo "WARNING - Too many unicorn workers ($count_workers) running."
exit ${WARNING_STATE}
elif [[ "$count_workers" -lt $1 ]]; then
echo "CRITICAL - only $count_workers unicorn workers are running !"
exit ${CRITICAL_STATE}
else
echo "OK - $count_workers unicorn workers running"
exit ${OK_STATE}
fi
fi
elif [[ "$count_master" -gt 1 ]]; then
echo "WARNING - $count_master master unicorn running at the same time!"
exit ${WARNING_STATE}
elif [[ "$count_master" -lt 1 ]]; then
echo "CRITICAL - no master unicorn running !"
exit ${CRITICAL_STATE}
else
echo "UNKNOWN - Could not figure unicorn status. Please check it out ASAP."
exit ${UNKNOW_STATE}
fi