]> arthur.barton.de Git - netdata.git/blobdiff - charts.d/apache.chart.sh
Merge pull request #1912 from vlvkobal/master
[netdata.git] / charts.d / apache.chart.sh
old mode 100755 (executable)
new mode 100644 (file)
index 6c6e36e..b503e74
@@ -1,15 +1,20 @@
-#!/bin/sh
+# no need for shebang - this file is loaded from charts.d.plugin
+
+# netdata
+# real-time performance and health monitoring, done right!
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
+# GPL v3+
+#
 
 # the URL to download apache status info
 apache_url="http://127.0.0.1:80/server-status?auto"
+apache_curl_opts=
 
 # _update_every is a special variable - it holds the number of seconds
 # between the calls of the _update() function
 apache_update_every=
 
-# let netdata calculate averages (0)
-# or use apache calculated averages (1)
-apache_averages=0
+apache_priority=60000
 
 # convert apache floating point values
 # to integer using this multiplier
@@ -20,77 +25,129 @@ apache_decimal_detail=1000000
 declare -a apache_response=()
 apache_accesses=0
 apache_kbytes=0
-apache_cpuload=0
-apache_uptime=0
 apache_reqpersec=0
 apache_bytespersec=0
 apache_bytesperreq=0
 apache_busyworkers=0
 apache_idleworkers=0
-apache_scoreboard=
+apache_connstotal=0
+apache_connsasyncwriting=0
+apache_connsasynckeepalive=0
+apache_connsasyncclosing=0
+
+apache_keys_detected=0
+apache_has_conns=0
+apache_key_accesses=
+apache_key_kbytes=
+apache_key_reqpersec=
+apache_key_bytespersec=
+apache_key_bytesperreq=
+apache_key_busyworkers=
+apache_key_idleworkers=
+apache_key_scoreboard=
+apache_key_connstotal=
+apache_key_connsasyncwriting=
+apache_key_connsasynckeepalive=
+apache_key_connsasyncclosing=
+apache_detect() {
+       local i=0
+       for x in "${@}"
+       do
+               case "${x}" in
+                       'Total Accesses')               apache_key_accesses=$((i + 1)) ;;
+                       'Total kBytes')                 apache_key_kbytes=$((i + 1)) ;;
+                       'ReqPerSec')                    apache_key_reqpersec=$((i + 1)) ;;
+                       'BytesPerSec')                  apache_key_bytespersec=$((i + 1)) ;;
+                       'BytesPerReq')                  apache_key_bytesperreq=$((i + 1)) ;;
+                       'BusyWorkers')                  apache_key_busyworkers=$((i + 1)) ;;
+                       'IdleWorkers')                  apache_key_idleworkers=$((i + 1));;
+                       'ConnsTotal')                   apache_key_connstotal=$((i + 1)) ;;
+                       'ConnsAsyncWriting')    apache_key_connsasyncwriting=$((i + 1)) ;;
+                       'ConnsAsyncKeepAlive')  apache_key_connsasynckeepalive=$((i + 1)) ;;
+                       'ConnsAsyncClosing')    apache_key_connsasyncclosing=$((i + 1)) ;;
+                       'Scoreboard')                   apache_key_scoreboard=$((i)) ;;
+               esac
+
+               i=$((i + 1))
+       done
+
+       # we will not check of the Conns*
+       # keys, since these are apache 2.4 specific
+       [ -z "${apache_key_accesses}"    ] && error "missing 'Total Accesses' from apache server: ${*}" && return 1
+       [ -z "${apache_key_kbytes}"      ] && error "missing 'Total kBytes' from apache server: ${*}" && return 1
+       [ -z "${apache_key_reqpersec}"   ] && error "missing 'ReqPerSec' from apache server: ${*}" && return 1
+       [ -z "${apache_key_bytespersec}" ] && error "missing 'BytesPerSec' from apache server: ${*}" && return 1
+       [ -z "${apache_key_bytesperreq}" ] && error "missing 'BytesPerReq' from apache server: ${*}" && return 1
+       [ -z "${apache_key_busyworkers}" ] && error "missing 'BusyWorkers' from apache server: ${*}" && return 1
+       [ -z "${apache_key_idleworkers}" ] && error "missing 'IdleWorkers' from apache server: ${*}" && return 1
+       [ -z "${apache_key_scoreboard}"  ] && error "missing 'Scoreboard' from apache server: ${*}" && return 1
+
+       if [ ! -z "${apache_key_connstotal}" \
+               -a ! -z "${apache_key_connsasyncwriting}" \
+               -a ! -z "${apache_key_connsasynckeepalive}" \
+               -a ! -z "${apache_key_connsasyncclosing}" \
+               ]
+               then
+               apache_has_conns=1
+       else
+               apache_has_conns=0
+       fi
+
+       return 0
+}
 
 apache_get() {
-       apache_response=($(curl -s "${apache_url}"))
-       [ $? -ne 0 -o "${#apache_response[@]}" -eq 0 ] && return 1
-
-       if [ "${apache_response[0]}" != "Total" \
-                -o "${apache_response[1]}" != "Accesses:" \
-                -o "${apache_response[3]}" != "Total" \
-                -o "${apache_response[4]}" != "kBytes:" \
-                -o "${apache_response[6]}" != "CPULoad:" \
-                -o "${apache_response[8]}" != "Uptime:" \
-                -o "${apache_response[10]}" != "ReqPerSec:" \
-                -o "${apache_response[12]}" != "BytesPerSec:" \
-                -o "${apache_response[14]}" != "BytesPerReq:" \
-                -o "${apache_response[16]}" != "BusyWorkers:" \
-                -o "${apache_response[18]}" != "IdleWorkers:" \
-                -o "${apache_response[20]}" != "Scoreboard:" \
-          ]
+       local oIFS="${IFS}" ret
+       IFS=$':\n' apache_response=($(run curl -Ss ${apache_curl_opts} "${apache_url}"))
+       ret=$?
+       IFS="${oIFS}"
+
+       [ $ret -ne 0 -o "${#apache_response[@]}" -eq 0 ] && return 1
+
+       # the last line on the apache output is "Scoreboard"
+       # we use this label to detect that the output has a new word count
+       if [ ${apache_keys_detected} -eq 0 -o "${apache_response[${apache_key_scoreboard}]}" != "Scoreboard" ]
                then
-               echo >&2 "apache: Invalid response from apache server: ${apache_response[*]}"
-               return 1
+               apache_detect "${apache_response[@]}" || return 1
+               apache_keys_detected=1
        fi
 
-       apache_accesses="${apache_response[2]}"
-       apache_kbytes="${apache_response[5]}"
-       
-       # float2int "${apache_response[7]}" ${apache_decimal_detail}
-       # apache_cpuload=${FLOAT2INT_RESULT}
+       apache_accesses="${apache_response[${apache_key_accesses}]}"
+       apache_kbytes="${apache_response[${apache_key_kbytes}]}"
        
-       # apache_uptime="${apache_response[9]}"
-       
-       if [ ${apache_averages} -eq 1 ]
-               then
-               float2int "${apache_response[11]}" ${apache_decimal_detail}
-               apache_reqpersec=${FLOAT2INT_RESULT}
+       float2int "${apache_response[${apache_key_reqpersec}]}" ${apache_decimal_detail}
+       apache_reqpersec=${FLOAT2INT_RESULT}
 
-               float2int "${apache_response[13]}" ${apache_decimal_detail}
-               apache_bytespersec=${FLOAT2INT_RESULT}
-       fi
+       float2int "${apache_response[${apache_key_bytespersec}]}" ${apache_decimal_detail}
+       apache_bytespersec=${FLOAT2INT_RESULT}
 
-       float2int "${apache_response[15]}" ${apache_decimal_detail}
+       float2int "${apache_response[${apache_key_bytesperreq}]}" ${apache_decimal_detail}
        apache_bytesperreq=${FLOAT2INT_RESULT}
 
-       apache_busyworkers="${apache_response[17]}"
-       apache_idleworkers="${apache_response[19]}"
-       apache_scoreboard="${apache_response[21]}"
+       apache_busyworkers="${apache_response[${apache_key_busyworkers}]}"
+       apache_idleworkers="${apache_response[${apache_key_idleworkers}]}"
 
        if [ -z "${apache_accesses}" \
                -o -z "${apache_kbytes}" \
-               -o -z "${apache_cpuload}" \
-               -o -z "${apache_uptime}" \
                -o -z "${apache_reqpersec}" \
                -o -z "${apache_bytespersec}" \
                -o -z "${apache_bytesperreq}" \
                -o -z "${apache_busyworkers}" \
                -o -z "${apache_idleworkers}" \
-               -o -z "${apache_scoreboard}" \
                ]
                then
-               echo >&2 "apache: empty values got from apache server: ${apache_response[*]}"
+               error "empty values got from apache server: ${apache_response[*]}"
                return 1
        fi
 
+       if [ ${apache_has_conns} -eq 1 ]
+               then
+               apache_connstotal="${apache_response[${apache_key_connstotal}]}"
+               apache_connsasyncwriting="${apache_response[${apache_key_connsasyncwriting}]}"
+               apache_connsasynckeepalive="${apache_response[${apache_key_connsasynckeepalive}]}"
+               apache_connsasyncclosing="${apache_response[${apache_key_connsasyncclosing}]}"
+       fi
+
        return 0
 }
 
@@ -100,7 +157,7 @@ apache_check() {
        apache_get
        if [ $? -ne 0 ]
                then
-               echo >&2 "apache: cannot find stub_status on URL '${apache_url}'. Please set apache_url='http://apache.server:80/server-status?auto' in $confd/apache.conf"
+               error "cannot find stub_status on URL '${apache_url}'. Please set apache_url='http://apache.server:80/server-status?auto' in $confd/apache.conf"
                return 1
        fi
 
@@ -114,30 +171,31 @@ apache_check() {
 # _create is called once, to create the charts
 apache_create() {
        cat <<EOF
-CHART apache.bytesperreq '' "apache Average Response Size (lifetime)" "bytes/request" apache apache area 16005 $apache_update_every
+CHART apache_local.bytesperreq '' "apache Lifetime Avg. Response Size" "bytes/request" statistics apache.bytesperreq area $((apache_priority + 8)) $apache_update_every
 DIMENSION size '' absolute 1 ${apache_decimal_detail}
-CHART apache.workers '' "apache Workers" "workers" apache apache stacked 16006 $apache_update_every
+CHART apache_local.workers '' "apache Workers" "workers" workers apache.workers stacked $((apache_priority + 5)) $apache_update_every
 DIMENSION idle '' absolute 1 1
 DIMENSION busy '' absolute 1 1
+CHART apache_local.reqpersec '' "apache Lifetime Avg. Requests/s" "requests/s" statistics apache.reqpersec line $((apache_priority + 6)) $apache_update_every
+DIMENSION requests '' absolute 1 ${apache_decimal_detail}
+CHART apache_local.bytespersec '' "apache Lifetime Avg. Bandwidth/s" "kilobits/s" statistics apache.bytespersec area $((apache_priority + 7)) $apache_update_every
+DIMENSION sent '' absolute 8 $((apache_decimal_detail * 1000))
+CHART apache_local.requests '' "apache Requests" "requests/s" requests apache.requests line $((apache_priority + 1)) $apache_update_every
+DIMENSION requests '' incremental 1 1
+CHART apache_local.net '' "apache Bandwidth" "kilobits/s" bandwidth apache.net area $((apache_priority + 3)) $apache_update_every
+DIMENSION sent '' incremental 8 1
 EOF
 
-       if [ ${apache_averages} -eq 1 ]
+       if [ ${apache_has_conns} -eq 1 ]
                then
-               # apache calculated averages
                cat <<EOF2
-CHART apache.requests '' "apache Requests" "requests/s" apache apache line 16001 $apache_update_every
-DIMENSION requests '' absolute 1 ${apache_decimal_detail}
-CHART apache.net '' "apache Bandwidth" "kilobits/s" apache apache area 16002 $apache_update_every
-DIMENSION sent '' absolute 8 $[apache_decimal_detail * 1000]
+CHART apache_local.connections '' "apache Connections" "connections" connections apache.connections line $((apache_priority + 2)) $apache_update_every
+DIMENSION connections '' absolute 1 1
+CHART apache_local.conns_async '' "apache Async Connections" "connections" connections apache.conns_async stacked $((apache_priority + 4)) $apache_update_every
+DIMENSION keepalive '' absolute 1 1
+DIMENSION closing '' absolute 1 1
+DIMENSION writing '' absolute 1 1
 EOF2
-       else
-               # netdata calculated averages
-               cat <<EOF3
-CHART apache.requests '' "apache Requests" "requests/s" apache apache line 16001 $apache_update_every
-DIMENSION requests '' incremental 1 1
-CHART apache.net '' "apache Bandwidth" "kilobits/s" apache apache area 16002 $apache_update_every
-DIMENSION sent '' incremental 8 1
-EOF3
        fi
 
        return 0
@@ -155,31 +213,42 @@ apache_update() {
 
        apache_get || return 1
 
-       if [ ${apache_averages} -eq 1 ]
-               then
-               reqs=${apache_reqpersec}
-               net=${apache_bytespersec}
-       else
-               reqs=${apache_accesses}
-               net=${apache_kbytes}
-       fi
-
        # write the result of the work.
        cat <<VALUESEOF
-BEGIN apache.requests $1
-SET requests = $[reqs]
+BEGIN apache_local.requests $1
+SET requests = $((apache_accesses))
+END
+BEGIN apache_local.net $1
+SET sent = $((apache_kbytes))
 END
-BEGIN apache.net $1
-SET sent = $[net]
+BEGIN apache_local.reqpersec $1
+SET requests = $((apache_reqpersec))
 END
-BEGIN apache.bytesperreq $1
-SET size = $[apache_bytesperreq]
+BEGIN apache_local.bytespersec $1
+SET sent = $((apache_bytespersec))
 END
-BEGIN apache.workers $1
-SET idle = $[apache_idleworkers]
-SET busy = $[apache_busyworkers]
+BEGIN apache_local.bytesperreq $1
+SET size = $((apache_bytesperreq))
+END
+BEGIN apache_local.workers $1
+SET idle = $((apache_idleworkers))
+SET busy = $((apache_busyworkers))
 END
 VALUESEOF
 
+       if [ ${apache_has_conns} -eq 1 ]
+               then
+       cat <<VALUESEOF2
+BEGIN apache_local.connections $1
+SET connections = $((apache_connstotal))
+END
+BEGIN apache_local.conns_async $1
+SET keepalive = $((apache_connsasynckeepalive))
+SET closing = $((apache_connsasyncclosing))
+SET writing = $((apache_connsasyncwriting))
+END
+VALUESEOF2
+       fi
+
        return 0
 }