]> arthur.barton.de Git - netdata.git/blob - charts.d/apache.chart.sh
fixed typo in apache.connections
[netdata.git] / charts.d / apache.chart.sh
1 #!/bin/sh
2
3 # the URL to download apache status info
4 apache_url="http://127.0.0.1:80/server-status?auto"
5
6 # _update_every is a special variable - it holds the number of seconds
7 # between the calls of the _update() function
8 apache_update_every=
9
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
15
16 declare -a apache_response=()
17 apache_accesses=0
18 apache_kbytes=0
19 apache_reqpersec=0
20 apache_bytespersec=0
21 apache_bytesperreq=0
22 apache_busyworkers=0
23 apache_idleworkers=0
24 apache_connstotal=0
25 apache_connsasyncwriting=0
26 apache_connsasynckeepalive=0
27 apache_connsasyncclosing=0
28
29 apache_keys_detected=0
30 apache_has_conns=0
31 apache_key_accesses=
32 apache_key_kbytes=
33 apache_key_reqpersec=
34 apache_key_bytespersec=
35 apache_key_bytesperreq=
36 apache_key_busyworkers=
37 apache_key_idleworkers=
38 apache_key_connstotal=
39 apache_key_connsasyncwriting=
40 apache_key_connsasynckeepalive=
41 apache_key_connsasyncclosing=
42 apache_detect() {
43         local i=0
44         for x in "${@}"
45         do
46                 case "${x}" in
47                         'Accesses:')                    apache_key_accesses=$[i + 1] ;;
48                         'kBytes:')                              apache_key_kbytes=$[i + 1] ;;
49                         'ReqPerSec:')                   apache_key_reqpersec=$[i + 1] ;;
50                         'BytesPerSec:')                 apache_key_bytespersec=$[i + 1] ;;
51                         'BytesPerReq:')                 apache_key_bytesperreq=$[i + 1] ;;
52                         'BusyWorkers:')                 apache_key_busyworkers=$[i + 1] ;;
53                         'IdleWorkers:')                 apache_key_idleworkers=$[i + 1] ;;
54                         'ConnsTotal:')                  apache_key_connstotal=$[i + 1] ;;
55                         'ConnsAsyncWriting:')   apache_key_connsasyncwriting=$[i + 1] ;;
56                         'ConnsAsyncKeepAlive:') apache_key_connsasynckeepalive=$[i + 1] ;;
57                         'ConnsAsyncClosing:')   apache_key_connsasyncclosing=$[i + 1] ;;
58                 esac
59
60                 i=$[i + 1]
61         done
62
63         # we will not check of the Conns*
64         # keys, since these are apache 2.4 specific
65         if [ -z "${apache_key_accesses}" \
66                 -o -z "${apache_key_kbytes}" \
67                 -o -z "${apache_key_reqpersec}" \
68                 -o -z "${apache_key_bytespersec}" \
69                 -o -z "${apache_key_bytesperreq}" \
70                 -o -z "${apache_key_busyworkers}" \
71                 -o -z "${apache_key_idleworkers}" \
72                 ]
73                 then
74                 echo >&2 "apache: Invalid response or missing keys from apache server: ${*}"
75                 return 1
76         fi
77
78         if [ ! -z "${apache_key_connstotal}" \
79                 -a ! -z "${apache_key_connsasyncwriting}" \
80                 -a ! -z "${apache_key_connsasynckeepalive}" \
81                 -a ! -z "${apache_key_connsasyncclosing}" \
82                 ]
83                 then
84                 apache_has_conns=1
85         fi
86
87         return 0
88 }
89
90 apache_get() {
91         apache_response=($(curl -s "${apache_url}"))
92         [ $? -ne 0 -o "${#apache_response[@]}" -eq 0 ] && return 1
93
94         if [ ${apache_keys_detected} -eq 0 ]
95                 then
96                 apache_detect "${apache_response[@]}" || return 1
97                 apache_keys_detected=1
98         fi
99
100         apache_accesses="${apache_response[${apache_key_accesses}]}"
101         apache_kbytes="${apache_response[${apache_key_kbytes}]}"
102         
103         float2int "${apache_response[${apache_key_reqpersec}]}" ${apache_decimal_detail}
104         apache_reqpersec=${FLOAT2INT_RESULT}
105
106         float2int "${apache_response[${apache_key_bytespersec}]}" ${apache_decimal_detail}
107         apache_bytespersec=${FLOAT2INT_RESULT}
108
109         float2int "${apache_response[${apache_key_bytesperreq}]}" ${apache_decimal_detail}
110         apache_bytesperreq=${FLOAT2INT_RESULT}
111
112         apache_busyworkers="${apache_response[${apache_key_busyworkers}]}"
113         apache_idleworkers="${apache_response[${apache_key_idleworkers}]}"
114
115         if [ -z "${apache_accesses}" \
116                 -o -z "${apache_kbytes}" \
117                 -o -z "${apache_reqpersec}" \
118                 -o -z "${apache_bytespersec}" \
119                 -o -z "${apache_bytesperreq}" \
120                 -o -z "${apache_busyworkers}" \
121                 -o -z "${apache_idleworkers}" \
122                 ]
123                 then
124                 echo >&2 "apache: empty values got from apache server: ${apache_response[*]}"
125                 return 1
126         fi
127
128         apache_connstotal="${apache_response[${apache_key_connstotal}]}"
129         apache_connsasyncwriting="${apache_response[${apache_key_connsasyncwriting}]}"
130         apache_connsasynckeepalive="${apache_response[${apache_key_connsasynckeepalive}]}"
131         apache_connsasyncclosing="${apache_response[${apache_key_connsasyncclosing}]}"
132
133         return 0
134 }
135
136 # _check is called once, to find out if this chart should be enabled or not
137 apache_check() {
138
139         apache_get
140         if [ $? -ne 0 ]
141                 then
142                 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"
143                 return 1
144         fi
145
146         # this should return:
147         #  - 0 to enable the chart
148         #  - 1 to disable the chart
149
150         return 0
151 }
152
153 # _create is called once, to create the charts
154 apache_create() {
155         cat <<EOF
156 CHART apache.bytesperreq '' "apache Lifetime Avg. Response Size" "bytes/request" apache apache area 16008 $apache_update_every
157 DIMENSION size '' absolute 1 ${apache_decimal_detail}
158 CHART apache.workers '' "apache Workers" "workers" apache apache stacked 16005 $apache_update_every
159 DIMENSION idle '' absolute 1 1
160 DIMENSION busy '' absolute 1 1
161 CHART apache.reqpersec '' "apache Lifetime Avg. Requests/s" "requests/s" apache apache line 16006 $apache_update_every
162 DIMENSION requests '' absolute 1 ${apache_decimal_detail}
163 CHART apache.bytespersec '' "apache Lifetime Avg. Bandwidth/s" "kilobits/s" apache apache area 16007 $apache_update_every
164 DIMENSION sent '' absolute 8 $[apache_decimal_detail * 1000]
165 CHART apache.requests '' "apache Requests" "requests/s" apache apache line 16001 $apache_update_every
166 DIMENSION requests '' incremental 1 1
167 CHART apache.net '' "apache Bandwidth" "kilobits/s" apache apache area 16003 $apache_update_every
168 DIMENSION sent '' incremental 8 1
169 EOF
170
171         if [ ${apache_has_conns} -eq 1 ]
172                 then
173                 cat <<EOF2
174 CHART apache.connections '' "apache Connections" "connections" apache apache line 16002 $apache_update_every
175 DIMENSION connections '' absolute 1 1
176 CHART apache.conns_async '' "apache Async Connections" "connections" apache apache stacked 16004 $apache_update_every
177 DIMENSION keepalive '' absolute 1 1
178 DIMENSION closing '' absolute 1 1
179 DIMENSION writing '' absolute 1 1
180 EOF2
181         fi
182
183         return 0
184 }
185
186 # _update is called continiously, to collect the values
187 apache_update() {
188         local reqs net
189         # the first argument to this function is the microseconds since last update
190         # pass this parameter to the BEGIN statement (see bellow).
191
192         # do all the work to collect / calculate the values
193         # for each dimension
194         # remember: KEEP IT SIMPLE AND SHORT
195
196         apache_get || return 1
197
198         # write the result of the work.
199         cat <<VALUESEOF
200 BEGIN apache.requests $1
201 SET requests = $[apache_accesses]
202 END
203 BEGIN apache.net $1
204 SET sent = $[apache_kbytes]
205 END
206 BEGIN apache.reqpersec $1
207 SET requests = $[apache_reqpersec]
208 END
209 BEGIN apache.bytespersec $1
210 SET sent = $[apache_bytespersec]
211 END
212 BEGIN apache.bytesperreq $1
213 SET size = $[apache_bytesperreq]
214 END
215 BEGIN apache.workers $1
216 SET idle = $[apache_idleworkers]
217 SET busy = $[apache_busyworkers]
218 END
219 VALUESEOF
220
221         if [ ${apache_has_conns} -eq 1 ]
222                 then
223         cat <<VALUESEOF2
224 BEGIN apache.connections $1
225 SET connections = $[apache_connstotal]
226 END
227 BEGIN apache.conns_async $1
228 SET keepalive = $[apache_connsasynckeepalive]
229 SET closing = $[apache_connsasyncwriting]
230 SET writing = $[apache_connsasyncwriting]
231 END
232 VALUESEOF2
233         fi
234
235         return 0
236 }