better apache fields parsing
Costa Tsaousis (ktsaou) committed
Jan 23, 2016 at 15:21 UTC
f8d5a8f5070c592efa58648ff9619775ff122427
1 file changed
+24
-17
charts.d/apache.chart.sh
+24
-17
@@ -44,17 +44,17 @@ apache_detect() {
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] ;;
47
+ 'Total Accesses') apache_key_accesses=$[i + 1] ;;
48
+ 'Total 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]
@@ -88,8 +88,12 @@ apache_detect() {
88
}
89
90
apache_get() {
91
- apache_response=($(curl -s "${apache_url}"))
92
- [ $? -ne 0 -o "${#apache_response[@]}" -eq 0 ] && return 1
91
+ local oIFS="${IFS}" ret
92
+ IFS=$':\n' apache_response=($(curl -s "${apache_url}"))
93
+ ret=$?
94
+ IFS="${oIFS}"
95
+
96
+ [ $ret -ne 0 -o "${#apache_response[@]}" -eq 0 ] && return 1
97
98
if [ ${apache_keys_detected} -eq 0 ]
99
then
@@ -125,10 +129,13 @@ apache_get() {
129
return 1
130
fi
131
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
+ if [ ${apache_has_conns} -eq 1 ]
133
+ then
134
+ apache_connstotal="${apache_response[${apache_key_connstotal}]}"
135
+ apache_connsasyncwriting="${apache_response[${apache_key_connsasyncwriting}]}"
136
+ apache_connsasynckeepalive="${apache_response[${apache_key_connsasynckeepalive}]}"
137
+ apache_connsasyncclosing="${apache_response[${apache_key_connsasyncclosing}]}"
138
+ fi
139
140
return 0
141
}