X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=charts.d%2Fexample.chart.sh;h=86fde490134e077d0d84e9bcbe40ffe818659623;hb=b060bae83cc36fdc4f14120228e4c9b0d1ec42e8;hp=aa1005d11aec536a75b4d6c96b7e0a56d38e85d6;hpb=71b72e4f59b129ced0a1d15e5ce3b21370edfbbd;p=netdata.git diff --git a/charts.d/example.chart.sh b/charts.d/example.chart.sh old mode 100755 new mode 100644 index aa1005d1..86fde490 --- a/charts.d/example.chart.sh +++ b/charts.d/example.chart.sh @@ -1,4 +1,10 @@ -#!/bin/sh +# no need for shebang - this file is loaded from charts.d.plugin + +# netdata +# real-time performance and health monitoring, done right! +# (C) 2016 Costa Tsaousis +# GPL v3+ +# # if this chart is called X.chart.sh, then all functions and global variables # must start with X_ @@ -7,12 +13,71 @@ # between the calls of the _update() function example_update_every= +# the priority is used to sort the charts on the dashboard +# 1 = the first chart +example_priority=150000 + +# to enable this chart, you have to set this to 12345 +# (just a demonstration for something that needs to be checked) +example_magic_number= + +# global variables to store our collected data +# remember: they need to start with the module name example_ +example_value1= +example_value2= +example_value3= +example_value4= +example_last=0 +example_count=0 + +example_get() { + # do all the work to collect / calculate the values + # for each dimension + # + # Remember: + # 1. KEEP IT SIMPLE AND SHORT + # 2. AVOID FORKS (avoid piping commands) + # 3. AVOID CALLING TOO MANY EXTERNAL PROGRAMS + # 4. USE LOCAL VARIABLES (global variables may overlap with other modules) + + example_value1=$RANDOM + example_value2=$RANDOM + example_value3=$RANDOM + example_value4=$((8192 + (RANDOM * 16383 / 32767) )) + + if [ $example_count -gt 0 ] + then + example_count=$((example_count - 1)) + + [ $example_last -gt 16383 ] && example_value4=$((example_last + (RANDOM * ( (32767 - example_last) / 2) / 32767))) + [ $example_last -le 16383 ] && example_value4=$((example_last - (RANDOM * (example_last / 2) / 32767))) + else + example_count=$((1 + (RANDOM * 5 / 32767) )) + + [ $example_last -gt 16383 -a $example_value4 -gt 16383 ] && example_value4=$((example_value4 - 16383)) + [ $example_last -le 16383 -a $example_value4 -lt 16383 ] && example_value4=$((example_value4 + 16383)) + fi + example_last=$example_value4 + + # this should return: + # - 0 to send the data to netdata + # - 1 to report a failure to collect the data + + return 0 +} + # _check is called once, to find out if this chart should be enabled or not example_check() { # this should return: # - 0 to enable the chart # - 1 to disable the chart + # check something + [ "${example_magic_number}" != "12345" ] && error "manual configuration required: you have to set example_magic_number=$example_magic_number in example.conf to start example chart." && return 1 + + # check that we can collect data + example_get || return 1 + return 0 } @@ -20,10 +85,12 @@ example_check() { example_create() { # create the chart with 3 dimensions cat <