3 # if this chart is called X.chart.sh, then all functions and global variables
6 # first, you need open php-fpm status in php-fpm.conf
7 # second, you need add status location in nginx.conf
8 # you can see, https://easyengine.io/tutorials/php/fpm-status-page/
10 declare -A phpfpm_urls=()
12 # _update_every is a special variable - it holds the number of seconds
13 # between the calls of the _update() function
17 declare -a phpfpm_response=()
21 phpfpm_accepted_conn=0
23 phpfpm_max_listen_queue=0
24 phpfpm_listen_queue_len=0
25 phpfpm_idle_processes=0
26 phpfpm_active_processes=0
27 phpfpm_total_processes=0
28 phpfpm_max_active_processes=0
29 phpfpm_max_children_reached=0
30 phpfpm_slow_requests=0
33 phpfpm_response=($(curl -Ss "${url}"))
34 [ $? -ne 0 -o "${#phpfpm_response[@]}" -eq 0 ] && return 1
36 if [[ "${phpfpm_response[0]}" != "pool:" \
37 || "${phpfpm_response[2]}" != "process" \
38 || "${phpfpm_response[5]}" != "start" \
39 || "${phpfpm_response[12]}" != "accepted" \
40 || "${phpfpm_response[15]}" != "listen" \
41 || "${phpfpm_response[16]}" != "queue:" \
42 || "${phpfpm_response[26]}" != "idle" \
43 || "${phpfpm_response[29]}" != "active" \
44 || "${phpfpm_response[32]}" != "total" \
45 || "${phpfpm_response[43]}" != "slow" \
48 echo >&2 "phpfpm: invalid response from phpfpm status server: ${phpfpm_response[*]}"
52 phpfpm_pool="${phpfpm_response[1]}"
53 phpfpm_start_time="${phpfpm_response[7]} ${phpfpm_response[8]}"
54 phpfpm_start_since="${phpfpm_response[11]}"
55 phpfpm_accepted_conn="${phpfpm_response[14]}"
56 phpfpm_listen_queue="${phpfpm_response[17]}"
57 phpfpm_max_listen_queue="${phpfpm_response[21]}"
58 phpfpm_listen_queue_len="${phpfpm_response[25]}"
59 phpfpm_idle_processes="${phpfpm_response[28]}"
60 phpfpm_active_processes="${phpfpm_response[31]}"
61 phpfpm_total_processes="${phpfpm_response[34]}"
62 phpfpm_max_active_processes="${phpfpm_response[38]}"
63 phpfpm_max_children_reached="${phpfpm_response[42]}"
64 phpfpm_slow_requests="${phpfpm_response[45]}"
66 if [[ -z "${phpfpm_pool}" \
67 || -z "${phpfpm_start_time}" \
68 || -z "${phpfpm_start_since}" \
69 || -z "${phpfpm_accepted_conn}" \
70 || -z "${phpfpm_listen_queue}" \
71 || -z "${phpfpm_max_listen_queue}" \
72 || -z "${phpfpm_listen_queue_len}" \
73 || -z "${phpfpm_idle_processes}" \
74 || -z "${phpfpm_active_processes}" \
75 || -z "${phpfpm_total_processes}" \
76 || -z "${phpfpm_max_active_processes}" \
77 || -z "${phpfpm_max_children_reached}" \
78 || -z "${phpfpm_slow_requests}" \
81 echo >&2 "phpfpm: empty values got from phpfpm status server: ${phpfpm_response[*]}"
88 # _check is called once, to find out if this chart should be enabled or not
90 if [ ${#phpfpm_urls[@]} -eq 0 ]; then
91 phpfpm_urls[local]="http://localhost/status"
95 for m in "${!phpfpm_urls[@]}"
97 phpfpm_get "${phpfpm_urls[$m]}"
99 echo >&2 "phpfpm: cannot find status on URL '${phpfpm_url[$m]}'. Please set phpfpm_urls[$m]='http://localhost/status' in $confd/phpfpm.conf"
100 unset phpfpm_urls[$m]
105 if [ ${#phpfpm_urls[@]} -eq 0 ]; then
106 echo >&2 "phpfpm: no phpfpm servers found. Please set phpfpm_urls[name]='url' to whatever needed to get status to the phpfpm server, in $confd/phpfpm.conf"
110 # this should return:
111 # - 0 to enable the chart
112 # - 1 to disable the chart
117 # _create is called once, to create the charts
120 for m in "${!phpfpm_urls[@]}"
123 CHART phpfpm_$m.connections '' "PHP-FPM Active Connections" "connections" phpfpm phpfpm.connections line $[phpfpm_priority + 1] $phpfpm_update_every
124 DIMENSION active '' absolute 1 1
125 DIMENSION maxActive 'max active' absolute 1 1
126 DIMENSION idle '' absolute 1 1
128 CHART phpfpm_$m.requests '' "PHP-FPM Requests" "requests/s" phpfpm phpfpm.requests line $[phpfpm_priority + 2] $phpfpm_update_every
129 DIMENSION requests '' incremental 1 1
131 CHART phpfpm_$m.performance '' "PHP-FPM Performance" "status" phpfpm phpfpm.performance line $[phpfpm_priority + 3] $phpfpm_update_every
132 DIMENSION reached 'max children reached' absolute 1 1
133 DIMENSION slow 'slow requests' absolute 1 1
140 # _update is called continiously, to collect the values
142 # the first argument to this function is the microseconds since last update
143 # pass this parameter to the BEGIN statement (see bellow).
145 # do all the work to collect / calculate the values
147 # remember: KEEP IT SIMPLE AND SHORT
150 for m in "${!phpfpm_urls[@]}"
152 phpfpm_get "${phpfpm_urls[$m]}"
153 if [ $? -ne 0 ]; then
157 # write the result of the work.
159 BEGIN phpfpm_$m.connections $1
160 SET active = $[phpfpm_active_processes]
161 SET maxActive = $[phpfpm_max_active_processes]
162 SET idle = $[phpfpm_idle_processes]
164 BEGIN phpfpm_$m.requests $1
165 SET requests = $[phpfpm_accepted_conn]
167 BEGIN phpfpm_$m.performance $1
168 SET reached = $[phpfpm_max_children_reached]
169 SET slow = $[phpfpm_slow_requests]