]> arthur.barton.de Git - netdata.git/blob - charts.d/example.chart.sh
updated charts.d readme and makefile
[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 example_priority=150000
11
12 # _check is called once, to find out if this chart should be enabled or not
13 example_check() {
14         # this should return:
15         #  - 0 to enable the chart
16         #  - 1 to disable the chart
17
18         return 0
19 }
20
21 # _create is called once, to create the charts
22 example_create() {
23         # create the chart with 3 dimensions
24         cat <<EOF
25 CHART example.random '' "Random Numbers Stacked Chart" "% of random numbers" random random stacked $((example_priority)) $example_update_every
26 DIMENSION random1 '' percentage-of-absolute-row 1 1
27 DIMENSION random2 '' percentage-of-absolute-row 1 1
28 DIMENSION random3 '' percentage-of-absolute-row 1 1
29 CHART example.random2 '' "A random number" "random number" random random area $((example_priority + 1)) $example_update_every
30 DIMENSION random '' absolute 1 1
31 EOF
32
33         return 0
34 }
35
36 # _update is called continiously, to collect the values
37 example_last=0
38 example_count=0
39 example_update() {
40         local value1 value2 value3 value4 mode
41
42         # the first argument to this function is the microseconds since last update
43         # pass this parameter to the BEGIN statement (see bellow).
44
45         # do all the work to collect / calculate the values
46         # for each dimension
47         # remember: KEEP IT SIMPLE AND SHORT
48
49         value1=$RANDOM
50         value2=$RANDOM
51         value3=$RANDOM
52         value4=$((8192 + (RANDOM * 16383 / 32767) ))
53
54         if [ $example_count -gt 0 ]
55                 then
56                 example_count=$((example_count - 1))
57
58                 [ $example_last -gt 16383 ] && value4=$((example_last + (RANDOM * ( (32767 - example_last) / 2) / 32767)))
59                 [ $example_last -le 16383 ] && value4=$((example_last - (RANDOM * (example_last / 2) / 32767)))
60         else
61                 example_count=$((1 + (RANDOM * 5 / 32767) ))
62
63                 [ $example_last -gt 16383 -a $value4 -gt 16383 ] && value4=$((value4 - 16383))
64                 [ $example_last -le 16383 -a $value4 -lt 16383 ] && value4=$((value4 + 16383))
65         fi
66         example_last=$value4
67
68         # write the result of the work.
69         cat <<VALUESEOF
70 BEGIN example.random $1
71 SET random1 = $value1
72 SET random2 = $value2
73 SET random3 = $value3
74 END
75 BEGIN example.random2 $1
76 SET random = $value4
77 END
78 VALUESEOF
79         # echo >&2 "example_count = $example_count value = $value4"
80
81         return 0
82 }