-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_fcgi.sh
86 lines (75 loc) · 1.65 KB
/
check_fcgi.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
#!/bin/bash
#
# author: danievanzyl (https://github.com/danievanzyl)
# version: 1.0
# license: http://www.apache.org/licenses/LICENSE-2.0.html
# read changelog for most up-to-date changes
##########################
#Global Variables
exit_status=-1
msg=""
fcgi=$(which cgi-fcgi)
TMP=$(mktemp /tmp/check_phpfpm.XXXXX)
STATUS[0]="OK - "
STATUS[1]="WARNING - "
STATUS[2]="CRITICAL - "
STATUS[3]="UNKNOWN - "
#Functions
#
function display_usage {
echo -ne "\tUsage: \n"
echo -ne "\t\t$0 <ip> <port>\n"
echo -ne "\t\te.g. $0 127.0.0.1 9000\n"
}
function clean_up {
rm -f $TMP
}
function check_fcgi {
local _host=$1
local _port=$2
local _tmp=$3
#execute command
SCRIPT_NAME=/status \
SCRIPT_FILENAME=/status \
REQUEST_METHOD=GET \
QUERY_STRING= \
$fcgi -bind -connect $_host:$_port > $_tmp 2>/dev/null
return $?
}
function main {
local _host=$1
local _port=$2
local perf=""
#trap on exit cleanup function
trap clean_up EXIT
#run fcgi command
check_fcgi $_host $_port $TMP
if [[ "$?" -ge "1" ]]; then
echo "General Error - fcgi command not found, please install"
exit 255
fi
#check if file is empty
if [[ -s $TMP ]];then
pool_name=$(awk '/pool:/ {print $2}' $TMP)
p_active=$(awk -F : '/^active processes:/ {print $2}' $TMP)
p_total=$(awk -F : '/total processes:/ {print $2} ' $TMP)
perf="procs=$p_active;$p_total;"
msg="Pool $pool_name listening on $_host:$_port"
exit_status=0
else
msg="Could not connect to $host:$port"
exit_status=2
fi
echo ${STATUS[$exit_status]} $msg "|" $perf
exit $exit_status
}
#
#EOFunctions
# check arguments
if [[ "$#" -lt "2" ]];then
display_usage
exit 1
else
#then run main function
main $1 $2
fi