-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphp-fpm_
executable file
·185 lines (173 loc) · 4.92 KB
/
php-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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/bash
# Looseley based on https://github.com/munin-monitoring/contrib/blob/master/plugins/php/php5-fpm_status
#################################################################
#
# Script to monitor PHP Fast Process Manager
#
#################################################################
#
# Parameters understood: config, autoconf and suggest
#
#################################################################
#
# Configuration section
#
# Configuration example
#
# [php-fpm_*]
# user root
# env.HOST 127.0.0.1 # Host to connect to
# env.PORT 9000 # TCP port number to connect to
# env.SOCKET /xx.sock # UNIX socket FPM listens to
# env.URL_PATH status # Path of status page without leading '/'
# env.CACHE_PATH # System path to store cache file
# env.CACHE_TIME # How many minutes we keep cache file
#
# NOTE: HOST:PORT and SOCKET options are mutally exclusive
#
#################################################################
#
# Changelog:
# - Added direct support to unixsockets
# - Added slow requests graph
# - First Release, Enjoy.
#
#################################################################
#################################################################
# Settigs required for autoconf
#%# family=auto
#%# capabilities=autoconf suggest
# Dependencies
BASENAME=$(which basename)
AWK=$(which awk)
FIND=$(which find)
ECHO=$(which echo)
CAT=$(which cat)
CGI_FCGI=$(which cgi-fcgi)
# Load from ENV
HOST=${HOST:-"127.0.0.1"}
PORT=${PORT:-"9000"}
URL_PATH=${URL_PATH:-"/php-fpm-status"}
CACHE_PATH=${CACHE_PATH:-"/tmp"}
CACHE_TIME=${CACHE_TIME:-"4"}
CONNECT=${SOCKET:-"${HOST}:${PORT}"}
CATEGORY="php-fpm"
BASE=$( ${BASENAME} $0 )
NAME_ROOT=$(${ECHO} "${BASE}" | ${AWK} -F"_" '{$NF=""; print $1}')
CACHE_FILE="${CACHE_PATH}/${NAME_ROOT}.munin"
TYPE=$( ${ECHO} ${BASE} | ${AWK} -F"_" '{print $NF}')
# exec 3<>/dev/tcp/127.0.0.1/8080 ; echo -e "GET /php-fpm-status HTTP/1.1\r\nHost: 127.0.0.1\r\nConnection: close\r\n\r\n" >&3 ; cat <&3 > test.txt
if [[ ! -e ${CACHE_FILE} ]] || [[ $( ${FIND} ${CACHE_FILE} ! -mmin -${CACHE_TIME} ) != "" ]]; then
# OLD STYLE
#exec 3<>/dev/tcp/${HOST}/${PORT} ; ${ECHO} -e "GET /${URL_PATH} HTTP/1.1\r\nHost: ${HOST}\r\nConnection: close\r\n\r\n" >&3 ; ${CAT} <&3 > ${CACHE_FILE}
# Based on http://www.thatsgeeky.com/2012/02/directly-connecting-to-php-fpm/
SCRIPT_NAME="${URL_PATH}" SCRIPT_FILENAME="${URL_PATH}" REQUEST_METHOD=GET ${CGI_FCGI} -bind -connect ${CONNECT} > ${CACHE_FILE}
fi
POOL=$( $AWK '/pool/{print $2}' ${CACHE_FILE} )
case $1 in
autoconf)
echo "yes"
exit 0;;
suggest)
echo "connections"
echo "processes"
echo "children"
echo "uptime"
echo "slowreq"
exit 0;;
config)
case ${TYPE} in
connections)
cat <<EOM
graph_title php5-fpm connections ${POOL}
graph_args --base 1000 -l 0
graph_vlabel requests / s
graph_category ${CATEGORY}
conns.type DERIVE
conns.label Connections
conns.draw LINE2
conns.info The number of request accepted by the pool
conns.min 0
EOM
;;
processes)
cat <<EOM
graph_title php-fpm processes ${POOL}
graph_vlabel processes
graph_category ${CATEGORY}
active.type GAUGE
active.label Active processes
active.draw AREA
active.info The number of active processes
idle.type GAUGE
idle.label Idle processes
idle.draw STACK
idle.info The number of idle processes
total.type GAUGE
total.label Total processes
total.draw LINE2
total.info The number of idle + active processes
EOM
;;
children)
cat <<EOM
graph_title php5-fpm max children reached ${POOL}
graph_args --base 1000 -l 0
graph_vlabel times
graph_category ${CATEGORY}
child.type GAUGE
child.label max children reached
child.draw LINE2
child.info Number of times, the process limit has been reached, when pm tries to start more children (works only for pm 'dynamic')
EOM
;;
uptime)
cat <<EOM
graph_title php5-fpm uptime ${POOL}
graph_args --base 1000 -l 0\n
graph_vlabel days
graph_category ${CATEGORY}
up.type GAUGE
up.label Uptime days
up.draw LINE2
up.info The number of request accepted by the pool
EOM
;;
slowreq)
cat <<EOM
graph_title php5-fpm slow requests ${POOL}
graph_args --base 1000 -l 0
graph_vlabel requests / s
graph_category ${CATEGORY}
slowreqs.type DERIVE
slowreqs.label Requests
slowreqs.draw LINE2
slowreqs.info The number of slow request served by the pool?
slowreqs.min 0
EOM
;;
esac
exit 0;;
esac
case $TYPE in
connections)
${AWK} '/^accepted conn/ {print "conns.value " $3}' < ${CACHE_FILE}
;;
processes)
${AWK} '
/^idle/ {print "idle.value " $3}
/^active/ {print "active.value " $3}
/^total/ {print "total.value " $3}
' < ${CACHE_FILE}
;;
children)
${AWK} '/^max children reached/ {print "child.value " $4}' < ${CACHE_FILE}
;;
uptime)
${AWK} '/^start since/ {print "up.value " $3/(24*60*60)}' < ${CACHE_FILE}
;;
slowreq)
${AWK} '/^slow requests/ {print "slowreqs.value " $3}' < ${CACHE_FILE}
;;
esac
exit 0