]> arthur.barton.de Git - netdata.git/blob - charts.d/example.chart.sh
Now there are 2 kinds of plugins:
[netdata.git] / charts.d / example.chart.sh
1 #!/bin/sh
2
3 # report our PID back to netdata
4 # this is required for netdata to kill this process when it exits
5 echo "MYPID $$"
6
7 # default sleep function
8 loopsleepms() {
9         sleep $1
10 }
11 # if found and included, this file overwrites loopsleepms()
12 # with a high resolution timer function for precise looping.
13 . "`dirname $0`/loopsleepms.sh.inc"
14
15 # netdata passes the requested update frequency as the first argument
16 update_every=$1
17 update_every=$(( update_every + 1 - 1)) # makes sure it is a number
18 test $update_every -eq 0 && update_every=1 # if it is zero, make it 1
19
20
21 # create the chart with 3 dimensions
22 cat <<EOF
23 CHART example.load '' "System Load Average" "load" load load line 500 $update_every
24 DIMENSION load1 '1 min' absolute 1 100
25 DIMENSION load5 '5 mins' absolute 1 100
26 DIMENSION load15 '15 mins' absolute 1 100
27
28 CHART example.random '' "Random Numbers Stacked Chart" "% of random numbers" random random stacked 5000 $update_every
29 DIMENSION random1 '' percentage-of-absolute-row 1 1
30 DIMENSION random2 '' percentage-of-absolute-row 1 1
31 DIMENSION random3 '' percentage-of-absolute-row 1 1
32 EOF
33
34 # You can create more charts if you like.
35 # Just add more chart definitions.
36
37 # work forever
38 while [ 1 ]
39 do
40         # do all the work to collect / calculate the values
41         # for each dimension
42
43         # here we parse the system average load
44         # it is decimal (with 2 decimal digits), so we remove the dot and
45         # at the definition we have divisor = 100, to have the graph show the right value
46         loadavg="`cat /proc/loadavg | sed -e "s/\.//g"`"
47         load1=`echo $loadavg | cut -d ' ' -f 1`
48         load5=`echo $loadavg | cut -d ' ' -f 2`
49         load15=`echo $loadavg | cut -d ' ' -f 3`
50
51         value1=$RANDOM
52         value2=$RANDOM
53         value3=$RANDOM
54
55         # write the result of the work.
56         cat <<VALUESEOF
57 BEGIN example.load
58 SET load1 = $load1
59 SET load5 = $load5
60 SET load15 = $load15
61 END
62
63 BEGIN example.random
64 SET random1 = $value1
65 SET random2 = $value2
66 SET random3 = $value3
67 END
68 VALUESEOF
69
70         # if you have more charts, add BEGIN->END statements here
71
72         # wait the time you are required to
73         loopsleepms $update_every
74 done