From 1e6c93250172946eeb38e94a92a1fd12c9d3011e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 7 Nov 2018 13:22:44 +0100 Subject: Merging upstream version 1.11.0+dfsg. Signed-off-by: Daniel Baumann --- collectors/charts.d.plugin/squid/squid.chart.sh | 147 ++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 collectors/charts.d.plugin/squid/squid.chart.sh (limited to 'collectors/charts.d.plugin/squid/squid.chart.sh') diff --git a/collectors/charts.d.plugin/squid/squid.chart.sh b/collectors/charts.d.plugin/squid/squid.chart.sh new file mode 100644 index 000000000..cf5d1d78a --- /dev/null +++ b/collectors/charts.d.plugin/squid/squid.chart.sh @@ -0,0 +1,147 @@ +# shellcheck shell=bash disable=SC2154 +# no need for shebang - this file is loaded from charts.d.plugin +# SPDX-License-Identifier: GPL-3.0-or-later + +# netdata +# real-time performance and health monitoring, done right! +# (C) 2016 Costa Tsaousis +# + +squid_host= +squid_port= +squid_url= +squid_update_every=2 +squid_priority=60000 + +squid_get_stats_internal() { + local host="$1" port="$2" url="$3" + run squidclient -h "$host" -p "$port" "$url" +} + +squid_get_stats() { + squid_get_stats_internal "$squid_host" "$squid_port" "$squid_url" +} + +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" + debug "found squid at '$host:$port' with url '$url'" + return 0 + fi + done + done + + error "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() { + require_cmd squidclient || return 1 + require_cmd sed || return 1 + require_cmd egrep || return 1 + + if [ -z "$squid_host" ] || [ -z "$squid_port" ] || [ -z "$squid_url" ] + then + squid_autodetect || return 1 + fi + + # check once if the url works + local x + x="$(squid_get_stats | grep client_http.requests)" + # shellcheck disable=SC2181 + if [ ! $? -eq 0 ] || [ -z "$x" ] + then + error "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 + + return 0 +} + +squid_create() { + # create the charts + cat <