]> arthur.barton.de Git - netdata.git/blob - charts.d/airsearches.chart.sh
per minute reporting
[netdata.git] / charts.d / airsearches.chart.sh
1 #!/bin/sh
2
3 airsearches_url=
4 airsearches_cmds=
5 airsearches_update_every=15
6
7 airsearches_get() {
8         wget 2>/dev/null -O - "$airsearches_url" |\
9                 sed -e "s|<br />|\n|g" -e "s|: |=|g" -e "s| \+|_|g" |\
10                 tr "[A-Z]\.\!@#\$%^&*()_+\-" "[a-z]_____________" |\
11                 egrep "^[a-z0-9_]+=[0-9]+$" |\
12                 sort -u
13 }
14
15 airsearches_check() {
16         # check once if the url works
17         wget 2>/dev/null -O /dev/null "$airsearches_url"
18         if [ ! $? -eq 0 ]
19         then
20                 echo >&2 "airsearches: cannot fetch the url: $airsearches_url. Please set airsearches_url='url' in $confd/airsearches.conf"
21                 return 1
22         fi
23
24         if [ -z "$airsearches_cmds" ]
25         then
26                 airsearches_cmds="`airsearches_get | cut -d '=' -f 1`"
27                 echo
28         fi
29         if [ -z "$airsearches_cmds" ]
30         then
31                 echo >&2 "airsearches: cannot find command list automatically. Please set airsearches_cmds='...' in $confd/airsearches.conf"
32                 return 1
33         fi
34         return 0
35 }
36
37 airsearches_create() {
38         # create the charts
39         local x=
40         echo "CHART airsearches.affiliates '' 'Air Searches per affiliate' 'requests / min' airsearches '' stacked 20000 $airsearches_update_every"
41         for x in $airsearches_cmds
42         do
43                 echo "DIMENSION $x '' incremental 60 $airsearches_update_every"
44         done
45
46         return 0
47 }
48
49 airsearches_update() {
50         # the first argument to this function is the microseconds since last update
51         # pass this parameter to the BEGIN statement (see bellow).
52
53         # do all the work to collect / calculate the values
54         # for each dimension
55         # remember: KEEP IT SIMPLE AND SHORT
56
57         # get the values from airsearches
58         eval "`airsearches_get | sed "s/^/airsearches_/g"`"
59
60         # write the result of the work.
61         local x=
62
63         echo "BEGIN airsearches.affiliates $1"
64         for x in $airsearches_cmds
65         do
66                 eval "v=\$airsearches_$x"
67                 echo "SET $x = $v"
68         done
69         echo "END"
70
71         airsearches_dt=0
72
73         return 0
74 }