3 # -----------------------------------------------------------------------------
6 pause_method="sleep" # use either "suspend" or "sleep"
7 # DO NOT USE SUSPEND - LINUX WILL SUSPEND NETDATA TOO
8 # THE WHOLE PROCESS GROUP - NOT JUST THE SHELL
13 myconfig="$confd/charts.d.conf"
14 minimum_update_frequency=1
15 update_every=1 # this is overwritten by the command line
17 # -----------------------------------------------------------------------------
32 if [ "$1" = "debug" -o "$1" = "all" ]
39 if [ -f "$chartsd/$1.chart.sh" ]
42 chart_only="`echo $1.chart.sh | sed "s/\.chart\.sh$//g"`"
47 if [ -f "$chartsd/$1" ]
50 chart_only="`echo $1 | sed "s/\.chart\.sh$//g"`"
58 chart_only="`basename "$1" | sed "s/\.chart\.sh$//g"`"
73 echo >&2 "Cannot understand parameter $1. Aborting."
79 # -----------------------------------------------------------------------------
80 # load my configuration
87 echo >&2 "charts.d: cannot load $myconfig"
93 if [ "$pause_method" = "suspend" ]
95 # enable bash job control
96 # this is required for suspend to work
100 # -----------------------------------------------------------------------------
103 # netdata passes the requested update frequency as the first argument
104 update_every=$(( update_every + 1 - 1)) # makes sure it is a number
105 test $update_every -eq 0 && update_every=1 # if it is zero, make it 1
107 # check the charts.d directory
108 if [ ! -d "$chartsd" ]
110 echo >&2 "charts.d: cannot find charts directory '$chartsd'"
115 # -----------------------------------------------------------------------------
118 # default sleep function
122 # if found and included, this file overwrites loopsleepms()
123 # with a high resolution timer function for precise looping.
124 . "`dirname $0`/loopsleepms.sh.inc"
127 # -----------------------------------------------------------------------------
128 # charts check functions
132 ls *.chart.sh | sed "s/\.chart\.sh$//g"
135 all_enabled_charts() {
138 # find all enabled charts
140 for x in `all_charts`
143 if [ "$enabled" = "yes" ]
145 local charts="$charts $x"
147 echo >&2 "charts.d: chart '$x' is NOT enabled. Add a line with $x=yes in $myconfig to enable it."
154 # check the enabled charts
155 local check=`cat "$chartsd/$x.chart.sh" | sed "s/^ \+//g" | grep "^${x}_check()"`
158 echo >&2 "charts.d: chart '$x' does not seem to have a ${x}_check() function. Disabling it."
162 local create=`cat "$chartsd/$x.chart.sh" | sed "s/^ \+//g" | grep "^${x}_create()"`
165 echo >&2 "charts.d: chart '$x' does not seem to have a ${x}_create() function. Disabling it."
169 local update=`cat "$chartsd/$x.chart.sh" | sed "s/^ \+//g" | grep "^${x}_update()"`
172 echo >&2 "charts.d: chart '$x' does not seem to have a ${x}_update() function. Disabling it."
177 if [ -f "$confd/$x.conf" ]
179 if [ ! -z "`cat "$confd/$x.conf" | sed "s/^ \+//g" | grep -v "^$" | grep -v "^#" | grep -v "^${x}_"`" ]
181 echo >&2 "charts.d: chart's $x config $confd/$x.conf should only have lines starting with ${x}_ . Disabling it."
186 "$pluginsd/charts.d.dryrun-helper.sh" "$x" "$chartsd/$x.chart.sh" "$confd/$x.conf" >/dev/null
189 echo >&2 "charts.d: chart's $x did not pass the dry run check. This means it uses global variables not starting with $x. Disabling it."
193 local charts2="$charts2 $x"
200 # -----------------------------------------------------------------------------
204 for x in `all_enabled_charts`
206 . "$chartsd/$x.chart.sh"
208 if [ -f "$confd/$x.conf" ]
216 active_charts="$active_charts $x"
218 echo >&2 "charts.d: chart '$x' check() function reports failure."
223 # -----------------------------------------------------------------------------
226 # enable work time reporting
228 test $debug -eq 1 && debug_time=tellwork
230 # if we only need a specific chart, remove all the others
231 if [ ! -z "$chart_only" ]
234 for x in $active_charts
236 if [ "$x" = "$chart_only" ]
242 active_charts="$check_charts"
245 # stop if we just need a pre-check
249 echo "Will run the charts: $active_charts"
254 # -----------------------------------------------------------------------------
258 for x in $active_charts
263 run_charts="$run_charts $x"
265 echo >&2 "charts.d: chart '$x' create() function reports failure."
270 # -----------------------------------------------------------------------------
274 now_charts=$run_charts
282 run_charts="$run_charts $x"
284 echo >&2 "charts.d: chart '$x' update() function reports failure. Disabling it."
288 if [ "$pause_method" = "suspend" ]
290 echo "STOPPING_WAKE_ME_UP_PLEASE"
291 suspend || ( echo >&2 "suspend returned error $?, falling back to sleep."; loopsleepms $debug_time $update_every )
293 # wait the time you are required to
294 loopsleepms $debug_time $update_every