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 phpfpm_url="http://nginx.server/php-status"
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
32 phpfpm_response=($(curl -s "${phpfpm_url}"))
33 [ $? -ne 0 -o "${#phpfpm_response[@]}" -eq 0 ] && return 1
35 if [[ "${phpfpm_response[0]}" != "pool:" \
36 || "${phpfpm_response[2]}" != "process" \
37 || "${phpfpm_response[5]}" != "start" \
38 || "${phpfpm_response[12]}" != "accepted" \
39 || "${phpfpm_response[15]}" != "listen" \
40 || "${phpfpm_response[16]}" != "queue:" \
41 || "${phpfpm_response[26]}" != "idle" \
42 || "${phpfpm_response[29]}" != "active" \
43 || "${phpfpm_response[32]}" != "total" \
44 || "${phpfpm_response[43]}" != "slow" \
47 echo >&2 "phpfpm: invalid response from phpfpm status server: ${phpfpm_response[*]}"
51 phpfpm_pool="${phpfpm_response[1]}"
52 phpfpm_start_time="${phpfpm_response[7]} ${phpfpm_response[8]}"
53 phpfpm_start_since="${phpfpm_response[11]}"
54 phpfpm_accepted_conn="${phpfpm_response[14]}"
55 phpfpm_listen_queue="${phpfpm_response[17]}"
56 phpfpm_max_listen_queue="${phpfpm_response[21]}"
57 phpfpm_listen_queue_len="${phpfpm_response[25]}"
58 phpfpm_idle_processes="${phpfpm_response[28]}"
59 phpfpm_active_processes="${phpfpm_response[31]}"
60 phpfpm_total_processes="${phpfpm_response[34]}"
61 phpfpm_max_active_processes="${phpfpm_response[38]}"
62 phpfpm_max_children_reached="${phpfpm_response[42]}"
63 phpfpm_slow_requests="${phpfpm_response[45]}"
65 if [[ -z "${phpfpm_pool}" \
66 || -z "${phpfpm_start_time}" \
67 || -z "${phpfpm_start_since}" \
68 || -z "${phpfpm_accepted_conn}" \
69 || -z "${phpfpm_listen_queue}" \
70 || -z "${phpfpm_max_listen_queue}" \
71 || -z "${phpfpm_listen_queue_len}" \
72 || -z "${phpfpm_idle_processes}" \
73 || -z "${phpfpm_active_processes}" \
74 || -z "${phpfpm_total_processes}" \
75 || -z "${phpfpm_max_active_processes}" \
76 || -z "${phpfpm_max_children_reached}" \
77 || -z "${phpfpm_slow_requests}" \
80 echo >&2 "phpfpm: empty values got from phpfpm status server: ${phpfpm_response[*]}"
87 # _check is called once, to find out if this chart should be enabled or not
91 echo >&2 "phpfpm: cannot find status on URL '${phpfpm_url}'. Please set phpfpm_url='http://nginx.server/php_status' in $confd/phpfpm.conf"
96 # - 0 to enable the chart
97 # - 1 to disable the chart
102 # _create is called once, to create the charts
105 CHART phpfpm.connections '' "PHP-FPM Active Connections" "connections" phpfpm phpfpm.connections line $[phpfpm_priority + 1] $phpfpm_update_every
106 DIMENSION active '' absolute 1 1
107 DIMENSION maxActive 'max active' absolute 1 1
108 DIMENSION idle '' absolute 1 1
110 CHART phpfpm.requests '' "PHP-FPM Requests" "requests/s" phpfpm phpfpm.requests line $[phpfpm_priority + 2] $phpfpm_update_every
111 DIMENSION requests '' incremental 1 1
113 CHART phpfpm.performance '' "PHP-FPM Performance" "status" phpfpm phpfpm.performance line $[phpfpm_priority + 3] $phpfpm_update_every
114 DIMENSION reached 'max children reached' absolute 1 1
115 DIMENSION slow 'slow requests' absolute 1 1
121 # _update is called continiously, to collect the values
123 # the first argument to this function is the microseconds since last update
124 # pass this parameter to the BEGIN statement (see bellow).
126 # do all the work to collect / calculate the values
128 # remember: KEEP IT SIMPLE AND SHORT
130 phpfpm_get || return 1
132 # write the result of the work.
134 BEGIN phpfpm.connections $1
135 SET active = $[phpfpm_active_processes]
136 SET maxActive = $[phpfpm_max_active_processes]
137 SET idle = $[phpfpm_idle_processes]
139 BEGIN phpfpm.requests $1
140 SET requests = $[phpfpm_accepted_conn]
142 BEGIN phpfpm.performance $1
143 SET reached = $[phpfpm_max_children_reached]
144 SET slow = $[phpfpm_slow_requests]