]> arthur.barton.de Git - netdata.git/blob - charts.d/airsearches.chart.sh
Merge pull request #560 from paulfantom/master
[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" -e "s/^/airsearches_/g" |\
10                 tr "[A-Z]\.\!@#\$%^&*()_+\-" "[a-z]_____________" |\
11                 egrep "^airsearches_[a-z0-9_]+=[0-9]+$"
12 }
13
14 airsearches_check() {
15         # make sure we have all the commands we need
16         require_cmd wget || return 1
17
18         # make sure we are configured
19         if [ -z "$airsearches_url" ]
20                 then
21                 echo >&2 "$PROGRAM_NAME: airsearches: not configured. Please set airsearches_url='url' in $confd/airsearches.conf"
22                 return 1
23         fi
24
25         # check once if the url works
26         wget 2>/dev/null -O /dev/null "$airsearches_url"
27         if [ ! $? -eq 0 ]
28         then
29                 echo >&2 "$PROGRAM_NAME: airsearches: cannot fetch the url: $airsearches_url. Please set airsearches_url='url' in $confd/airsearches.conf"
30                 return 1
31         fi
32
33         # if the admin did not give any commands
34         # find the available ones
35         if [ -z "$airsearches_cmds" ]
36         then
37                 airsearches_cmds="$(airsearches_get | cut -d '=' -f 1 | sed "s/^airsearches_//g" | sort -u)"
38                 echo
39         fi
40
41         # did we find any commands?
42         if [ -z "$airsearches_cmds" ]
43         then
44                 echo >&2 "$PROGRAM_NAME: airsearches: cannot find command list automatically. Please set airsearches_cmds='...' in $confd/airsearches.conf"
45                 return 1
46         fi
47
48         # ok we can do it
49         return 0
50 }
51
52 airsearches_create() {
53         [ -z "$airsearches_cmds" ] && return 1
54
55         # create the charts
56         local x=
57         echo "CHART airsearches.affiliates '' 'Air Searches per affiliate' 'requests / min' airsearches '' stacked 20000 $airsearches_update_every"
58         for x in $airsearches_cmds
59         do
60                 echo "DIMENSION $x '' incremental 60 1"
61         done
62
63         return 0
64 }
65
66 airsearches_update() {
67         # the first argument to this function is the microseconds since last update
68         # pass this parameter to the BEGIN statement (see bellow).
69
70         # do all the work to collect / calculate the values
71         # for each dimension
72         # remember: KEEP IT SIMPLE AND SHORT
73
74         # get the values from airsearches
75         eval "$(airsearches_get)"
76
77         # write the result of the work.
78         local x=
79
80         echo "BEGIN airsearches.affiliates $1"
81         for x in $airsearches_cmds
82         do
83                 eval "v=\$airsearches_$x"
84                 echo "SET $x = $v"
85         done
86         echo "END"
87
88         airsearches_dt=0
89
90         return 0
91 }