3 # the URL to download apache status info
4 apache_url="http://127.0.0.1:80/server-status?auto"
6 # _update_every is a special variable - it holds the number of seconds
7 # between the calls of the _update() function
10 # convert apache floating point values
11 # to integer using this multiplier
12 # this only affects precision - the values
13 # will be in the proper units
14 apache_decimal_detail=1000000
16 declare -a apache_response=()
25 apache_connsasyncwriting=0
26 apache_connsasynckeepalive=0
27 apache_connsasyncclosing=0
29 apache_keys_detected=0
34 apache_key_bytespersec=
35 apache_key_bytesperreq=
36 apache_key_busyworkers=
37 apache_key_idleworkers=
38 apache_key_scoreboard=
39 apache_key_connstotal=
40 apache_key_connsasyncwriting=
41 apache_key_connsasynckeepalive=
42 apache_key_connsasyncclosing=
48 'Total Accesses') apache_key_accesses=$[i + 1] ;;
49 'Total kBytes') apache_key_kbytes=$[i + 1] ;;
50 'ReqPerSec') apache_key_reqpersec=$[i + 1] ;;
51 'BytesPerSec') apache_key_bytespersec=$[i + 1] ;;
52 'BytesPerReq') apache_key_bytesperreq=$[i + 1] ;;
53 'BusyWorkers') apache_key_busyworkers=$[i + 1] ;;
54 'IdleWorkers') apache_key_idleworkers=$[i + 1];;
55 'ConnsTotal') apache_key_connstotal=$[i + 1] ;;
56 'ConnsAsyncWriting') apache_key_connsasyncwriting=$[i + 1] ;;
57 'ConnsAsyncKeepAlive') apache_key_connsasynckeepalive=$[i + 1] ;;
58 'ConnsAsyncClosing') apache_key_connsasyncclosing=$[i + 1] ;;
59 'Scoreboard') apache_key_scoreboard=$[i] ;;
65 # we will not check of the Conns*
66 # keys, since these are apache 2.4 specific
67 if [ -z "${apache_key_accesses}" \
68 -o -z "${apache_key_kbytes}" \
69 -o -z "${apache_key_reqpersec}" \
70 -o -z "${apache_key_bytespersec}" \
71 -o -z "${apache_key_bytesperreq}" \
72 -o -z "${apache_key_busyworkers}" \
73 -o -z "${apache_key_idleworkers}" \
74 -o -z "${apache_key_scoreboard}" \
77 echo >&2 "apache: Invalid response or missing keys from apache server: ${*}"
81 if [ ! -z "${apache_key_connstotal}" \
82 -a ! -z "${apache_key_connsasyncwriting}" \
83 -a ! -z "${apache_key_connsasynckeepalive}" \
84 -a ! -z "${apache_key_connsasyncclosing}" \
94 local oIFS="${IFS}" ret
95 IFS=$':\n' apache_response=($(curl -s "${apache_url}"))
99 [ $ret -ne 0 -o "${#apache_response[@]}" -eq 0 ] && return 1
101 # the last line on the apache output is "Scoreboard"
102 # we use this label to detect that the output has a new word count
103 if [ ${apache_keys_detected} -eq 0 -o "${apache_response[${apache_key_scoreboard}]}" != "Scoreboard" ]
105 apache_detect "${apache_response[@]}" || return 1
106 apache_keys_detected=1
109 apache_accesses="${apache_response[${apache_key_accesses}]}"
110 apache_kbytes="${apache_response[${apache_key_kbytes}]}"
112 float2int "${apache_response[${apache_key_reqpersec}]}" ${apache_decimal_detail}
113 apache_reqpersec=${FLOAT2INT_RESULT}
115 float2int "${apache_response[${apache_key_bytespersec}]}" ${apache_decimal_detail}
116 apache_bytespersec=${FLOAT2INT_RESULT}
118 float2int "${apache_response[${apache_key_bytesperreq}]}" ${apache_decimal_detail}
119 apache_bytesperreq=${FLOAT2INT_RESULT}
121 apache_busyworkers="${apache_response[${apache_key_busyworkers}]}"
122 apache_idleworkers="${apache_response[${apache_key_idleworkers}]}"
124 if [ -z "${apache_accesses}" \
125 -o -z "${apache_kbytes}" \
126 -o -z "${apache_reqpersec}" \
127 -o -z "${apache_bytespersec}" \
128 -o -z "${apache_bytesperreq}" \
129 -o -z "${apache_busyworkers}" \
130 -o -z "${apache_idleworkers}" \
133 echo >&2 "apache: empty values got from apache server: ${apache_response[*]}"
137 if [ ${apache_has_conns} -eq 1 ]
139 apache_connstotal="${apache_response[${apache_key_connstotal}]}"
140 apache_connsasyncwriting="${apache_response[${apache_key_connsasyncwriting}]}"
141 apache_connsasynckeepalive="${apache_response[${apache_key_connsasynckeepalive}]}"
142 apache_connsasyncclosing="${apache_response[${apache_key_connsasyncclosing}]}"
148 # _check is called once, to find out if this chart should be enabled or not
154 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"
158 # this should return:
159 # - 0 to enable the chart
160 # - 1 to disable the chart
165 # _create is called once, to create the charts
168 CHART apache.bytesperreq '' "apache Lifetime Avg. Response Size" "bytes/request" apache apache area 16008 $apache_update_every
169 DIMENSION size '' absolute 1 ${apache_decimal_detail}
170 CHART apache.workers '' "apache Workers" "workers" apache apache stacked 16005 $apache_update_every
171 DIMENSION idle '' absolute 1 1
172 DIMENSION busy '' absolute 1 1
173 CHART apache.reqpersec '' "apache Lifetime Avg. Requests/s" "requests/s" apache apache line 16006 $apache_update_every
174 DIMENSION requests '' absolute 1 ${apache_decimal_detail}
175 CHART apache.bytespersec '' "apache Lifetime Avg. Bandwidth/s" "kilobits/s" apache apache area 16007 $apache_update_every
176 DIMENSION sent '' absolute 8 $[apache_decimal_detail * 1000]
177 CHART apache.requests '' "apache Requests" "requests/s" apache apache line 16001 $apache_update_every
178 DIMENSION requests '' incremental 1 1
179 CHART apache.net '' "apache Bandwidth" "kilobits/s" apache apache area 16003 $apache_update_every
180 DIMENSION sent '' incremental 8 1
183 if [ ${apache_has_conns} -eq 1 ]
186 CHART apache.connections '' "apache Connections" "connections" apache apache line 16002 $apache_update_every
187 DIMENSION connections '' absolute 1 1
188 CHART apache.conns_async '' "apache Async Connections" "connections" apache apache stacked 16004 $apache_update_every
189 DIMENSION keepalive '' absolute 1 1
190 DIMENSION closing '' absolute 1 1
191 DIMENSION writing '' absolute 1 1
198 # _update is called continiously, to collect the values
201 # the first argument to this function is the microseconds since last update
202 # pass this parameter to the BEGIN statement (see bellow).
204 # do all the work to collect / calculate the values
206 # remember: KEEP IT SIMPLE AND SHORT
208 apache_get || return 1
210 # write the result of the work.
212 BEGIN apache.requests $1
213 SET requests = $[apache_accesses]
216 SET sent = $[apache_kbytes]
218 BEGIN apache.reqpersec $1
219 SET requests = $[apache_reqpersec]
221 BEGIN apache.bytespersec $1
222 SET sent = $[apache_bytespersec]
224 BEGIN apache.bytesperreq $1
225 SET size = $[apache_bytesperreq]
227 BEGIN apache.workers $1
228 SET idle = $[apache_idleworkers]
229 SET busy = $[apache_busyworkers]
233 if [ ${apache_has_conns} -eq 1 ]
236 BEGIN apache.connections $1
237 SET connections = $[apache_connstotal]
239 BEGIN apache.conns_async $1
240 SET keepalive = $[apache_connsasynckeepalive]
241 SET closing = $[apache_connsasyncwriting]
242 SET writing = $[apache_connsasyncwriting]