]> arthur.barton.de Git - netdata.git/blob - charts.d/squid.chart.sh
Now there are 2 kinds of plugins:
[netdata.git] / charts.d / squid.chart.sh
1 #!/bin/sh
2
3 url="http://127.0.0.1:8080/squid-internal-mgr/counters"
4
5 # report our PID back to netdata
6 # this is required for netdata to kill this process when it exits
7 echo "MYPID $$"
8
9 # default sleep function
10 loopsleepms() {
11         sleep $1
12 }
13 # if found and included, this file overwrites loopsleepms()
14 # with a high resolution timer function for precise looping.
15 . "`dirname $0`/loopsleepms.sh.inc"
16
17 # netdata passes the requested update frequency as the first argument
18 update_every=$1
19 update_every=$(( update_every + 1 - 1)) # makes sure it is a number
20 test $update_every -eq 0 && update_every=1 # if it is zero, make it 1
21
22 # we accept a url as the second argument
23 if [ ! -z "$2" ]
24 then
25         url="$2"
26 fi
27
28 # check once if the url works
29 wget 2>/dev/null -O /dev/null "$url"
30 if [ ! $? -eq 0 ]
31 then
32         # it does not work - disable the plugin
33         echo "DISABLE"
34         exit 1
35 fi
36
37 # create the charts
38 cat <<EOF
39 CHART squid.client_bandwidth '' "Squid Client Bandwidth" "kilobits/s" squid squid area 1 $update_every
40 DIMENSION client_http_kbytes_in in incremental 8 1
41 DIMENSION client_http_kbytes_out out incremental -8 1
42 DIMENSION client_http_hit_kbytes_out hits incremental -8 1
43
44 CHART squid.client_requests '' "Squid Client Requests" "requests/s" squid squid line 3 $update_every
45 DIMENSION client_http_requests requests incremental 1 1
46 DIMENSION client_http_hits hits incremental 1 1
47 DIMENSION client_http_errors errors incremental -1 1
48
49 CHART squid.server_bandwidth '' "Squid Server Bandwidth" "kilobits/s" squid squid area 2 $update_every
50 DIMENSION server_all_kbytes_in in incremental 8 1
51 DIMENSION server_all_kbytes_out out incremental -8 1
52
53 CHART squid.server_requests '' "Squid Server Requests" "requests/s" squid squid line 4 $update_every
54 DIMENSION server_all_requests requests incremental 1 1
55 DIMENSION server_all_errors errors incremental -1 1
56 EOF
57
58 # You can create more charts if you like.
59 # Just add more chart definitions.
60
61 # work forever
62 while [ 1 ]
63 do
64         # do all the work to collect / calculate the values
65         # for each dimension
66
67         # get the values from squid
68         eval `wget 2>/dev/null -O - "$url" | sed -e "s/\./_/g" -e "s/ = /=/g" | egrep "(^client_http_|^server_all_)"`
69
70         # write the result of the work.
71         cat <<VALUESEOF
72 BEGIN squid.client_bandwidth
73 SET client_http_kbytes_in = $client_http_kbytes_in
74 SET client_http_kbytes_out = $client_http_kbytes_out
75 SET client_http_hit_kbytes_out = $client_http_hit_kbytes_out
76 END
77
78 BEGIN squid.client_requests
79 SET client_http_requests = $client_http_requests
80 SET client_http_hits = $client_http_hits
81 SET client_http_errors = $client_http_errors
82 END
83
84 BEGIN squid.server_bandwidth
85 SET server_all_kbytes_in = $server_all_kbytes_in
86 SET server_all_kbytes_out = $server_all_kbytes_out
87 END
88
89 BEGIN squid.server_requests
90 SET server_all_requests = $server_all_requests
91 SET server_all_errors = $server_all_errors
92 END
93 VALUESEOF
94
95         # wait the time you are required to
96         loopsleepms $update_every
97 done