]> arthur.barton.de Git - netdata.git/blobdiff - charts.d/phpfpm.chart.sh
updated configs.signatures
[netdata.git] / charts.d / phpfpm.chart.sh
index 4c54aa522e1983c03eab87b754b269eb80ae6835..a5ee0ad561637dd3dd30571e966d1863c019ffb4 100644 (file)
@@ -1,13 +1,18 @@
-#!/bin/bash
+# no need for shebang - this file is loaded from charts.d.plugin
 
-# if this chart is called X.chart.sh, then all functions and global variables
-# must start with X_
+# netdata
+# real-time performance and health monitoring, done right!
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
+# GPL v3+
+#
+# Contributed by @safeie with PR #276
 
-# first, you need open php-fpm status in php-fpm.conf 
+# first, you need open php-fpm status in php-fpm.conf
 # second, you need add status location in nginx.conf
 # you can see, https://easyengine.io/tutorials/php/fpm-status-page/
 
 declare -A phpfpm_urls=()
+declare -A phpfpm_curl_opts=()
 
 # _update_every is a special variable - it holds the number of seconds
 # between the calls of the _update() function
@@ -29,8 +34,9 @@ phpfpm_max_active_processes=0
 phpfpm_max_children_reached=0
 phpfpm_slow_requests=0
 phpfpm_get() {
-       url=$1
-       phpfpm_response=($(curl -s "${url}"))
+       local opts="${1}" url="${2}"
+
+       phpfpm_response=($(run curl -Ss ${opts} "${url}"))
        [ $? -ne 0 -o "${#phpfpm_response[@]}" -eq 0 ] && return 1
 
        if [[ "${phpfpm_response[0]}" != "pool:" \
@@ -42,10 +48,9 @@ phpfpm_get() {
                || "${phpfpm_response[26]}" != "idle" \
                || "${phpfpm_response[29]}" != "active" \
                || "${phpfpm_response[32]}" != "total" \
-               || "${phpfpm_response[43]}" != "slow" \
        ]]
                then
-               echo >&2 "phpfpm: invalid response from phpfpm status server: ${phpfpm_response[*]}"
+               error "invalid response from phpfpm status server: ${phpfpm_response[*]}"
                return 1
        fi
 
@@ -61,7 +66,12 @@ phpfpm_get() {
        phpfpm_total_processes="${phpfpm_response[34]}"
        phpfpm_max_active_processes="${phpfpm_response[38]}"
        phpfpm_max_children_reached="${phpfpm_response[42]}"
-       phpfpm_slow_requests="${phpfpm_response[45]}"
+       if [ "${phpfpm_response[43]}" == "slow" ]
+               then
+               phpfpm_slow_requests="${phpfpm_response[45]}"
+       else
+               phpfpm_slow_requests="-1"
+       fi
        
        if [[ -z "${phpfpm_pool}" \
                || -z "${phpfpm_start_time}" \
@@ -75,10 +85,9 @@ phpfpm_get() {
                || -z "${phpfpm_total_processes}" \
                || -z "${phpfpm_max_active_processes}" \
                || -z "${phpfpm_max_children_reached}" \
-               || -z "${phpfpm_slow_requests}" \
        ]]
                then
-               echo >&2 "phpfpm: empty values got from phpfpm status server: ${phpfpm_response[*]}"
+               error "empty values got from phpfpm status server: ${phpfpm_response[*]}"
                return 1
        fi
 
@@ -94,16 +103,16 @@ phpfpm_check() {
        local m
        for m in "${!phpfpm_urls[@]}"
        do
-               phpfpm_get "${phpfpm_urls[$m]}"
+               phpfpm_get "${phpfpm_curl_opts[$m]}" "${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"
+                       error "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"
+               error "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
        
@@ -120,18 +129,21 @@ phpfpm_create() {
        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
+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_$m.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_$m.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
+               if [ $((phpfpm_slow_requests)) -ne -1 ]
+                       then
+                       echo "DIMENSION slow 'slow requests' absolute 1 1"
+               fi
        done
        
        return 0
@@ -149,7 +161,7 @@ phpfpm_update() {
        local m
        for m in "${!phpfpm_urls[@]}"
        do
-               phpfpm_get "${phpfpm_urls[$m]}"
+               phpfpm_get "${phpfpm_curl_opts[$m]}" "${phpfpm_urls[$m]}"
                if [ $? -ne 0 ]; then
                        continue
                fi
@@ -157,19 +169,26 @@ phpfpm_update() {
                # 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]
+SET active = $((phpfpm_active_processes))
+SET maxActive = $((phpfpm_max_active_processes))
+SET idle = $((phpfpm_idle_processes))
 END
 BEGIN phpfpm_$m.requests $1
-SET requests = $[phpfpm_accepted_conn]
+SET requests = $((phpfpm_accepted_conn))
 END
 BEGIN phpfpm_$m.performance $1
-SET reached = $[phpfpm_max_children_reached]
-SET slow = $[phpfpm_slow_requests]
-END
+SET reached = $((phpfpm_max_children_reached))
 EOF
+               if [ $((phpfpm_slow_requests)) -ne -1 ]
+                       then
+                       echo "SET slow = $((phpfpm_slow_requests))"
+               fi
+               echo "END"
        done
        
        return 0
 }
+
+phpfpm_check
+phpfpm_create
+phpfpm_update