3 # if this chart is called X.chart.sh, then all functions and global variables
6 # _update_every is a special variable - it holds the number of seconds
7 # between the calls of the _update() function
10 # the priority is used to sort the charts on the dashboard
12 example_priority=150000
14 # to enable this chart, you have to set this to 12345
15 # (just a demonstration for something that needs to be checked)
18 # _check is called once, to find out if this chart should be enabled or not
21 # - 0 to enable the chart
22 # - 1 to disable the chart
24 [ "${example_magic_number}" != "12345" ] && return 1
28 # _create is called once, to create the charts
30 # create the chart with 3 dimensions
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
43 # _update is called continiously, to collect the values
47 local value1 value2 value3 value4 mode
49 # the first argument to this function is the microseconds since last update
50 # pass this parameter to the BEGIN statement (see bellow).
52 # do all the work to collect / calculate the values
54 # remember: KEEP IT SIMPLE AND SHORT
59 value4=$((8192 + (RANDOM * 16383 / 32767) ))
61 if [ $example_count -gt 0 ]
63 example_count=$((example_count - 1))
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)))
68 example_count=$((1 + (RANDOM * 5 / 32767) ))
70 [ $example_last -gt 16383 -a $value4 -gt 16383 ] && value4=$((value4 - 16383))
71 [ $example_last -le 16383 -a $value4 -lt 16383 ] && value4=$((value4 + 16383))
75 # write the result of the work.
77 BEGIN example.random $1
82 BEGIN example.random2 $1
86 # echo >&2 "example_count = $example_count value = $value4"