summaryrefslogtreecommitdiffstats
path: root/collectors/charts.d.plugin/squid
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2018-11-07 12:19:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2018-11-07 12:20:17 +0000
commita64a253794ac64cb40befee54db53bde17dd0d49 (patch)
treec1024acc5f6e508814b944d99f112259bb28b1be /collectors/charts.d.plugin/squid
parentNew upstream version 1.10.0+dfsg (diff)
downloadnetdata-a64a253794ac64cb40befee54db53bde17dd0d49.tar.xz
netdata-a64a253794ac64cb40befee54db53bde17dd0d49.zip
New upstream version 1.11.0+dfsgupstream/1.11.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'collectors/charts.d.plugin/squid')
-rw-r--r--collectors/charts.d.plugin/squid/Makefile.inc13
-rw-r--r--collectors/charts.d.plugin/squid/README.md66
-rw-r--r--collectors/charts.d.plugin/squid/squid.chart.sh147
-rw-r--r--collectors/charts.d.plugin/squid/squid.conf26
4 files changed, 252 insertions, 0 deletions
diff --git a/collectors/charts.d.plugin/squid/Makefile.inc b/collectors/charts.d.plugin/squid/Makefile.inc
new file mode 100644
index 000000000..ad470d88c
--- /dev/null
+++ b/collectors/charts.d.plugin/squid/Makefile.inc
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# THIS IS NOT A COMPLETE Makefile
+# IT IS INCLUDED BY ITS PARENT'S Makefile.am
+# IT IS REQUIRED TO REFERENCE ALL FILES RELATIVE TO THE PARENT
+
+# install these files
+dist_charts_DATA += squid/squid.chart.sh
+dist_chartsconfig_DATA += squid/squid.conf
+
+# do not install these files, but include them in the distribution
+dist_noinst_DATA += squid/README.md squid/Makefile.inc
+
diff --git a/collectors/charts.d.plugin/squid/README.md b/collectors/charts.d.plugin/squid/README.md
new file mode 100644
index 000000000..0934ccfcf
--- /dev/null
+++ b/collectors/charts.d.plugin/squid/README.md
@@ -0,0 +1,66 @@
+> THIS MODULE IS OBSOLETE.
+> USE THE PYTHON ONE - IT SUPPORTS MULTIPLE JOBS AND IT IS MORE EFFICIENT
+
+
+# squid
+
+The plugin will monitor a squid server.
+
+It will produce 4 charts:
+
+1. **Squid Client Bandwidth** in kbps
+
+ * in
+ * out
+ * hits
+
+2. **Squid Client Requests** in requests/sec
+
+ * requests
+ * hits
+ * errors
+
+3. **Squid Server Bandwidth** in kbps
+
+ * in
+ * out
+
+4. **Squid Server Requests** in requests/sec
+
+ * requests
+ * errors
+
+### autoconfig
+
+The plugin will by itself detect squid servers running on
+localhost, on ports 3128 or 8080.
+
+It will attempt to download URLs in the form:
+
+- `cache_object://HOST:PORT/counters`
+- `/squid-internal-mgr/counters`
+
+If any succeeds, it will use this.
+
+### configuration
+
+If you need to configure it by hand, create the file
+`/etc/netdata/squid.conf` with the following variables:
+
+- `squid_host=IP` the IP of the squid host
+- `squid_port=PORT` the port the squid is listening
+- `squid_url="URL"` the URL with the statistics to be fetched from squid
+- `squid_timeout=SECONDS` how much time we should wait for squid to respond
+- `squid_update_every=SECONDS` the frequency of the data collection
+
+Example `/etc/netdata/squid.conf`:
+
+```sh
+squid_host=127.0.0.1
+squid_port=3128
+squid_url="cache_object://127.0.0.1:3128/counters"
+squid_timeout=2
+squid_update_every=5
+```
+
+---
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 <costa@tsaousis.gr>
+#
+
+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 <<EOF
+CHART squid_local.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_local.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_local.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_local.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
+}
+
+
+squid_update() {
+ # the first argument to this function is the microseconds since last update
+ # pass this parameter to the BEGIN statement (see bellow).
+
+ # do all the work to collect / calculate the values
+ # for each dimension
+ # remember: KEEP IT SIMPLE AND SHORT
+
+ # 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
+ # local squid_server_all_ then one or more of these a-z 0-9 _ then = and one of more of 0-9
+ # 4. then execute this as a script with the eval
+ #
+ # be very carefull with eval:
+ # 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
+
+ # shellcheck disable=SC1117
+ eval "$(squid_get_stats |\
+ sed -e "s/ \+/ /g" -e "s/\./_/g" -e "s/^\([a-z0-9_]\+\) *= *\([0-9]\+\)$/local squid_\1=\2/g" |\
+ grep -E "^local squid_(client_http|server_all)_[a-z0-9_]+=[0-9]+$")"
+
+ # write the result of the work.
+ cat <<VALUESEOF
+BEGIN squid_local.clients_net $1
+SET client_http_kbytes_in = $squid_client_http_kbytes_in
+SET client_http_kbytes_out = $squid_client_http_kbytes_out
+SET client_http_hit_kbytes_out = $squid_client_http_hit_kbytes_out
+END
+
+BEGIN squid_local.clients_requests $1
+SET client_http_requests = $squid_client_http_requests
+SET client_http_hits = $squid_client_http_hits
+SET client_http_errors = $squid_client_http_errors
+END
+
+BEGIN squid_local.servers_net $1
+SET server_all_kbytes_in = $squid_server_all_kbytes_in
+SET server_all_kbytes_out = $squid_server_all_kbytes_out
+END
+
+BEGIN squid_local.servers_requests $1
+SET server_all_requests = $squid_server_all_requests
+SET server_all_errors = $squid_server_all_errors
+END
+VALUESEOF
+
+ return 0
+}
diff --git a/collectors/charts.d.plugin/squid/squid.conf b/collectors/charts.d.plugin/squid/squid.conf
new file mode 100644
index 000000000..19e928f25
--- /dev/null
+++ b/collectors/charts.d.plugin/squid/squid.conf
@@ -0,0 +1,26 @@
+# no need for shebang - this file is loaded from charts.d.plugin
+
+# netdata
+# real-time performance and health monitoring, done right!
+# (C) 2018 Costa Tsaousis <costa@tsaousis.gr>
+# GPL v3+
+
+# THIS PLUGIN IS DEPRECATED
+# USE THE PYTHON.D ONE
+
+#squid_host=
+#squid_port=
+#squid_url=
+#squid_timeout=2
+
+# the data collection frequency
+# if unset, will inherit the netdata update frequency
+#squid_update_every=2
+
+# the charts priority on the dashboard
+#squid_priority=60000
+
+# the number of retries to do in case of failure
+# before disabling the module
+#squid_retries=10
+