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