3 # the URL to download apache status info
4 apache_url="http://127.0.0.1:80/server-status?auto"
7 # _update_every is a special variable - it holds the number of seconds
8 # between the calls of the _update() function
13 # convert apache floating point values
14 # to integer using this multiplier
15 # this only affects precision - the values
16 # will be in the proper units
17 apache_decimal_detail=1000000
19 declare -a apache_response=()
28 apache_connsasyncwriting=0
29 apache_connsasynckeepalive=0
30 apache_connsasyncclosing=0
32 apache_keys_detected=0
37 apache_key_bytespersec=
38 apache_key_bytesperreq=
39 apache_key_busyworkers=
40 apache_key_idleworkers=
41 apache_key_scoreboard=
42 apache_key_connstotal=
43 apache_key_connsasyncwriting=
44 apache_key_connsasynckeepalive=
45 apache_key_connsasyncclosing=
51 'Total Accesses') apache_key_accesses=$((i + 1)) ;;
52 'Total kBytes') apache_key_kbytes=$((i + 1)) ;;
53 'ReqPerSec') apache_key_reqpersec=$((i + 1)) ;;
54 'BytesPerSec') apache_key_bytespersec=$((i + 1)) ;;
55 'BytesPerReq') apache_key_bytesperreq=$((i + 1)) ;;
56 'BusyWorkers') apache_key_busyworkers=$((i + 1)) ;;
57 'IdleWorkers') apache_key_idleworkers=$((i + 1));;
58 'ConnsTotal') apache_key_connstotal=$((i + 1)) ;;
59 'ConnsAsyncWriting') apache_key_connsasyncwriting=$((i + 1)) ;;
60 'ConnsAsyncKeepAlive') apache_key_connsasynckeepalive=$((i + 1)) ;;
61 'ConnsAsyncClosing') apache_key_connsasyncclosing=$((i + 1)) ;;
62 'Scoreboard') apache_key_scoreboard=$((i)) ;;
68 # we will not check of the Conns*
69 # keys, since these are apache 2.4 specific
70 if [ -z "${apache_key_accesses}" \
71 -o -z "${apache_key_kbytes}" \
72 -o -z "${apache_key_reqpersec}" \
73 -o -z "${apache_key_bytespersec}" \
74 -o -z "${apache_key_bytesperreq}" \
75 -o -z "${apache_key_busyworkers}" \
76 -o -z "${apache_key_idleworkers}" \
77 -o -z "${apache_key_scoreboard}" \
80 echo >&2 "apache: Invalid response or missing keys from apache server: ${*}"
84 if [ ! -z "${apache_key_connstotal}" \
85 -a ! -z "${apache_key_connsasyncwriting}" \
86 -a ! -z "${apache_key_connsasynckeepalive}" \
87 -a ! -z "${apache_key_connsasyncclosing}" \
97 local oIFS="${IFS}" ret
98 IFS=$':\n' apache_response=($(curl -Ss ${apache_curl_opts} "${apache_url}"))
102 [ $ret -ne 0 -o "${#apache_response[@]}" -eq 0 ] && return 1
104 # the last line on the apache output is "Scoreboard"
105 # we use this label to detect that the output has a new word count
106 if [ ${apache_keys_detected} -eq 0 -o "${apache_response[${apache_key_scoreboard}]}" != "Scoreboard" ]
108 apache_detect "${apache_response[@]}" || return 1
109 apache_keys_detected=1
112 apache_accesses="${apache_response[${apache_key_accesses}]}"
113 apache_kbytes="${apache_response[${apache_key_kbytes}]}"
115 float2int "${apache_response[${apache_key_reqpersec}]}" ${apache_decimal_detail}
116 apache_reqpersec=${FLOAT2INT_RESULT}
118 float2int "${apache_response[${apache_key_bytespersec}]}" ${apache_decimal_detail}
119 apache_bytespersec=${FLOAT2INT_RESULT}
121 float2int "${apache_response[${apache_key_bytesperreq}]}" ${apache_decimal_detail}
122 apache_bytesperreq=${FLOAT2INT_RESULT}
124 apache_busyworkers="${apache_response[${apache_key_busyworkers}]}"
125 apache_idleworkers="${apache_response[${apache_key_idleworkers}]}"
127 if [ -z "${apache_accesses}" \
128 -o -z "${apache_kbytes}" \
129 -o -z "${apache_reqpersec}" \
130 -o -z "${apache_bytespersec}" \
131 -o -z "${apache_bytesperreq}" \
132 -o -z "${apache_busyworkers}" \
133 -o -z "${apache_idleworkers}" \
136 echo >&2 "apache: empty values got from apache server: ${apache_response[*]}"
140 if [ ${apache_has_conns} -eq 1 ]
142 apache_connstotal="${apache_response[${apache_key_connstotal}]}"
143 apache_connsasyncwriting="${apache_response[${apache_key_connsasyncwriting}]}"
144 apache_connsasynckeepalive="${apache_response[${apache_key_connsasynckeepalive}]}"
145 apache_connsasyncclosing="${apache_response[${apache_key_connsasyncclosing}]}"
151 # _check is called once, to find out if this chart should be enabled or not
157 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"
161 # this should return:
162 # - 0 to enable the chart
163 # - 1 to disable the chart
168 # _create is called once, to create the charts
171 CHART apache.bytesperreq '' "apache Lifetime Avg. Response Size" "bytes/request" statistics apache.bytesperreq area $((apache_priority + 8)) $apache_update_every
172 DIMENSION size '' absolute 1 ${apache_decimal_detail}
173 CHART apache.workers '' "apache Workers" "workers" workers apache.workers stacked $((apache_priority + 5)) $apache_update_every
174 DIMENSION idle '' absolute 1 1
175 DIMENSION busy '' absolute 1 1
176 CHART apache.reqpersec '' "apache Lifetime Avg. Requests/s" "requests/s" statistics apache.reqpersec line $((apache_priority + 6)) $apache_update_every
177 DIMENSION requests '' absolute 1 ${apache_decimal_detail}
178 CHART apache.bytespersec '' "apache Lifetime Avg. Bandwidth/s" "kilobits/s" statistics apache.bytespersec area $((apache_priority + 7)) $apache_update_every
179 DIMENSION sent '' absolute 8 $((apache_decimal_detail * 1000))
180 CHART apache.requests '' "apache Requests" "requests/s" requests apache.requests line $((apache_priority + 1)) $apache_update_every
181 DIMENSION requests '' incremental 1 1
182 CHART apache.net '' "apache Bandwidth" "kilobits/s" bandwidth apache.net area $((apache_priority + 3)) $apache_update_every
183 DIMENSION sent '' incremental 8 1
186 if [ ${apache_has_conns} -eq 1 ]
189 CHART apache.connections '' "apache Connections" "connections" connections apache.connections line $((apache_priority + 2)) $apache_update_every
190 DIMENSION connections '' absolute 1 1
191 CHART apache.conns_async '' "apache Async Connections" "connections" connections apache.conns_async stacked $((apache_priority + 4)) $apache_update_every
192 DIMENSION keepalive '' absolute 1 1
193 DIMENSION closing '' absolute 1 1
194 DIMENSION writing '' absolute 1 1
201 # _update is called continiously, to collect the values
204 # the first argument to this function is the microseconds since last update
205 # pass this parameter to the BEGIN statement (see bellow).
207 # do all the work to collect / calculate the values
209 # remember: KEEP IT SIMPLE AND SHORT
211 apache_get || return 1
213 # write the result of the work.
215 BEGIN apache.requests $1
216 SET requests = $((apache_accesses))
219 SET sent = $((apache_kbytes))
221 BEGIN apache.reqpersec $1
222 SET requests = $((apache_reqpersec))
224 BEGIN apache.bytespersec $1
225 SET sent = $((apache_bytespersec))
227 BEGIN apache.bytesperreq $1
228 SET size = $((apache_bytesperreq))
230 BEGIN apache.workers $1
231 SET idle = $((apache_idleworkers))
232 SET busy = $((apache_busyworkers))
236 if [ ${apache_has_conns} -eq 1 ]
239 BEGIN apache.connections $1
240 SET connections = $((apache_connstotal))
242 BEGIN apache.conns_async $1
243 SET keepalive = $((apache_connsasynckeepalive))
244 SET closing = $((apache_connsasyncwriting))
245 SET writing = $((apache_connsasyncwriting))