@cryptotaxi247 / netdata-1 / commits / 91d6ed3a1

update phpfpm chart suppport multi urls

safeie committed Apr 20, 2016 at 18:18 UTC 91d6ed3a141ea1fcd88eaa1a7eb79a4a1c01a9ba
1 file changed +43 -16
charts.d/phpfpm.chart.sh
+43 -16
@@ -7,7 +7,7 @@
7 # second, you need add status location in nginx.conf
8 # you can see, https://easyengine.io/tutorials/php/fpm-status-page/
9
10 -phpfpm_url="http://localhost/status"
10 +declare -A phpfpm_urls=()
11
12 # _update_every is a special variable - it holds the number of seconds
13 # between the calls of the _update() function
@@ -29,7 +29,8 @@ phpfpm_max_active_processes=0
29 phpfpm_max_children_reached=0
30 phpfpm_slow_requests=0
31 phpfpm_get() {
32 - phpfpm_response=($(curl -s "${phpfpm_url}"))
32 + url=$1
33 + phpfpm_response=($(curl -s "${url}"))
34 [ $? -ne 0 -o "${#phpfpm_response[@]}" -eq 0 ] && return 1
35
36 if [[ "${phpfpm_response[0]}" != "pool:" \
@@ -86,9 +87,23 @@ phpfpm_get() {
87
88 # _check is called once, to find out if this chart should be enabled or not
89 phpfpm_check() {
89 - phpfpm_get
90 - if [ $? -ne 0 ]; then
91 - echo >&2 "phpfpm: cannot find status on URL '${phpfpm_url}'. Please set phpfpm_url='http://nginx.server/php_status' in $confd/phpfpm.conf"
90 + if [ ${#phpfpm_urls[@]} -eq 0 ]; then
91 + phpfpm_urls[local]="http://localhost/status"
92 + fi
93 +
94 + local m
95 + for m in "${!phpfpm_urls[@]}"
96 + do
97 + phpfpm_get "${phpfpm_urls[$m]}"
98 + if [ $? -ne 0 ]; then
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]
101 + continue
102 + fi
103 + done
104 +
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"
107 return 1
108 fi
109
@@ -101,20 +116,24 @@ phpfpm_check() {
116
117 # _create is called once, to create the charts
118 phpfpm_create() {
104 - cat <<EOF
105 -CHART phpfpm.connections '' "PHP-FPM Active Connections" "connections" phpfpm phpfpm.connections line $[phpfpm_priority + 1] $phpfpm_update_every
119 + local m
120 + for m in "${!phpfpm_urls[@]}"
121 + do
122 + cat <<EOF
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
127
110 -CHART phpfpm.requests '' "PHP-FPM Requests" "requests/s" phpfpm phpfpm.requests line $[phpfpm_priority + 2] $phpfpm_update_every
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
130
113 -CHART phpfpm.performance '' "PHP-FPM Performance" "status" phpfpm phpfpm.performance line $[phpfpm_priority + 3] $phpfpm_update_every
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
134 EOF
117 -
135 + done
136 +
137 return 0
138 }
139
@@ -127,22 +146,30 @@ phpfpm_update() {
146 # for each dimension
147 # remember: KEEP IT SIMPLE AND SHORT
148
130 - phpfpm_get || return 1
149 + local m
150 + for m in "${!phpfpm_urls[@]}"
151 + do
152 + phpfpm_get "${phpfpm_urls[$m]}"
153 + if [ $? -ne 0 ]; then
154 + continue
155 + fi
156
132 - # write the result of the work.
133 - cat <<EOF
134 -BEGIN phpfpm.connections $1
157 + # write the result of the work.
158 + cat <<EOF
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]
163 END
139 -BEGIN phpfpm.requests $1
164 +BEGIN phpfpm_$m.requests $1
165 SET requests = $[phpfpm_accepted_conn]
166 END
142 -BEGIN phpfpm.performance $1
167 +BEGIN phpfpm_$m.performance $1
168 SET reached = $[phpfpm_max_children_reached]
169 SET slow = $[phpfpm_slow_requests]
170 END
171 EOF
172 + done
173 +
174 return 0
175 }