]> arthur.barton.de Git - netdata.git/blobdiff - charts.d/squid.chart.sh
Merge remote-tracking branch 'upstream/master'
[netdata.git] / charts.d / squid.chart.sh
index fad8f9f7a31dfea7dc3ddcee9e716aa53e556446..f6154b256539afec06f49f3d93cd3199f01c55d2 100755 (executable)
@@ -1,22 +1,53 @@
 #!/bin/sh
 
-squid_host="127.0.0.1"
-squid_port="3128"
-squid_url="cache_object://$squid_host:$squid_port/counters"
+squid_host=
+squid_port=
+squid_url=
+squid_timeout=2
 squid_update_every=5
+squid_priority=60000
+
+squid_get_stats_internal() {
+       local host="$1" port="$2" url="$3"
+       squidclient -h $host -p $port $url
+}
 
 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)
+       squid_get_stats_internal "$squid_host" "$squid_port" "$squid_url"
+}
 
-EOF
+squid_autodetect() {
+       local host="127.0.0.1" port url x
+
+       for port in 3128 8080
+       do
+               for url in "cache_object://$host:$port/counters" "/squid-internal-mgr/counters"
+               do
+                       x=$(squid_get_stats_internal "$host" "$port" "$url" | grep client_http.requests)
+                       if [ ! -z "$x" ]
+                               then
+                               squid_host="$host"
+                               squid_port="$port"
+                               squid_url="$url"
+                               echo >&2 "squid: found squid at '$host:$port' with url '$url'"
+                               return 0
+                       fi
+               done
+       done
+
+       echo >&2 "squid: cannot find squid running in localhost. Please set squid_url='url' and squid_host='IP' and squid_port='PORT' in $confd/squid.conf"
+       return 1
 }
 
 squid_check() {
-       squid_url="cache_object://$squid_host:$squid_port/counters"
+       require_cmd squidclient || return 1
+       require_cmd sed || return 1
+       require_cmd egrep || return 1
+
+       if [ -z "$squid_host" -o -z "$squid_port" -o -z "$squid_url" ]
+               then
+               squid_autodetect || return 1
+       fi
 
        # check once if the url works
        local x="$(squid_get_stats | grep client_http.requests)"
@@ -32,25 +63,25 @@ squid_check() {
 squid_create() {
        # create the charts
        cat <<EOF
-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))
+CHART squid.clients_net '' "Squid Client Bandwidth" "kilobits / sec" clients squid.clients.net area $((squid_priority + 1)) $squid_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 / sec" clients squid.clients.requests line $((squid_priority + 3)) $squid_update_every
+DIMENSION client_http_requests requests incremental 1 1
+DIMENSION client_http_hits hits incremental 1 1
+DIMENSION client_http_errors errors incremental -1 1
+
+CHART squid.servers_net '' "Squid Server Bandwidth" "kilobits / sec" servers squid.servers.net area $((squid_priority + 2)) $squid_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 / sec" servers squid.servers.requests line $((squid_priority + 4)) $squid_update_every
+DIMENSION server_all_requests requests incremental 1 1
+DIMENSION server_all_errors errors incremental -1 1
 EOF
-       
+
        return 0
 }
 
@@ -105,4 +136,3 @@ VALUESEOF
 
        return 0
 }
-