3 # -----------------------------------------------------------------------------
9 myconfig="$confd/charts.d.conf"
10 minimum_update_frequency=1
11 update_every=1 # this is overwritten by the command line
13 # -----------------------------------------------------------------------------
28 if [ -f "$chartsd/$1.chart.sh" ]
31 chart_only="`echo $1.chart.sh | sed "s/\.chart\.sh$//g"`"
36 if [ -f "$chartsd/$1" ]
39 chart_only="`echo $1 | sed "s/\.chart\.sh$//g"`"
47 chart_only="`basename "$1" | sed "s/\.chart\.sh$//g"`"
62 echo >&2 "Cannot understand parameter $1. Aborting."
68 # -----------------------------------------------------------------------------
69 # load my configuration
76 echo >&2 "charts.d: cannot load $myconfig"
83 # -----------------------------------------------------------------------------
86 # netdata passes the requested update frequency as the first argument
87 update_every=$(( update_every + 1 - 1)) # makes sure it is a number
88 test $update_every -eq 0 && update_every=1 # if it is zero, make it 1
90 # check the charts.d directory
91 if [ ! -d "$chartsd" ]
93 echo >&2 "charts.d: cannot find charts directory '$chartsd'"
98 # -----------------------------------------------------------------------------
101 # default sleep function
105 # if found and included, this file overwrites loopsleepms()
106 # with a high resolution timer function for precise looping.
107 . "`dirname $0`/loopsleepms.sh.inc"
110 # -----------------------------------------------------------------------------
111 # charts check functions
115 ls *.chart.sh | sed "s/\.chart\.sh$//g"
118 all_enabled_charts() {
121 # find all enabled charts
123 for x in `all_charts`
126 if [ "$enabled" = "yes" ]
128 local charts="$charts $x"
130 echo >&2 "charts.d: chart '$x' is NOT enabled. Add a line with $x=yes in $myconfig to enable it."
137 # check the enabled charts
138 local check=`cat "$chartsd/$x.chart.sh" | sed "s/^ \+//g" | grep "^${x}_check()"`
141 echo >&2 "charts.d: chart '$x' does not seem to have a ${x}_check() function. Disabling it."
145 local create=`cat "$chartsd/$x.chart.sh" | sed "s/^ \+//g" | grep "^${x}_create()"`
148 echo >&2 "charts.d: chart '$x' does not seem to have a ${x}_create() function. Disabling it."
152 local update=`cat "$chartsd/$x.chart.sh" | sed "s/^ \+//g" | grep "^${x}_update()"`
155 echo >&2 "charts.d: chart '$x' does not seem to have a ${x}_update() function. Disabling it."
160 if [ -f "$confd/$x.conf" ]
162 if [ ! -z "`cat "$confd/$x.conf" | sed "s/^ \+//g" | grep -v "^$" | grep -v "^#" | grep -v "^${x}_"`" ]
164 echo >&2 "charts.d: chart's $x config $confd/$x.conf should only have lines starting with ${x}_ . Disabling it."
169 "$pluginsd/charts.d.dryrun-helper.sh" "$x" "$chartsd/$x.chart.sh" "$confd/$x.conf" >/dev/null
172 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."
176 local charts2="$charts2 $x"
183 # -----------------------------------------------------------------------------
187 for x in `all_enabled_charts`
189 . "$chartsd/$x.chart.sh"
191 if [ -f "$confd/$x.conf" ]
199 active_charts="$active_charts $x"
201 echo >&2 "charts.d: chart '$x' check() function reports failure."
206 # -----------------------------------------------------------------------------
209 # if we only need a specific chart, remove all the others
211 if [ ! -z "$chart_only" ]
215 for x in $active_charts
217 if [ "$x" = "$chart_only" ]
223 active_charts="$check_charts"
226 # stop if we just need a pre-check
230 echo "Will run the charts: $active_charts"
235 # -----------------------------------------------------------------------------
239 for x in $active_charts
244 run_charts="$run_charts $x"
246 echo >&2 "charts.d: chart '$x' create() function reports failure."
251 # -----------------------------------------------------------------------------
255 now_charts=$run_charts
263 run_charts="$run_charts $x"
265 echo >&2 "charts.d: chart '$x' update() function reports failure. Disabling it."
269 # wait the time you are required to
270 loopsleepms $debug_time $update_every