]> arthur.barton.de Git - netdata.git/blob - charts.d/example.chart.sh
Merge pull request #567 from paulfantom/master
[netdata.git] / charts.d / example.chart.sh
1 #!/bin/bash
2
3 # if this chart is called X.chart.sh, then all functions and global variables
4 # must start with X_
5
6 # _update_every is a special variable - it holds the number of seconds
7 # between the calls of the _update() function
8 example_update_every=
9
10 # the priority is used to sort the charts on the dashboard
11 # 1 = the first chart
12 example_priority=150000
13
14 # to enable this chart, you have to set this to 12345
15 # (just a demonstration for something that needs to be checked)
16 example_magic_number=
17
18 # _check is called once, to find out if this chart should be enabled or not
19 example_check() {
20         # this should return:
21         #  - 0 to enable the chart
22         #  - 1 to disable the chart
23
24         [ "${example_magic_number}" != "12345" ] && return 1
25         return 0
26 }
27
28 # _create is called once, to create the charts
29 example_create() {
30         # create the chart with 3 dimensions
31         cat <<EOF
32 CHART example.random '' "Random Numbers Stacked Chart" "% of random numbers" random random stacked $((example_priority)) $example_update_every
33 DIMENSION random1 '' percentage-of-absolute-row 1 1
34 DIMENSION random2 '' percentage-of-absolute-row 1 1
35 DIMENSION random3 '' percentage-of-absolute-row 1 1
36 CHART example.random2 '' "A random number" "random number" random random area $((example_priority + 1)) $example_update_every
37 DIMENSION random '' absolute 1 1
38 EOF
39
40         return 0
41 }
42
43 # _update is called continiously, to collect the values
44 example_last=0
45 example_count=0
46 example_update() {
47         local value1 value2 value3 value4 mode
48
49         # the first argument to this function is the microseconds since last update
50         # pass this parameter to the BEGIN statement (see bellow).
51
52         # do all the work to collect / calculate the values
53         # for each dimension
54         # remember: KEEP IT SIMPLE AND SHORT
55
56         value1=$RANDOM
57         value2=$RANDOM
58         value3=$RANDOM
59         value4=$((8192 + (RANDOM * 16383 / 32767) ))
60
61         if [ $example_count -gt 0 ]
62                 then
63                 example_count=$((example_count - 1))
64
65                 [ $example_last -gt 16383 ] && value4=$((example_last + (RANDOM * ( (32767 - example_last) / 2) / 32767)))
66                 [ $example_last -le 16383 ] && value4=$((example_last - (RANDOM * (example_last / 2) / 32767)))
67         else
68                 example_count=$((1 + (RANDOM * 5 / 32767) ))
69
70                 [ $example_last -gt 16383 -a $value4 -gt 16383 ] && value4=$((value4 - 16383))
71                 [ $example_last -le 16383 -a $value4 -lt 16383 ] && value4=$((value4 + 16383))
72         fi
73         example_last=$value4
74
75         # write the result of the work.
76         cat <<VALUESEOF
77 BEGIN example.random $1
78 SET random1 = $value1
79 SET random2 = $value2
80 SET random3 = $value3
81 END
82 BEGIN example.random2 $1
83 SET random = $value4
84 END
85 VALUESEOF
86         # echo >&2 "example_count = $example_count value = $value4"
87
88         return 0
89 }