-
Notifications
You must be signed in to change notification settings - Fork 171
/
Copy pathphp-fpm-check.sh
executable file
·66 lines (58 loc) · 2.13 KB
/
php-fpm-check.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
#!/bin/bash
##################################
# Zabbix monitoring script
#
# php-fpm:
# - anything available via FPM status page
#
##################################
# Contact:
##################################
# ChangeLog:
# 20100922 VV initial creation
##################################
# Zabbix requested parameter
ZBX_REQ_DATA="$1"
ZBX_REQ_DATA_URL="$2"
# Nginx defaults
NGINX_STATUS_DEFAULT_URL="http://localhost:80/php-fpm_status"
WGET_BIN="/usr/bin/wget"
#
# Error handling:
# - need to be displayable in Zabbix (avoid NOT_SUPPORTED)
# - items need to be of type "float" (allow negative + float)
#
ERROR_NO_ACCESS_FILE="-0.9900"
ERROR_NO_ACCESS="-0.9901"
ERROR_WRONG_PARAM="-0.9902"
ERROR_DATA="-0.9903" # either can not connect / bad host / bad port
# Handle host and port if non-default
if [ ! -z "$ZBX_REQ_DATA_URL" ]; then
URL="$ZBX_REQ_DATA_URL"
else
URL="$NGINX_STATUS_DEFAULT_URL"
fi
# save the nginx stats in a variable for future parsing
NGINX_STATS=$($WGET_BIN -q $URL -O - 2> /dev/null)
# error during retrieve
if [ $? -ne 0 -o -z "$NGINX_STATS" ]; then
echo $ERROR_DATA
exit 1
fi
#
# Extract data from nginx stats
#
case $ZBX_REQ_DATA in
'accepted conn') echo "$NGINX_STATS" | grep '^accepted conn:' | cut -f2 -d ':' | sed 's/\s//g';;
'active processes') echo "$NGINX_STATS" | grep '^active processes:' | cut -f2 -d ':' | sed 's/\s//g';;
'idle processes') echo "$NGINX_STATS" | grep '^idle processes:' | cut -f2 -d ':' | sed 's/\s//g';;
'listen queue len') echo "$NGINX_STATS" | grep '^listen queue len:' | cut -f2 -d ':' | sed 's/\s//g';;
'listen queue') echo "$NGINX_STATS" | grep '^listen queue:' | cut -f2 -d ':' | sed 's/\s//g';;
'max active processes') echo "$NGINX_STATS" | grep '^max active processes:' | cut -f2 -d ':' | sed 's/\s//g';;
'max children reached') echo "$NGINX_STATS" | grep '^max children reached:' | cut -f2 -d ':' | sed 's/\s//g';;
'max listen queue') echo "$NGINX_STATS" | grep '^max listen queue:' | cut -f2 -d ':' | sed 's/\s//g';;
'total processes') echo "$NGINX_STATS" | grep '^total processes:' | cut -f2 -d ':' | sed 's/\s//g';;
*) echo $ERROR_WRONG_PARAM; exit 1;;
esac
exit 0