1 # no need for shebang - this file is loaded from charts.d.plugin
4 # real-time performance and health monitoring, done right!
5 # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
9 # the URL to download apache status info
10 apache_url="http://127.0.0.1:80/server-status?auto"
13 # _update_every is a special variable - it holds the number of seconds
14 # between the calls of the _update() function
19 # convert apache floating point values
20 # to integer using this multiplier
21 # this only affects precision - the values
22 # will be in the proper units
23 apache_decimal_detail=1000000
25 declare -a apache_response=()
34 apache_connsasyncwriting=0
35 apache_connsasynckeepalive=0
36 apache_connsasyncclosing=0
38 apache_keys_detected=0
43 apache_key_bytespersec=
44 apache_key_bytesperreq=
45 apache_key_busyworkers=
46 apache_key_idleworkers=
47 apache_key_scoreboard=
48 apache_key_connstotal=
49 apache_key_connsasyncwriting=
50 apache_key_connsasynckeepalive=
51 apache_key_connsasyncclosing=
57 'Total Accesses') apache_key_accesses=$((i + 1)) ;;
58 'Total kBytes') apache_key_kbytes=$((i + 1)) ;;
59 'ReqPerSec') apache_key_reqpersec=$((i + 1)) ;;
60 'BytesPerSec') apache_key_bytespersec=$((i + 1)) ;;
61 'BytesPerReq') apache_key_bytesperreq=$((i + 1)) ;;
62 'BusyWorkers') apache_key_busyworkers=$((i + 1)) ;;
63 'IdleWorkers') apache_key_idleworkers=$((i + 1));;
64 'ConnsTotal') apache_key_connstotal=$((i + 1)) ;;
65 'ConnsAsyncWriting') apache_key_connsasyncwriting=$((i + 1)) ;;
66 'ConnsAsyncKeepAlive') apache_key_connsasynckeepalive=$((i + 1)) ;;
67 'ConnsAsyncClosing') apache_key_connsasyncclosing=$((i + 1)) ;;
68 'Scoreboard') apache_key_scoreboard=$((i)) ;;
74 # we will not check of the Conns*
75 # keys, since these are apache 2.4 specific
76 [ -z "${apache_key_accesses}" ] && error "missing 'Total Accesses' from apache server: ${*}" && return 1
77 [ -z "${apache_key_kbytes}" ] && error "missing 'Total kBytes' from apache server: ${*}" && return 1
78 [ -z "${apache_key_reqpersec}" ] && error "missing 'ReqPerSec' from apache server: ${*}" && return 1
79 [ -z "${apache_key_bytespersec}" ] && error "missing 'BytesPerSec' from apache server: ${*}" && return 1
80 [ -z "${apache_key_bytesperreq}" ] && error "missing 'BytesPerReq' from apache server: ${*}" && return 1
81 [ -z "${apache_key_busyworkers}" ] && error "missing 'BusyWorkers' from apache server: ${*}" && return 1
82 [ -z "${apache_key_idleworkers}" ] && error "missing 'IdleWorkers' from apache server: ${*}" && return 1
83 [ -z "${apache_key_scoreboard}" ] && error "missing 'Scoreboard' from apache server: ${*}" && return 1
85 if [ ! -z "${apache_key_connstotal}" \
86 -a ! -z "${apache_key_connsasyncwriting}" \
87 -a ! -z "${apache_key_connsasynckeepalive}" \
88 -a ! -z "${apache_key_connsasyncclosing}" \
100 local oIFS="${IFS}" ret
101 IFS=$':\n' apache_response=($(run curl -Ss ${apache_curl_opts} "${apache_url}"))
105 [ $ret -ne 0 -o "${#apache_response[@]}" -eq 0 ] && return 1
107 # the last line on the apache output is "Scoreboard"
108 # we use this label to detect that the output has a new word count
109 if [ ${apache_keys_detected} -eq 0 -o "${apache_response[${apache_key_scoreboard}]}" != "Scoreboard" ]
111 apache_detect "${apache_response[@]}" || return 1
112 apache_keys_detected=1
115 apache_accesses="${apache_response[${apache_key_accesses}]}"
116 apache_kbytes="${apache_response[${apache_key_kbytes}]}"
118 float2int "${apache_response[${apache_key_reqpersec}]}" ${apache_decimal_detail}
119 apache_reqpersec=${FLOAT2INT_RESULT}
121 float2int "${apache_response[${apache_key_bytespersec}]}" ${apache_decimal_detail}
122 apache_bytespersec=${FLOAT2INT_RESULT}
124 float2int "${apache_response[${apache_key_bytesperreq}]}" ${apache_decimal_detail}
125 apache_bytesperreq=${FLOAT2INT_RESULT}
127 apache_busyworkers="${apache_response[${apache_key_busyworkers}]}"
128 apache_idleworkers="${apache_response[${apache_key_idleworkers}]}"
130 if [ -z "${apache_accesses}" \
131 -o -z "${apache_kbytes}" \
132 -o -z "${apache_reqpersec}" \
133 -o -z "${apache_bytespersec}" \
134 -o -z "${apache_bytesperreq}" \
135 -o -z "${apache_busyworkers}" \
136 -o -z "${apache_idleworkers}" \
139 error "empty values got from apache server: ${apache_response[*]}"
143 if [ ${apache_has_conns} -eq 1 ]
145 apache_connstotal="${apache_response[${apache_key_connstotal}]}"
146 apache_connsasyncwriting="${apache_response[${apache_key_connsasyncwriting}]}"
147 apache_connsasynckeepalive="${apache_response[${apache_key_connsasynckeepalive}]}"
148 apache_connsasyncclosing="${apache_response[${apache_key_connsasyncclosing}]}"
154 # _check is called once, to find out if this chart should be enabled or not
160 error "cannot find stub_status on URL '${apache_url}'. Please set apache_url='http://apache.server:80/server-status?auto' in $confd/apache.conf"
164 # this should return:
165 # - 0 to enable the chart
166 # - 1 to disable the chart
171 # _create is called once, to create the charts
174 CHART apache_local.bytesperreq '' "apache Lifetime Avg. Response Size" "bytes/request" statistics apache.bytesperreq area $((apache_priority + 8)) $apache_update_every
175 DIMENSION size '' absolute 1 ${apache_decimal_detail}
176 CHART apache_local.workers '' "apache Workers" "workers" workers apache.workers stacked $((apache_priority + 5)) $apache_update_every
177 DIMENSION idle '' absolute 1 1
178 DIMENSION busy '' absolute 1 1
179 CHART apache_local.reqpersec '' "apache Lifetime Avg. Requests/s" "requests/s" statistics apache.reqpersec line $((apache_priority + 6)) $apache_update_every
180 DIMENSION requests '' absolute 1 ${apache_decimal_detail}
181 CHART apache_local.bytespersec '' "apache Lifetime Avg. Bandwidth/s" "kilobits/s" statistics apache.bytespersec area $((apache_priority + 7)) $apache_update_every
182 DIMENSION sent '' absolute 8 $((apache_decimal_detail * 1000))
183 CHART apache_local.requests '' "apache Requests" "requests/s" requests apache.requests line $((apache_priority + 1)) $apache_update_every
184 DIMENSION requests '' incremental 1 1
185 CHART apache_local.net '' "apache Bandwidth" "kilobits/s" bandwidth apache.net area $((apache_priority + 3)) $apache_update_every
186 DIMENSION sent '' incremental 8 1
189 if [ ${apache_has_conns} -eq 1 ]
192 CHART apache_local.connections '' "apache Connections" "connections" connections apache.connections line $((apache_priority + 2)) $apache_update_every
193 DIMENSION connections '' absolute 1 1
194 CHART apache_local.conns_async '' "apache Async Connections" "connections" connections apache.conns_async stacked $((apache_priority + 4)) $apache_update_every
195 DIMENSION keepalive '' absolute 1 1
196 DIMENSION closing '' absolute 1 1
197 DIMENSION writing '' absolute 1 1
204 # _update is called continiously, to collect the values
207 # the first argument to this function is the microseconds since last update
208 # pass this parameter to the BEGIN statement (see bellow).
210 # do all the work to collect / calculate the values
212 # remember: KEEP IT SIMPLE AND SHORT
214 apache_get || return 1
216 # write the result of the work.
218 BEGIN apache_local.requests $1
219 SET requests = $((apache_accesses))
221 BEGIN apache_local.net $1
222 SET sent = $((apache_kbytes))
224 BEGIN apache_local.reqpersec $1
225 SET requests = $((apache_reqpersec))
227 BEGIN apache_local.bytespersec $1
228 SET sent = $((apache_bytespersec))
230 BEGIN apache_local.bytesperreq $1
231 SET size = $((apache_bytesperreq))
233 BEGIN apache_local.workers $1
234 SET idle = $((apache_idleworkers))
235 SET busy = $((apache_busyworkers))
239 if [ ${apache_has_conns} -eq 1 ]
242 BEGIN apache_local.connections $1
243 SET connections = $((apache_connstotal))
245 BEGIN apache_local.conns_async $1
246 SET keepalive = $((apache_connsasynckeepalive))
247 SET closing = $((apache_connsasyncclosing))
248 SET writing = $((apache_connsasyncwriting))