now it queries cache_object with nc, instead of wget
Costa Tsaousis (ktsaou) committed
Dec 23, 2014 at 00:06 UTC
9a5715d759a00571c0d146aa2cdfc591082ded57
1 file changed
+14
-6
charts.d/squid.chart.sh
+14
-6
@@ -1,14 +1,22 @@
1
#!/bin/sh
2
3
-squid_url="http://127.0.0.1:8080/squid-internal-mgr/counters"
3
+squid_host="127.0.0.1"
4
+squid_port="3128"
5
squid_update_every=5
6
7
+squid_get_stats() {
8
+nc $squid_host $squid_port <<EOF
9
+GET cache_object://$squid_host:$squid_port/counters HTTP/1.0
10
+
11
+EOF
12
+}
13
+
14
squid_check() {
15
# check once if the url works
8
- wget 2>/dev/null -O /dev/null "$squid_url"
9
- if [ ! $? -eq 0 ]
16
+ local x=`squid_get_stats | grep client_http.requests`
17
+ if [ ! $? -eq 0 -o -z "$x" ]
18
then
11
- echo >&2 "squid: cannot fetch the counters url: $squid_url. Please set squid_url='url' in $confd/squid.conf"
19
+ echo >&2 "squid: cannot fetch the counters from $squid_host:$squid_port. Please set squid_host='host' and squid_port='port' in $confd/squid.conf"
20
return 1
21
fi
22
@@ -60,8 +68,8 @@ squid_update() {
68
# prepare the script and always grep at the end the lines that are usefull, so that
69
# even if something goes wrong, no other code can be executed
70
63
- eval "`wget 2>/dev/null -O - "$squid_url" |\
64
- sed -e "s/ \+/ /g" -e "s/\./_/g" -e "s/ = /=/g" -e "s/^/local squid_/g" |\
71
+ eval "`squid_get_stats |\
72
+ sed -e "s/ \+/ /g" -e "s/\./_/g" -e "s/^\([a-z0-9_]\+\) *= *\([0-9]\+\)$/local squid_\1=\2/g" |\
73
egrep "^local squid_(client_http|server_all)_[a-z0-9_]+=[0-9]+$"`"
74
75
# write the result of the work.