-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_fpm
executable file
·45 lines (33 loc) · 1.08 KB
/
check_fpm
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
#!/bin/bash
. $(dirname $0)/lib.sh
HOST="localhost:9000"
URL="/status"
while getopts "h:u:" OPT; do
case $OPT in
h) HOST=$OPTARG ;;
u) URL=$OPTARG ;;
esac
done
RS=$(REQUEST_METHOD=GET SCRIPT_NAME=$URL SCRIPT_FILENAME=$URL QUERY_STRING=xml \
cgi-fcgi -bind -connect $HOST 2>/dev/null)
if [[ $? != 0 ]]; then
echo "CRITICAL - Failed to connect to PHP-FPM"
exit $STATE_CRITICAL
fi
STATUS=$(sed -n '1,/^\r$/{/^Status: /{s///;s/^\([0-9]*\).*/\1/p}}' <<< "$RS")
if [[ $STATUS && $STATUS != 200 ]]; then
echo "CRITICAL - Status code of PHP-FPM response is $STATUS"
exit $STATE_CRITICAL
fi
VARS=$(sed '1,/^\r$/d' <<< "$RS" | xmlstarlet sel -t -m '/status/*' \
-v 'name()' -o = -v . -n 2>/dev/null)
if [[ $? != 0 ]]; then
echo "CRITICAL - Could not parse PHP-FPM response"
exit $STATE_CRITICAL
fi
eval $(sed 'y/-/_/;s/[^=]*/\U\0/' <<< "$VARS")
echo "OK - up $((START_SINCE / 86400)) days - \
accepted $ACCEPTED_CONN connections - \
max. $MAX_LISTEN_QUEUE connections queued of $LISTEN_QUEUE_LEN queue length|\
queue=$LISTEN_QUEUE idle=$IDLE_PROCESSES active=$ACTIVE_PROCESSES"
exit $STATE_OK