summaryrefslogtreecommitdiffstats
path: root/charts.d/phpfpm.chart.sh
diff options
context:
space:
mode:
authorsafeie <safeie@163.com>2016-04-20 18:18:12 +0800
committersafeie <safeie@163.com>2016-04-20 18:18:12 +0800
commit91d6ed3a141ea1fcd88eaa1a7eb79a4a1c01a9ba (patch)
treea4d1b0478598c32b9b8ee5af1d13ccba6990d677 /charts.d/phpfpm.chart.sh
parent2ba3488444bc7a5264b8dd95157f10b88088c6a0 (diff)
update phpfpm chart suppport multi urls
Diffstat (limited to 'charts.d/phpfpm.chart.sh')
-rw-r--r--charts.d/phpfpm.chart.sh59
1 files changed, 43 insertions, 16 deletions
diff --git a/charts.d/phpfpm.chart.sh b/charts.d/phpfpm.chart.sh
index eaa20930ca..4c54aa522e 100644
--- a/charts.d/phpfpm.chart.sh
+++ b/charts.d/phpfpm.chart.sh
@@ -7,7 +7,7 @@
# second, you need add status location in nginx.conf
# you can see, https://easyengine.io/tutorials/php/fpm-status-page/
-phpfpm_url="http://localhost/status"
+declare -A phpfpm_urls=()
# _update_every is a special variable - it holds the number of seconds
# between the calls of the _update() function
@@ -29,7 +29,8 @@ phpfpm_max_active_processes=0
phpfpm_max_children_reached=0
phpfpm_slow_requests=0
phpfpm_get() {
- phpfpm_response=($(curl -s "${phpfpm_url}"))
+ url=$1
+ phpfpm_response=($(curl -s "${url}"))
[ $? -ne 0 -o "${#phpfpm_response[@]}" -eq 0 ] && return 1
if [[ "${phpfpm_response[0]}" != "pool:" \
@@ -86,9 +87,23 @@ phpfpm_get() {
# _check is called once, to find out if this chart should be enabled or not
phpfpm_check() {
- phpfpm_get
- if [ $? -ne 0 ]; then
- echo >&2 "phpfpm: cannot find status on URL '${phpfpm_url}'. Please set phpfpm_url='http://nginx.server/php_status' in $confd/phpfpm.conf"
+ if [ ${#phpfpm_urls[@]} -eq 0 ]; then
+ phpfpm_urls[local]="http://localhost/status"
+ fi
+
+ local m
+ for m in "${!phpfpm_urls[@]}"
+ do
+ phpfpm_get "${phpfpm_urls[$m]}"
+ if [ $? -ne 0 ]; then
+ echo >&2 "phpfpm: cannot find status on URL '${phpfpm_url[$m]}'. Please set phpfpm_urls[$m]='http://localhost/status' in $confd/phpfpm.conf"
+ unset phpfpm_urls[$m]
+ continue
+ fi
+ done
+
+ if [ ${#phpfpm_urls[@]} -eq 0 ]; then
+ 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"
return 1
fi
@@ -101,20 +116,24 @@ phpfpm_check() {
# _create is called once, to create the charts
phpfpm_create() {
- cat <<EOF
-CHART phpfpm.connections '' "PHP-FPM Active Connections" "connections" phpfpm phpfpm.connections line $[phpfpm_priority + 1] $phpfpm_update_every
+ local m
+ for m in "${!phpfpm_urls[@]}"
+ do
+ cat <<EOF
+CHART phpfpm_$m.connections '' "PHP-FPM Active Connections" "connections" phpfpm phpfpm.connections line $[phpfpm_priority + 1] $phpfpm_update_every
DIMENSION active '' absolute 1 1
DIMENSION maxActive 'max active' absolute 1 1
DIMENSION idle '' absolute 1 1
-CHART phpfpm.requests '' "PHP-FPM Requests" "requests/s" phpfpm phpfpm.requests line $[phpfpm_priority + 2] $phpfpm_update_every
+CHART phpfpm_$m.requests '' "PHP-FPM Requests" "requests/s" phpfpm phpfpm.requests line $[phpfpm_priority + 2] $phpfpm_update_every
DIMENSION requests '' incremental 1 1
-CHART phpfpm.performance '' "PHP-FPM Performance" "status" phpfpm phpfpm.performance line $[phpfpm_priority + 3] $phpfpm_update_every
+CHART phpfpm_$m.performance '' "PHP-FPM Performance" "status" phpfpm phpfpm.performance line $[phpfpm_priority + 3] $phpfpm_update_every
DIMENSION reached 'max children reached' absolute 1 1
DIMENSION slow 'slow requests' absolute 1 1
EOF
-
+ done
+
return 0
}
@@ -127,22 +146,30 @@ phpfpm_update() {
# for each dimension
# remember: KEEP IT SIMPLE AND SHORT
- phpfpm_get || return 1
+ local m
+ for m in "${!phpfpm_urls[@]}"
+ do
+ phpfpm_get "${phpfpm_urls[$m]}"
+ if [ $? -ne 0 ]; then
+ continue
+ fi
- # write the result of the work.
- cat <<EOF
-BEGIN phpfpm.connections $1
+ # write the result of the work.
+ cat <<EOF
+BEGIN phpfpm_$m.connections $1
SET active = $[phpfpm_active_processes]
SET maxActive = $[phpfpm_max_active_processes]
SET idle = $[phpfpm_idle_processes]
END
-BEGIN phpfpm.requests $1
+BEGIN phpfpm_$m.requests $1
SET requests = $[phpfpm_accepted_conn]
END
-BEGIN phpfpm.performance $1
+BEGIN phpfpm_$m.performance $1
SET reached = $[phpfpm_max_children_reached]
SET slow = $[phpfpm_slow_requests]
END
EOF
+ done
+
return 0
}