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
12 # convert apache floating point values
13 # to integer using this multiplier
14 # this only affects precision - the values
15 # will be in the proper units
16 apache_decimal_detail=1000000
18 declare -a apache_response=()
27 apache_connsasyncwriting=0
28 apache_connsasynckeepalive=0
29 apache_connsasyncclosing=0
31 apache_keys_detected=0
36 apache_key_bytespersec=
37 apache_key_bytesperreq=
38 apache_key_busyworkers=
39 apache_key_idleworkers=
40 apache_key_scoreboard=
41 apache_key_connstotal=
42 apache_key_connsasyncwriting=
43 apache_key_connsasynckeepalive=
44 apache_key_connsasyncclosing=
50 'Total Accesses') apache_key_accesses=$[i + 1] ;;
51 'Total kBytes') apache_key_kbytes=$[i + 1] ;;
52 'ReqPerSec') apache_key_reqpersec=$[i + 1] ;;
53 'BytesPerSec') apache_key_bytespersec=$[i + 1] ;;
54 'BytesPerReq') apache_key_bytesperreq=$[i + 1] ;;
55 'BusyWorkers') apache_key_busyworkers=$[i + 1] ;;
56 'IdleWorkers') apache_key_idleworkers=$[i + 1];;
57 'ConnsTotal') apache_key_connstotal=$[i + 1] ;;
58 'ConnsAsyncWriting') apache_key_connsasyncwriting=$[i + 1] ;;
59 'ConnsAsyncKeepAlive') apache_key_connsasynckeepalive=$[i + 1] ;;
60 'ConnsAsyncClosing') apache_key_connsasyncclosing=$[i + 1] ;;
61 'Scoreboard') apache_key_scoreboard=$[i] ;;
67 # we will not check of the Conns*
68 # keys, since these are apache 2.4 specific
69 if [ -z "${apache_key_accesses}" \
70 -o -z "${apache_key_kbytes}" \
71 -o -z "${apache_key_reqpersec}" \
72 -o -z "${apache_key_bytespersec}" \
73 -o -z "${apache_key_bytesperreq}" \
74 -o -z "${apache_key_busyworkers}" \
75 -o -z "${apache_key_idleworkers}" \
76 -o -z "${apache_key_scoreboard}" \
79 echo >&2 "apache: Invalid response or missing keys from apache server: ${*}"
83 if [ ! -z "${apache_key_connstotal}" \
84 -a ! -z "${apache_key_connsasyncwriting}" \
85 -a ! -z "${apache_key_connsasynckeepalive}" \
86 -a ! -z "${apache_key_connsasyncclosing}" \
96 local oIFS="${IFS}" ret
97 IFS=$':\n' apache_response=($(curl -s "${apache_url}"))
101 [ $ret -ne 0 -o "${#apache_response[@]}" -eq 0 ] && return 1
103 # the last line on the apache output is "Scoreboard"
104 # we use this label to detect that the output has a new word count
105 if [ ${apache_keys_detected} -eq 0 -o "${apache_response[${apache_key_scoreboard}]}" != "Scoreboard" ]
107 apache_detect "${apache_response[@]}" || return 1
108 apache_keys_detected=1
111 apache_accesses="${apache_response[${apache_key_accesses}]}"
112 apache_kbytes="${apache_response[${apache_key_kbytes}]}"
114 float2int "${apache_response[${apache_key_reqpersec}]}" ${apache_decimal_detail}
115 apache_reqpersec=${FLOAT2INT_RESULT}
117 float2int "${apache_response[${apache_key_bytespersec}]}" ${apache_decimal_detail}
118 apache_bytespersec=${FLOAT2INT_RESULT}
120 float2int "${apache_response[${apache_key_bytesperreq}]}" ${apache_decimal_detail}
121 apache_bytesperreq=${FLOAT2INT_RESULT}
123 apache_busyworkers="${apache_response[${apache_key_busyworkers}]}"
124 apache_idleworkers="${apache_response[${apache_key_idleworkers}]}"
126 if [ -z "${apache_accesses}" \
127 -o -z "${apache_kbytes}" \
128 -o -z "${apache_reqpersec}" \
129 -o -z "${apache_bytespersec}" \
130 -o -z "${apache_bytesperreq}" \
131 -o -z "${apache_busyworkers}" \
132 -o -z "${apache_idleworkers}" \
135 echo >&2 "apache: empty values got from apache server: ${apache_response[*]}"
139 if [ ${apache_has_conns} -eq 1 ]
141 apache_connstotal="${apache_response[${apache_key_connstotal}]}"
142 apache_connsasyncwriting="${apache_response[${apache_key_connsasyncwriting}]}"
143 apache_connsasynckeepalive="${apache_response[${apache_key_connsasynckeepalive}]}"
144 apache_connsasyncclosing="${apache_response[${apache_key_connsasyncclosing}]}"
150 # _check is called once, to find out if this chart should be enabled or not
156 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"
160 # this should return:
161 # - 0 to enable the chart
162 # - 1 to disable the chart
167 # _create is called once, to create the charts
170 CHART apache.bytesperreq '' "apache Lifetime Avg. Response Size" "bytes/request" statistics apache.bytesperreq area $[apache_priority + 8] $apache_update_every
171 DIMENSION size '' absolute 1 ${apache_decimal_detail}
172 CHART apache.workers '' "apache Workers" "workers" workers apache.workers stacked $[apache_priority + 5] $apache_update_every
173 DIMENSION idle '' absolute 1 1
174 DIMENSION busy '' absolute 1 1
175 CHART apache.reqpersec '' "apache Lifetime Avg. Requests/s" "requests/s" statistics apache.reqpersec line $[apache_priority + 6] $apache_update_every
176 DIMENSION requests '' absolute 1 ${apache_decimal_detail}
177 CHART apache.bytespersec '' "apache Lifetime Avg. Bandwidth/s" "kilobits/s" statistics apache.bytespersec area $[apache_priority + 7] $apache_update_every
178 DIMENSION sent '' absolute 8 $[apache_decimal_detail * 1000]
179 CHART apache.requests '' "apache Requests" "requests/s" requests apache.requests line $[apache_priority + 1] $apache_update_every
180 DIMENSION requests '' incremental 1 1
181 CHART apache.net '' "apache Bandwidth" "kilobits/s" bandwidth apache.net area $[apache_priority + 3] $apache_update_every
182 DIMENSION sent '' incremental 8 1
185 if [ ${apache_has_conns} -eq 1 ]
188 CHART apache.connections '' "apache Connections" "connections" connections apache.connections line $[apache_priority + 2] $apache_update_every
189 DIMENSION connections '' absolute 1 1
190 CHART apache.conns_async '' "apache Async Connections" "connections" connections apache.conns_async stacked $[apache_priority + 4] $apache_update_every
191 DIMENSION keepalive '' absolute 1 1
192 DIMENSION closing '' absolute 1 1
193 DIMENSION writing '' absolute 1 1
200 # _update is called continiously, to collect the values
203 # the first argument to this function is the microseconds since last update
204 # pass this parameter to the BEGIN statement (see bellow).
206 # do all the work to collect / calculate the values
208 # remember: KEEP IT SIMPLE AND SHORT
210 apache_get || return 1
212 # write the result of the work.
214 BEGIN apache.requests $1
215 SET requests = $[apache_accesses]
218 SET sent = $[apache_kbytes]
220 BEGIN apache.reqpersec $1
221 SET requests = $[apache_reqpersec]
223 BEGIN apache.bytespersec $1
224 SET sent = $[apache_bytespersec]
226 BEGIN apache.bytesperreq $1
227 SET size = $[apache_bytesperreq]
229 BEGIN apache.workers $1
230 SET idle = $[apache_idleworkers]
231 SET busy = $[apache_busyworkers]
235 if [ ${apache_has_conns} -eq 1 ]
238 BEGIN apache.connections $1
239 SET connections = $[apache_connstotal]
241 BEGIN apache.conns_async $1
242 SET keepalive = $[apache_connsasynckeepalive]
243 SET closing = $[apache_connsasyncwriting]
244 SET writing = $[apache_connsasyncwriting]