the apache plugin
Costa Tsaousis (ktsaou) committed
Jan 23, 2016 at 04:55 UTC
cbaf3a08be7820c1ccaaabfb94ab5ec39db6f9b4
1 file changed
+185
charts.d/apache.chart.sh
new
+185
@@ -0,0 +1,185 @@
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
+# let netdata calculate averages (0)
11
+# or use apache calculated averages (1)
12
+apache_averages=0
13
+
14
+# convert apache floating point values
15
+# to integer using this multiplier
16
+# this only affects precision - the values
17
+# will be in the proper units
18
+apache_decimal_detail=1000000
19
+
20
+declare -a apache_response=()
21
+apache_accesses=0
22
+apache_kbytes=0
23
+apache_cpuload=0
24
+apache_uptime=0
25
+apache_reqpersec=0
26
+apache_bytespersec=0
27
+apache_bytesperreq=0
28
+apache_busyworkers=0
29
+apache_idleworkers=0
30
+apache_scoreboard=
31
+
32
+apache_get() {
33
+ apache_response=($(curl -s "${apache_url}"))
34
+ [ $? -ne 0 -o "${#apache_response[@]}" -eq 0 ] && return 1
35
+
36
+ if [ "${apache_response[0]}" != "Total" \
37
+ -o "${apache_response[1]}" != "Accesses:" \
38
+ -o "${apache_response[3]}" != "Total" \
39
+ -o "${apache_response[4]}" != "kBytes:" \
40
+ -o "${apache_response[6]}" != "CPULoad:" \
41
+ -o "${apache_response[8]}" != "Uptime:" \
42
+ -o "${apache_response[10]}" != "ReqPerSec:" \
43
+ -o "${apache_response[12]}" != "BytesPerSec:" \
44
+ -o "${apache_response[14]}" != "BytesPerReq:" \
45
+ -o "${apache_response[16]}" != "BusyWorkers:" \
46
+ -o "${apache_response[18]}" != "IdleWorkers:" \
47
+ -o "${apache_response[20]}" != "Scoreboard:" \
48
+ ]
49
+ then
50
+ echo >&2 "apache: Invalid response from apache server: ${apache_response[*]}"
51
+ return 1
52
+ fi
53
+
54
+ apache_accesses="${apache_response[2]}"
55
+ apache_kbytes="${apache_response[5]}"
56
+
57
+ # float2int "${apache_response[7]}" ${apache_decimal_detail}
58
+ # apache_cpuload=${FLOAT2INT_RESULT}
59
+
60
+ # apache_uptime="${apache_response[9]}"
61
+
62
+ if [ ${apache_averages} -eq 1 ]
63
+ then
64
+ float2int "${apache_response[11]}" ${apache_decimal_detail}
65
+ apache_reqpersec=${FLOAT2INT_RESULT}
66
+
67
+ float2int "${apache_response[13]}" ${apache_decimal_detail}
68
+ apache_bytespersec=${FLOAT2INT_RESULT}
69
+ fi
70
+
71
+ float2int "${apache_response[15]}" ${apache_decimal_detail}
72
+ apache_bytesperreq=${FLOAT2INT_RESULT}
73
+
74
+ apache_busyworkers="${apache_response[17]}"
75
+ apache_idleworkers="${apache_response[19]}"
76
+ apache_scoreboard="${apache_response[21]}"
77
+
78
+ if [ -z "${apache_accesses}" \
79
+ -o -z "${apache_kbytes}" \
80
+ -o -z "${apache_cpuload}" \
81
+ -o -z "${apache_uptime}" \
82
+ -o -z "${apache_reqpersec}" \
83
+ -o -z "${apache_bytespersec}" \
84
+ -o -z "${apache_bytesperreq}" \
85
+ -o -z "${apache_busyworkers}" \
86
+ -o -z "${apache_idleworkers}" \
87
+ -o -z "${apache_scoreboard}" \
88
+ ]
89
+ then
90
+ echo >&2 "apache: empty values got from apache server: ${apache_response[*]}"
91
+ return 1
92
+ fi
93
+
94
+ return 0
95
+}
96
+
97
+# _check is called once, to find out if this chart should be enabled or not
98
+apache_check() {
99
+
100
+ apache_get
101
+ if [ $? -ne 0 ]
102
+ then
103
+ 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"
104
+ return 1
105
+ fi
106
+
107
+ # this should return:
108
+ # - 0 to enable the chart
109
+ # - 1 to disable the chart
110
+
111
+ return 0
112
+}
113
+
114
+# _create is called once, to create the charts
115
+apache_create() {
116
+ cat <<EOF
117
+CHART apache.bytesperreq '' "apache Average Response Size (lifetime)" "bytes/request" apache apache area 16005 $apache_update_every
118
+DIMENSION size '' absolute 1 ${apache_decimal_detail}
119
+CHART apache.workers '' "apache Workers" "workers" apache apache stacked 16006 $apache_update_every
120
+DIMENSION idle '' absolute 1 1
121
+DIMENSION busy '' absolute 1 1
122
+EOF
123
+
124
+ if [ ${apache_averages} -eq 1 ]
125
+ then
126
+ # apache calculated averages
127
+ cat <<EOF2
128
+CHART apache.requests '' "apache Requests" "requests/s" apache apache line 16001 $apache_update_every
129
+DIMENSION requests '' absolute 1 ${apache_decimal_detail}
130
+CHART apache.net '' "apache Bandwidth" "kilobits/s" apache apache area 16002 $apache_update_every
131
+DIMENSION sent '' absolute 8 $[apache_decimal_detail * 1000]
132
+EOF2
133
+ else
134
+ # netdata calculated averages
135
+ cat <<EOF3
136
+CHART apache.requests '' "apache Requests" "requests/s" apache apache line 16001 $apache_update_every
137
+DIMENSION requests '' incremental 1 1
138
+CHART apache.net '' "apache Bandwidth" "kilobits/s" apache apache area 16002 $apache_update_every
139
+DIMENSION sent '' incremental 8 1
140
+EOF3
141
+ fi
142
+
143
+ return 0
144
+}
145
+
146
+# _update is called continiously, to collect the values
147
+apache_update() {
148
+ local reqs net
149
+ # the first argument to this function is the microseconds since last update
150
+ # pass this parameter to the BEGIN statement (see bellow).
151
+
152
+ # do all the work to collect / calculate the values
153
+ # for each dimension
154
+ # remember: KEEP IT SIMPLE AND SHORT
155
+
156
+ apache_get || return 1
157
+
158
+ if [ ${apache_averages} -eq 1 ]
159
+ then
160
+ reqs=${apache_reqpersec}
161
+ net=${apache_bytespersec}
162
+ else
163
+ reqs=${apache_accesses}
164
+ net=${apache_kbytes}
165
+ fi
166
+
167
+ # write the result of the work.
168
+ cat <<VALUESEOF
169
+BEGIN apache.requests $1
170
+SET requests = $[reqs]
171
+END
172
+BEGIN apache.net $1
173
+SET sent = $[net]
174
+END
175
+BEGIN apache.bytesperreq $1
176
+SET size = $[apache_bytesperreq]
177
+END
178
+BEGIN apache.workers $1
179
+SET idle = $[apache_idleworkers]
180
+SET busy = $[apache_busyworkers]
181
+END
182
+VALUESEOF
183
+
184
+ return 0
185
+}