diff options
author | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2016-01-23 05:39:25 +0200 |
---|---|---|
committer | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2016-01-23 05:39:25 +0200 |
commit | 63aed58633cb183c4769898c4b1c625ad5e0fde6 (patch) | |
tree | 3e5259ecf6cfb0cfa1fa3e0853b57bf469b0a640 /charts.d/apache.chart.sh | |
parent | cbaf3a08be7820c1ccaaabfb94ab5ec39db6f9b4 (diff) |
adaptation of supporting apache 2.2 and 2.4
Diffstat (limited to 'charts.d/apache.chart.sh')
-rwxr-xr-x | charts.d/apache.chart.sh | 146 |
1 files changed, 76 insertions, 70 deletions
diff --git a/charts.d/apache.chart.sh b/charts.d/apache.chart.sh index 6c6e36e33f..eeb90247bf 100755 --- a/charts.d/apache.chart.sh +++ b/charts.d/apache.chart.sh @@ -7,10 +7,6 @@ apache_url="http://127.0.0.1:80/server-status?auto" # between the calls of the _update() function apache_update_every= -# let netdata calculate averages (0) -# or use apache calculated averages (1) -apache_averages=0 - # convert apache floating point values # to integer using this multiplier # this only affects precision - the values @@ -20,71 +16,95 @@ 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_keys_detected=0 +apache_key_accesses= +apache_key_kbytes= +apache_key_reqpersec= +apache_key_bytespersec= +apache_key_bytesperreq= +apache_key_busyworkers= +apache_key_idleworkers= +apache_key_connstotal= +apache_key_connsasyncwriting= +apache_key_connsasynckeepalive= +apache_key_connsasyncclosing= +apache_detect() { + local i=0 + for x in "${@}" + do + case "${x}" in + 'Accesses:') apache_key_accesses=$[i + 1] ;; + '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] ;; + esac + + i=$[i + 1] + done + + # we will not check of the Conns* + # keys, since these are apache 2.4 specific + if [ -z "${apache_key_accesses}" \ + -o -z "${apache_key_kbytes}" \ + -o -z "${apache_key_reqpersec}" \ + -o -z "${apache_key_bytespersec}" \ + -o -z "${apache_key_bytesperreq}" \ + -o -z "${apache_key_busyworkers}" \ + -o -z "${apache_key_idleworkers}" \ + ] + then + echo >&2 "apache: Invalid response or missing keys from apache server: ${*}" + return 1 + 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:" \ - ] + if [ ${apache_keys_detected} -eq 0 ] 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]}" + apache_accesses="${apache_response[${apache_key_accesses}]}" + apache_kbytes="${apache_response[${apache_key_kbytes}]}" - # float2int "${apache_response[7]}" ${apache_decimal_detail} - # apache_cpuload=${FLOAT2INT_RESULT} - - # 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[*]}" @@ -114,31 +134,20 @@ 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.bytesperreq '' "apache Lifetime Avg. Response Size" "bytes/request" apache apache area 16008 $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.workers '' "apache Workers" "workers" apache apache stacked 16005 $apache_update_every DIMENSION idle '' absolute 1 1 DIMENSION busy '' absolute 1 1 -EOF - - if [ ${apache_averages} -eq 1 ] - then - # apache calculated averages - cat <<EOF2 -CHART apache.requests '' "apache Requests" "requests/s" apache apache line 16001 $apache_update_every +CHART apache.reqpersec '' "apache Lifetime Avg. Requests/s" "requests/s" apache apache line 16006 $apache_update_every DIMENSION requests '' absolute 1 ${apache_decimal_detail} -CHART apache.net '' "apache Bandwidth" "kilobits/s" apache apache area 16002 $apache_update_every +CHART apache.bytespersec '' "apache Lifetime Avg. Bandwidth/s" "kilobits/s" apache apache area 16007 $apache_update_every DIMENSION sent '' absolute 8 $[apache_decimal_detail * 1000] -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 +EOF return 0 } @@ -155,22 +164,19 @@ 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] +SET requests = $[apache_accesses] END BEGIN apache.net $1 -SET sent = $[net] +SET sent = $[apache_kbytes] +END +BEGIN apache.reqpersec $1 +SET requests = $[apache_reqpersec] +END +BEGIN apache.bytespersec $1 +SET sent = $[apache_bytespersec] END BEGIN apache.bytesperreq $1 SET size = $[apache_bytesperreq] |