]> arthur.barton.de Git - netdata.git/blob - charts.d/squid.chart.sh
added support for different update frequency per chart in charts.d.plugin
[netdata.git] / charts.d / squid.chart.sh
1 #!/bin/sh
2
3 squid_url="http://127.0.0.1:8080/squid-internal-mgr/counters"
4 squid_update_every=5
5
6 squid_check() {
7         # check once if the url works
8         wget 2>/dev/null -O /dev/null "$squid_url"
9         if [ ! $? -eq 0 ]
10         then
11                 echo >&2 "squid: cannot fetch the counters url: $squid_url. Please set squid_url='url' in $confd/squid.conf"
12                 return 1
13         fi
14
15         return 0
16 }
17
18 squid_create() {
19         # create the charts
20         cat <<EOF
21 CHART squid.clients_net '' "Squid Client Bandwidth" "kilobits / $squid_update_every sec" squid '' area 20001 $squid_update_every
22 DIMENSION client_http_kbytes_in in incremental 8 1
23 DIMENSION client_http_kbytes_out out incremental -8 1
24 DIMENSION client_http_hit_kbytes_out hits incremental -8 1
25
26 CHART squid.clients_requests '' "Squid Client Requests" "requests / $squid_update_every sec" squid '' line 20003 $squid_update_every
27 DIMENSION client_http_requests requests incremental 1 1
28 DIMENSION client_http_hits hits incremental 1 1
29 DIMENSION client_http_errors errors incremental -1 1
30
31 CHART squid.servers_net '' "Squid Server Bandwidth" "kilobits / $squid_update_every sec" squid '' area 20002 $squid_update_every
32 DIMENSION server_all_kbytes_in in incremental 8 1
33 DIMENSION server_all_kbytes_out out incremental -8 1
34
35 CHART squid.servers_requests '' "Squid Server Requests" "requests / $squid_update_every sec" squid '' line 20004 $squid_update_every
36 DIMENSION server_all_requests requests incremental 1 1
37 DIMENSION server_all_errors errors incremental -1 1
38 EOF
39         
40         return 0
41 }
42
43
44 squid_update() {
45         # the first argument to this function is the microseconds since last update
46         # pass this parameter to the BEGIN statement (see bellow).
47
48         # do all the work to collect / calculate the values
49         # for each dimension
50         # remember: KEEP IT SIMPLE AND SHORT
51
52         # 1. wget the counters page from squid
53         # 2. sed to remove spaces; replace . with _; remove spaces around =; prepend each line with: local squid_
54         # 3. egrep lines starting with:
55         #    local squid_client_http_ then one or more of these a-z 0-9 _ then = and one of more of 0-9
56         #    local squid_server_all_ then one or more of these a-z 0-9 _ then = and one of more of 0-9
57         # 4. then execute this as a script with the eval
58         #
59         # be very carefull with eval:
60         # prepare the script and always grep at the end the lines that are usefull, so that
61         # even if something goes wrong, no other code can be executed
62
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" |\
65                 egrep "^local squid_(client_http|server_all)_[a-z0-9_]+=[0-9]+$"`"
66
67         # write the result of the work.
68         cat <<VALUESEOF
69 BEGIN squid.clients_net $1
70 SET client_http_kbytes_in = $squid_client_http_kbytes_in
71 SET client_http_kbytes_out = $squid_client_http_kbytes_out
72 SET client_http_hit_kbytes_out = $squid_client_http_hit_kbytes_out
73 END
74
75 BEGIN squid.clients_requests $1
76 SET client_http_requests = $squid_client_http_requests
77 SET client_http_hits = $squid_client_http_hits
78 SET client_http_errors = $squid_client_http_errors
79 END
80
81 BEGIN squid.servers_net $1
82 SET server_all_kbytes_in = $squid_server_all_kbytes_in
83 SET server_all_kbytes_out = $squid_server_all_kbytes_out
84 END
85
86 BEGIN squid.servers_requests $1
87 SET server_all_requests = $squid_server_all_requests
88 SET server_all_errors = $squid_server_all_errors
89 END
90 VALUESEOF
91
92         return 0
93 }
94