#!/bin/sh
-squid_url="http://127.0.0.1:8080/squid-internal-mgr/counters"
+squid_host="127.0.0.1"
+squid_port="3128"
+squid_url="cache_object://$squid_host:$squid_port/counters"
+squid_update_every=5
+
+squid_get_stats() {
+ nc $squid_host $squid_port <<EOF
+GET $squid_url HTTP/1.0
+Host: $squid_host:$squid_port
+Accept: */*
+User-Agent: netdata (charts.d/squid.chart.sh)
+
+EOF
+}
squid_check() {
+ squid_url="cache_object://$squid_host:$squid_port/counters"
+
# check once if the url works
- wget 2>/dev/null -O /dev/null "$squid_url"
- if [ ! $? -eq 0 ]
+ local x="$(squid_get_stats | grep client_http.requests)"
+ if [ ! $? -eq 0 -o -z "$x" ]
then
- echo >&2 "squid: cannot fetch the counters url: $squid_url. Please set squid_url='url' in $confd/squid.conf"
+ echo >&2 "squid: cannot fetch URL '$squid_url' by connecting to $squid_host:$squid_port. Please set squid_url='url' and squid_host='host' and squid_port='port' in $confd/squid.conf"
return 1
fi
squid_create() {
# create the charts
cat <<EOF
-CHART squid.clients_net '' "Squid Client Bandwidth" "kilobits/s" squid '' area 20001 $update_every
-DIMENSION client_http_kbytes_in in incremental 8 1
-DIMENSION client_http_kbytes_out out incremental -8 1
-DIMENSION client_http_hit_kbytes_out hits incremental -8 1
-
-CHART squid.clients_requests '' "Squid Client Requests" "requests/s" squid '' line 20003 $update_every
-DIMENSION client_http_requests requests incremental-no-interpolation 1 1
-DIMENSION client_http_hits hits incremental-no-interpolation 1 1
-DIMENSION client_http_errors errors incremental-no-interpolation -1 1
-
-CHART squid.servers_net '' "Squid Server Bandwidth" "kilobits/s" squid '' area 20002 $update_every
-DIMENSION server_all_kbytes_in in incremental 8 1
-DIMENSION server_all_kbytes_out out incremental -8 1
-
-CHART squid.servers_requests '' "Squid Server Requests" "requests/s" squid '' line 20004 $update_every
-DIMENSION server_all_requests requests incremental-no-interpolation 1 1
-DIMENSION server_all_errors errors incremental-no-interpolation -1 1
+CHART squid.clients_net '' "Squid Client Bandwidth" "kilobits / sec" squid '' area 20001 $squid_update_every
+DIMENSION client_http_kbytes_in in incremental 8 $((1 * squid_update_every))
+DIMENSION client_http_kbytes_out out incremental -8 $((1 * squid_update_every))
+DIMENSION client_http_hit_kbytes_out hits incremental -8 $((1 * squid_update_every))
+
+CHART squid.clients_requests '' "Squid Client Requests" "requests / sec" squid '' line 20003 $squid_update_every
+DIMENSION client_http_requests requests incremental 1 $((1 * squid_update_every))
+DIMENSION client_http_hits hits incremental 1 $((1 * squid_update_every))
+DIMENSION client_http_errors errors incremental -1 $((1 * squid_update_every))
+
+CHART squid.servers_net '' "Squid Server Bandwidth" "kilobits / sec" squid '' area 20002 $squid_update_every
+DIMENSION server_all_kbytes_in in incremental 8 $((1 * squid_update_every))
+DIMENSION server_all_kbytes_out out incremental -8 $((1 * squid_update_every))
+
+CHART squid.servers_requests '' "Squid Server Requests" "requests / sec" squid '' line 20004 $squid_update_every
+DIMENSION server_all_requests requests incremental 1 $((1 * squid_update_every))
+DIMENSION server_all_errors errors incremental -1 $((1 * squid_update_every))
EOF
return 0
# for each dimension
# remember: KEEP IT SIMPLE AND SHORT
- # 1. wget the counters page from squid
+ # 1. get the counters page from squid
# 2. sed to remove spaces; replace . with _; remove spaces around =; prepend each line with: local squid_
# 3. egrep lines starting with:
# local squid_client_http_ then one or more of these a-z 0-9 _ then = and one of more of 0-9
# prepare the script and always grep at the end the lines that are usefull, so that
# even if something goes wrong, no other code can be executed
- eval "`wget 2>/dev/null -O - "$squid_url" |\
- sed -e "s/ \+/ /g" -e "s/\./_/g" -e "s/ = /=/g" -e "s/^/local squid_/g" |\
- egrep "^local squid_(client_http|server_all)_[a-z0-9_]+=[0-9]+$"`"
+ eval "$(squid_get_stats |\
+ sed -e "s/ \+/ /g" -e "s/\./_/g" -e "s/^\([a-z0-9_]\+\) *= *\([0-9]\+\)$/local squid_\1=\2/g" |\
+ egrep "^local squid_(client_http|server_all)_[a-z0-9_]+=[0-9]+$")"
# write the result of the work.
cat <<VALUESEOF