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 [ "$1" = "debug" -o "$1" = "all" ]
35 if [ -f "$chartsd/$1.chart.sh" ]
38 chart_only="`echo $1.chart.sh | sed "s/\.chart\.sh$//g"`"
43 if [ -f "$chartsd/$1" ]
46 chart_only="`echo $1 | sed "s/\.chart\.sh$//g"`"
54 chart_only="`basename "$1" | sed "s/\.chart\.sh$//g"`"
69 echo >&2 "Cannot understand parameter $1. Aborting."
75 # -----------------------------------------------------------------------------
76 # load my configuration
83 echo >&2 "charts.d: cannot load $myconfig"
90 # -----------------------------------------------------------------------------
93 # netdata passes the requested update frequency as the first argument
94 update_every=$(( update_every + 1 - 1)) # makes sure it is a number
95 test $update_every -eq 0 && update_every=1 # if it is zero, make it 1
97 # check the charts.d directory
98 if [ ! -d "$chartsd" ]
100 echo >&2 "charts.d: cannot find charts directory '$chartsd'"
105 # -----------------------------------------------------------------------------
108 # default sleep function
112 # if found and included, this file overwrites loopsleepms()
113 # with a high resolution timer function for precise looping.
114 . "`dirname $0`/loopsleepms.sh.inc"
117 # -----------------------------------------------------------------------------
118 # charts check functions
122 ls *.chart.sh | sed "s/\.chart\.sh$//g"
125 all_enabled_charts() {
128 # find all enabled charts
130 for x in `all_charts`
133 if [ "$enabled" = "yes" ]
135 local charts="$charts $x"
137 echo >&2 "charts.d: chart '$x' is NOT enabled. Add a line with $x=yes in $myconfig to enable it."
144 # check the enabled charts
145 local check=`cat "$chartsd/$x.chart.sh" | sed "s/^ \+//g" | grep "^${x}_check()"`
148 echo >&2 "charts.d: chart '$x' does not seem to have a ${x}_check() function. Disabling it."
152 local create=`cat "$chartsd/$x.chart.sh" | sed "s/^ \+//g" | grep "^${x}_create()"`
155 echo >&2 "charts.d: chart '$x' does not seem to have a ${x}_create() function. Disabling it."
159 local update=`cat "$chartsd/$x.chart.sh" | sed "s/^ \+//g" | grep "^${x}_update()"`
162 echo >&2 "charts.d: chart '$x' does not seem to have a ${x}_update() function. Disabling it."
167 if [ -f "$confd/$x.conf" ]
169 if [ ! -z "`cat "$confd/$x.conf" | sed "s/^ \+//g" | grep -v "^$" | grep -v "^#" | grep -v "^${x}_"`" ]
171 echo >&2 "charts.d: chart's $x config $confd/$x.conf should only have lines starting with ${x}_ . Disabling it."
176 "$pluginsd/charts.d.dryrun-helper.sh" "$x" "$chartsd/$x.chart.sh" "$confd/$x.conf" >/dev/null
179 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."
183 local charts2="$charts2 $x"
190 # -----------------------------------------------------------------------------
194 for x in `all_enabled_charts`
196 . "$chartsd/$x.chart.sh"
198 if [ -f "$confd/$x.conf" ]
206 active_charts="$active_charts $x"
208 echo >&2 "charts.d: chart '$x' check() function reports failure."
213 # -----------------------------------------------------------------------------
216 # enable work time reporting
218 test $debug -eq 1 && debug_time=tellwork
220 # if we only need a specific chart, remove all the others
221 if [ ! -z "$chart_only" ]
224 for x in $active_charts
226 if [ "$x" = "$chart_only" ]
232 active_charts="$check_charts"
235 # stop if we just need a pre-check
239 echo "Will run the charts: $active_charts"
244 # -----------------------------------------------------------------------------
248 for x in $active_charts
253 run_charts="$run_charts $x"
255 echo >&2 "charts.d: chart '$x' create() function reports failure."
260 # -----------------------------------------------------------------------------
264 now_charts=$run_charts
272 run_charts="$run_charts $x"
274 echo >&2 "charts.d: chart '$x' update() function reports failure. Disabling it."
278 # wait the time you are required to
279 loopsleepms $debug_time $update_every