@cryptotaxi247 / netdata-1 / commits / 9a6ad9c58

fixed charts.d.plugin to get directories from netdata server; netdata now exports a set of variables for use by the plugins; optimized charts.d.plugin a lot

Costa Tsaousis (ktsaou) committed Nov 17, 2015 at 01:15 UTC 9a6ad9c580cc062c06a76dc643a9bcafc74f0561
5 files changed +172 -116
netdata.start
+9 -20
@@ -13,10 +13,11 @@ then
13 echo >&2 "Cleaning a possibly old compilation ..."
14 make clean || exit 1
15
16 - echo >&2 "Compiling netdata ..."
17 - make || exit 1
16 fi
17
18 +echo >&2 "Compiling netdata ..."
19 +make || exit 1
20 +
21 if [ -z "${netdata}" -o src/netdata -nt "${netdata}" ]
22 then
23 echo >&2 "Installing netdata ..."
@@ -31,15 +32,6 @@ fi
32
33 netdata=$(which netdata)
34
34 -base="`dirname "$0"`"
35 -
36 -if [ ! -d "${base}" ]
37 -then
38 - echo >&2 "Cannot find my home directory '${base}'."
39 - exit 1
40 -fi
41 -cd "${base}" || exit 1
42 -
35
36 # -----------------------------------------------------------------------------
37 # load options from the configuration file
@@ -53,7 +45,7 @@ config_option() {
45
46 if [ -s "/etc/netdata/netdata.conf" ]
47 then
56 - line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "conf.d/netdata.conf" | head -n 1 )"
48 + line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "/etc/netdata/netdata.conf" | head -n 1 )"
49 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
50 fi
51
@@ -74,10 +66,10 @@ defport=19999
66 NETDATA_PORT="$( config_option "port" ${defport} )"
67
68 # directories
77 -NETDATA_CACHE_DIR="$( config_option "database directory" "/var/cache/netdata" )"
69 +NETDATA_CACHE_DIR="$( config_option "cache directory" "/var/cache/netdata" )"
70 NETDATA_WEB_DIR="$( config_option "web files directory" "/usr/share/netdata/web" )"
79 -NETDATA_LOG_DIR="log"
80 -NETDATA_CONF_DIR="conf.d"
71 +NETDATA_LOG_DIR="$( config_option "log directory" "/var/log/netdata" )"
72 +NETDATA_CONF_DIR="$( config_option "config directory" "/etc/netdata" )"
73
74
75 # -----------------------------------------------------------------------------
@@ -88,7 +80,8 @@ for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NE
80 do
81 if [ ! -d "${x}" ]
82 then
91 - mkdir "${x}" || exit 1
83 + echo >&2 "Creating directory '${x}'"
84 + mkdir -p "${x}" || exit 1
85 fi
86 chown -R "${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
87 chmod 0775 "${x}" "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
@@ -123,10 +116,6 @@ echo >&2
116 # -----------------------------------------------------------------------------
117 # run netdata
118
126 -# avoid extended stat(/etc/localtime)
127 -# http://stackoverflow.com/questions/4554271/how-to-avoid-excessive-stat-etc-localtime-calls-in-strftime-on-linux
128 -export TZ=":/etc/localtime"
129 -
119 echo >&2 "Starting netdata..."
120 netdata "${@}"
121
plugins.d/charts.d.plugin
+111 -63
@@ -1,18 +1,56 @@
1 #!/bin/bash
2
3 +PROGRAM_FILE="$0"
4 +PROGRAM_NAME="charts.d"
5 +echo >&2 "$PROGRAM_NAME: started from '$PROGRAM_FILE' with options: $*"
6 +
7 +if [ $(( ${BASH_VERSINFO[0]} )) -lt 4 ]
8 +then
9 + echo >&2
10 + echo >&2 "$PROGRAM_NAME: ERROR"
11 + echo >&2 "BASH version 4 or later is required."
12 + echo >&2 "You are running version: ${BASH_VERSION}"
13 + echo >&2 "Please upgrade."
14 + echo >&2
15 + exit 1
16 +fi
17 +
18 +# check a few commands
19 +require_cmd() {
20 + which "$1" >/dev/null
21 + if [ $? -ne 0 ]
22 + then
23 + echo >&2 "$PROGRAM_NAME: ERROR: Command '$1' is not found in the system path."
24 + return 1
25 + fi
26 + return 0
27 +}
28 +
29 +require_cmd date || exit 1
30 +require_cmd sed || exit 1
31 +require_cmd basename || exit 1
32 +require_cmd dirname || exit 1
33 +require_cmd cat || exit 1
34 +require_cmd grep || exit 1
35 +require_cmd mktemp || exit 1
36 +
37 # -----------------------------------------------------------------------------
38 # insternal defaults
39 +# netdata exposes a few environment variables for us
40
41 pause_method="sleep" # use either "suspend" or "sleep"
42 # DO NOT USE SUSPEND - LINUX WILL SUSPEND NETDATA TOO
43 # THE WHOLE PROCESS GROUP - NOT JUST THE SHELL
44
10 -pluginsd="plugins.d"
11 -confd="conf.d"
12 -chartsd="charts.d"
45 +pluginsd="${NETDATA_PLUGINS_DIR}"
46 +[ -z "$pluginsd" ] && pluginsd="$( dirname $PROGRAM_FILE )"
47 +
48 +confd="${NETDATA_CONFIG_DIR-/etc/netdata}"
49 +chartsd="$pluginsd/../charts.d"
50 myconfig="$confd/charts.d.conf"
14 -minimum_update_frequency=1
15 -update_every=1 # this is overwritten by the command line
51 +
52 +minimum_update_frequency="${NETDATA_UPDATE_EVERY-1}"
53 +update_every=${minimum_update_frequency} # this will be overwritten by the command line
54
55 # work around for non BASH shells
56 charts_create="_create"
@@ -58,21 +96,13 @@ do
96 continue
97 fi
98
61 - if [ -f "$1" ]
62 - then
63 - debug=1
64 - chart_only="$( basename "$1" | sed "s/\.chart\.sh$//g" )"
65 - shift
66 - continue
67 - fi
68 -
99 # number check
100 n="$1"
71 - x=$((n + 1 - 1))
101 + x=$(( n ))
102 if [ "$x" = "$n" ]
103 then
74 - update_every=$x
104 shift
105 + update_every=$x
106 continue
107 fi
108
@@ -90,7 +120,7 @@ if [ -f "$myconfig" ]
120 . "$myconfig"
121 if [ $? -ne 0 ]
122 then
93 - echo >&2 "charts.d: cannot load $myconfig"
123 + echo >&2 "$PROGRAM_NAME: cannot load $myconfig"
124 echo "DISABLE"
125 exit 1
126 fi
@@ -113,7 +143,7 @@ test $update_every -eq 0 && update_every=1 # if it is zero, make it 1
143 # check the charts.d directory
144 if [ ! -d "$chartsd" ]
145 then
116 - echo >&2 "charts.d: cannot find charts directory '$chartsd'"
146 + echo >&2 "$PROGRAM_NAME: cannot find charts directory '$chartsd'"
147 echo "DISABLE"
148 fi
149
@@ -125,9 +155,16 @@ fi
155 loopsleepms() {
156 sleep $1
157 }
158 +
159 +now_ms=
160 +current_time_ms() {
161 + now_ms="$(date +'%s')000"
162 +}
163 +
164 # if found and included, this file overwrites loopsleepms()
129 -# with a high resolution timer function for precise looping.
130 -. "$( dirname $0 )/loopsleepms.sh.inc"
165 +# and current_time_ms() with a high resolution timer function
166 +# for precise looping.
167 +. "$pluginsd/loopsleepms.sh.inc"
168
169
170 # -----------------------------------------------------------------------------
@@ -135,6 +172,8 @@ loopsleepms() {
172
173 all_charts() {
174 cd "$chartsd"
175 + [ $? -ne 0 ] && echo >&2 "$PROGRAM_NAME: Cannot cd to $chartsd" && return 1
176 +
177 ls *.chart.sh | sed "s/\.chart\.sh$//g"
178 }
179
@@ -148,9 +187,10 @@ all_enabled_charts() {
187 eval "enabled=\$$chart"
188 if [ "$enabled" = "yes" ]
189 then
190 + [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: '$chart' is enabled."
191 local charts="$charts $chart"
192 else
153 - echo >&2 "charts.d: chart '$chart' is NOT enabled. Add a line with $chart=yes in $myconfig to enable it."
193 + echo >&2 "$PROGRAM_NAME: '$chart' is NOT enabled. Add a line with $chart=yes in $myconfig to enable it."
194 fi
195 done
196
@@ -161,38 +201,38 @@ all_enabled_charts() {
201 local check="$( cat "$chartsd/$chart.chart.sh" | sed "s/^ \+//g" | grep "^$chart$charts_check()" )"
202 if [ -z "$check" ]
203 then
164 - echo >&2 "charts.d: chart '$chart' does not seem to have a $chart$charts_check() function. Disabling it."
204 + echo >&2 "$PROGRAM_NAME: chart '$chart' does not seem to have a $chart$charts_check() function. Disabling it."
205 continue
206 fi
207
208 local create="$( cat "$chartsd/$chart.chart.sh" | sed "s/^ \+//g" | grep "^$chart$charts_create()" )"
209 if [ -z "$create" ]
210 then
171 - echo >&2 "charts.d: chart '$chart' does not seem to have a $chart$charts_create() function. Disabling it."
211 + echo >&2 "$PROGRAM_NAME: chart '$chart' does not seem to have a $chart$charts_create() function. Disabling it."
212 continue
213 fi
214
215 local update="$( cat "$chartsd/$chart.chart.sh" | sed "s/^ \+//g" | grep "^$chart$charts_update()" )"
216 if [ -z "$update" ]
217 then
178 - echo >&2 "charts.d: chart '$chart' does not seem to have a $chart$charts_update() function. Disabling it."
218 + echo >&2 "$PROGRAM_NAME: chart '$chart' does not seem to have a $chart$charts_update() function. Disabling it."
219 continue
220 fi
221
222 # check its config
183 - if [ -f "$confd/$chart.conf" ]
184 - then
185 - if [ ! -z "$( cat "$confd/$chart.conf" | sed "s/^ \+//g" | grep -v "^$" | grep -v "^#" | grep -v "^$chart$charts_undescore" )" ]
186 - then
187 - echo >&2 "charts.d: chart's $chart config $confd/$chart.conf should only have lines starting with $chart$charts_undescore . Disabling it."
188 - continue
189 - fi
190 - fi
223 + #if [ -f "$confd/$chart.conf" ]
224 + #then
225 + # if [ ! -z "$( cat "$confd/$chart.conf" | sed "s/^ \+//g" | grep -v "^$" | grep -v "^#" | grep -v "^$chart$charts_undescore" )" ]
226 + # then
227 + # echo >&2 "$PROGRAM_NAME: chart's $chart config $confd/$chart.conf should only have lines starting with $chart$charts_undescore . Disabling it."
228 + # continue
229 + # fi
230 + #fi
231
232 "$pluginsd/charts.d.dryrun-helper.sh" "$chart" "$chartsd/$chart.chart.sh" "$confd/$chart.conf" >/dev/null
233 if [ $? -ne 0 ]
234 then
195 - echo >&2 "charts.d: chart's $chart did not pass the dry run check. This means it uses global variables not starting with $chart. Disabling it."
235 + echo >&2 "$PROGRAM_NAME: chart's $chart did not pass the dry run check. This means it uses global variables not starting with $chart. Disabling it."
236 continue
237 fi
238
@@ -200,6 +240,7 @@ all_enabled_charts() {
240 done
241
242 echo $charts2
243 + [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: enabled charts: $charts2"
244 }
245
246
@@ -210,10 +251,12 @@ suffix_update_every="_update_every"
251 active_charts=
252 for chart in $( all_enabled_charts )
253 do
254 + [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: loading chart: '$chartsd/$chart.chart.sh'"
255 . "$chartsd/$chart.chart.sh"
256
257 if [ -f "$confd/$chart.conf" ]
258 then
259 + [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: loading chart options: '$confd/$chart.conf'"
260 . "$confd/$chart.conf"
261 fi
262
@@ -227,11 +270,13 @@ do
270 $chart$charts_check
271 if [ $? -eq 0 ]
272 then
273 + [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: '$chart' activated"
274 active_charts="$active_charts $chart"
275 else
232 - echo >&2 "charts.d: chart '$chart' check() function reports failure."
276 + echo >&2 "$PROGRAM_NAME: chart '$chart' check() function reports failure."
277 fi
278 done
279 +[ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: activated charts: $active_charts"
280
281
282 # -----------------------------------------------------------------------------
@@ -242,8 +287,9 @@ debug_time=
287 test $debug -eq 1 && debug_time=tellwork
288
289 # if we only need a specific chart, remove all the others
245 -if [ ! -z "$chart_only" ]
290 +if [ ! -z "${chart_only}" ]
291 then
292 + [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: requested to run only for: '${chart_only}'"
293 check_charts=
294 for chart in $active_charts
295 do
@@ -255,12 +301,13 @@ then
301 done
302 active_charts="$check_charts"
303 fi
304 +[ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: activated charts: $active_charts"
305
306 # stop if we just need a pre-check
307 if [ $check -eq 1 ]
308 then
262 - echo "CHECK RESULT"
263 - echo "Will run the charts: $active_charts"
309 + echo >&2 "CHECK RESULT"
310 + echo >&2 "Will run the charts: $active_charts"
311 exit 0
312 fi
313
@@ -269,9 +316,10 @@ fi
316
317 TMP_DIR=
318 chartsd_cleanup() {
319 + cd /tmp
320 if [ ! -z "$TMP_DIR" -a -d "$TMP_DIR" ]
321 then
274 - echo >&2 "charts.d: cleaning up temporary directory $TMP_DIR ..."
322 + [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: cleaning up temporary directory $TMP_DIR ..."
323 rm -rf "$TMP_DIR"
324 fi
325 exit 0
@@ -287,6 +335,8 @@ else
335 TMP_DIR="$( mktemp -d /tmp/.netdata-charts.d-XXXXXXXXXX )"
336 fi
337
338 +cd "$TMP_DIR" || exit 1
339 +
340 # -----------------------------------------------------------------------------
341 # library functions
342
@@ -304,77 +354,75 @@ fixid() {
354 run_charts=
355 for chart in $active_charts
356 do
357 + [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: Calling '$chart$charts_create()'..."
358 $chart$charts_create
359 if [ $? -eq 0 ]
360 then
361 run_charts="$run_charts $chart"
362 + [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: '$chart' has initialized."
363 else
312 - echo >&2 "charts.d: chart '$chart' create() function reports failure."
364 + echo >&2 "$PROGRAM_NAME: chart '$chart' function '$chart$charts_create()' reports failure."
365 fi
366 done
367 +[ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: run_charts='$run_charts'"
368
369
370 # -----------------------------------------------------------------------------
371 # update dimensions
372
373 +declare -A charts_last_update=() charts_min_dt=()
374 global_update() {
321 - local exit_after=$((3600 / update_every))
375 + local exit_after=$((3600 / update_every)) \
376 + c=0 dt \
377 + chart now_charts=() next_charts=($run_charts)
378
379 # return the current time in ms in $now_ms
380 current_time_ms
381
326 - local chart=
327 - for chart in $now_charts
382 + for chart in $run_charts
383 do
329 - eval "local last_update_$chart=\$((now_ms - ($chart$suffix_update_every * 1000) ))"
384 + eval "charts_min_dt[$chart]=\$$chart$suffix_update_every"
385 + test -z "${charts_min_dt[$chart]}" && charts_min_dt[$charts]=$update_every
386 + charts_last_update[$chart]=$((now_ms - (charts_min_dt[$chart] * 1000) ))
387 done
388
389 # the main loop
333 - local c=0
390 while [ 1 ]
391 do
336 - local c=$((c + 1))
337 - local now_charts="$run_charts"
338 - local run_charts=
392 + c=$((c + 1))
393 + now_charts=("${next_charts[@]}")
394 + next_charts=()
395
340 - local chart=
341 - for chart in $now_charts
396 + for chart in "${now_charts[@]}"
397 do
398 # return the current time in ms in $now_ms
399 current_time_ms
400
346 - eval "local chart_min_dt=\$$chart$suffix_update_every"
347 - test -z "$chart_min_dt" && local chart_min_dt=$update_every
348 - local chart_min_dt=$((chart_min_dt * 1000000))
349 -
350 - eval "local last=\$last_update_$chart"
351 - test -z "$last" && local last=$((now_ms - (chart_min_dt / 1000) ))
352 -
353 - local dt=$(( (now_ms - last) * 1000 ))
354 - if [ $dt -ge $chart_min_dt ]
401 + dt=$(( (now_ms - charts_last_update[$chart]) * 1000 ))
402 + if [ $dt -ge $(( charts_min_dt[$chart] * 1000000 )) ]
403 then
356 - eval "last_update_$chart=$now_ms"
404 + charts_last_update[$chart]=$now_ms
405
406 # the first call should not give a duration
407 # so that netdata calibrates to current time
360 - test $c -eq 1 && local dt=
408 + test $c -eq 1 && dt=
409
410 $chart$charts_update $dt
411 if [ $? -eq 0 ]
412 then
365 - run_charts="$run_charts $chart"
413 + next_charts+=($chart)
414 else
367 - echo >&2 "charts.d: chart '$chart' update() function reports failure. Disabling it."
415 + echo >&2 "$PROGRAM_NAME: chart '$chart' update() function reports failure. Disabling it."
416 fi
417 else
370 - run_charts="$run_charts $chart"
418 + next_charts+=($chart)
419 fi
420 done
421
422 if [ "$pause_method" = "suspend" ]
423 then
424 echo "STOPPING_WAKE_ME_UP_PLEASE"
377 - suspend || ( echo >&2 "suspend returned error $?, falling back to sleep."; loopsleepms $debug_time $update_every )
425 + suspend || ( echo >&2 "$PROGRAM_NAME: suspend returned error $?, falling back to sleep."; loopsleepms $debug_time $update_every )
426 else
427 # wait the time you are required to
428 loopsleepms $debug_time $update_every
plugins.d/loopsleepms.sh.inc
+25 -30
@@ -1,50 +1,47 @@
1 +#!/bin/bash
2 +
3 # this function is used to sleep a fraction of a second
4 # it calculates the difference between every time is called
5 # and tries to align the sleep time to give you exactly the
6 # loop you need.
7
6 -LOOPSLEEPMS_HIGHRES=2
8 +LOOPSLEEP_DATE="$(which date)"
9 +if [ -z "$LOOPSLEEP_DATE" ]
10 + then
11 + echo >&2 "$0: ERROR: Cannot find the command 'date' in the system path."
12 + exit 1
13 +fi
14 +
15 LOOPSLEEPMS_LASTRUN=0
16 LOOPSLEEPMS_LASTSLEEP=0
17 LOOPSLEEPMS_LASTWORK=0
18
11 -check_high_res() {
12 - LOOPSLEEPMS_HIGHRES=1
13 - test `date +%N` = "%N" && LOOPSLEEPMS_HIGHRES=0
14 -}
19 +LOOPSLEEPMS_HIGHRES=1
20 +test "$($LOOPSLEEP_DATE +%N)" = "%N" && LOOPSLEEPMS_HIGHRES=0
21
22 now_ms=
23 current_time_ms() {
18 - # check if high resolution timer is supported
19 - test $LOOPSLEEPMS_HIGHRES -eq 2 && check_high_res
20 -
24 # if high resolution is not supported
25 # just sleep the time requested, in seconds
26 if [ $LOOPSLEEPMS_HIGHRES -eq 0 ]
27 then
25 - local s="`date +'%s'`"
26 - local m="000"
28 + now_ms="$($LOOPSLEEP_DATE +'%s')000"
29 else
28 - local d="`date +'%s.%N'`"
29 - local s="`echo $d | cut -d '.' -f 1`"
30 - local m="`echo $d | cut -d '.' -f 2 | cut -b 1-3`"
30 + now_ms="$(( $( $LOOPSLEEP_DATE +'%s * 1000 + %-N / 1000000' ) ))"
31 fi
32 - now_ms="$s$m"
32 }
33
34 loopsleepms() {
36 - tellwork=0
37 - if [ "$1" = "tellwork" ]
35 + local tellwork=0 t="$1" s m now mstosleep
36 +
37 + if [ "$t" = "tellwork" ]
38 then
39 - local tellwork=1
39 + tellwork=1
40 shift
41 + t="$1"
42 fi
43
43 - # the time in seconds to wait, as the first argument
44 - local t=$1
45 -
46 - # check if high resolution timer is supported
47 - test $LOOPSLEEPMS_HIGHRES -eq 2 && check_high_res
44 + # $t = the time in seconds to wait
45
46 # if high resolution is not supported
47 # just sleep the time requested, in seconds
@@ -54,11 +51,9 @@ loopsleepms() {
51 return
52 fi
53
57 - # get the current time
58 - local d="`date +'%s.%N'`"
59 - local s="`echo $d | cut -d '.' -f 1`"
60 - local m="`echo $d | cut -d '.' -f 2 | cut -b 1-3`"
61 - local now="$s$m" # milliseconds since epoch (1-1-1970)
54 + # get the current time, in ms
55 + # milliseconds since epoch (1-1-1970)
56 + now="$(( $( $LOOPSLEEP_DATE +'%s * 1000 + %-N / 1000000' ) ))"
57
58 # calculate required sleep in ms
59 t=$((t * 1000))
@@ -74,14 +69,14 @@ loopsleepms() {
69 test $tellwork -eq 1 && echo >&2 " >>> PERFORMANCE >>> WORK TOOK $LOOPSLEEPMS_LASTWORK ms ( $((LOOPSLEEPMS_LASTWORK * 100 / 1000)).$((LOOPSLEEPMS_LASTWORK % 10))% cpu )"
70
71 # calculate ms to sleep
77 - local mstosleep=$((t - LOOPSLEEPMS_LASTWORK))
72 + mstosleep=$((t - LOOPSLEEPMS_LASTWORK))
73 # echo "# mstosleep is $mstosleep ms"
74
75 # if we are too slow, sleep some time
76 test $mstosleep -lt $((t / 2)) && mstosleep=$((t / 2))
77
83 - local s=$((mstosleep / 1000))
84 - local m=$((mstosleep - (s * 1000)))
78 + s=$((mstosleep / 1000))
79 + m=$((mstosleep - (s * 1000)))
80
81 # echo "# sleeping $s.$m"
82 # echo
src/main.c
+24
@@ -235,6 +235,20 @@ int main(int argc, char **argv)
235
236 if(!config_loaded) load_config(NULL, 0);
237
238 + // prepare configuration environment variables for the plugins
239 + setenv("NETDATA_CONFIG_DIR" , config_get("global", "config directory" , CONFIG_DIR) , 1);
240 + setenv("NETDATA_PLUGINS_DIR", config_get("global", "plugins directory" , PLUGINS_DIR), 1);
241 + setenv("NETDATA_WEB_DIR" , config_get("global", "web files directory", WEB_DIR) , 1);
242 + setenv("NETDATA_CACHE_DIR" , config_get("global", "cache directory" , CACHE_DIR) , 1);
243 + setenv("NETDATA_LOG_DIR" , config_get("global", "log directory" , LOG_DIR) , 1);
244 +
245 + // avoid extended to stat(/etc/localtime)
246 + // http://stackoverflow.com/questions/4554271/how-to-avoid-excessive-stat-etc-localtime-calls-in-strftime-on-linux
247 + setenv("TZ", ":/etc/localtime", 0);
248 +
249 + // cd to /tmp to avoid any plugins writing files at random places
250 + if(chdir("/tmp")) fprintf(stderr, "netdata: ERROR: Cannot cd to /tmp: %s", strerror(errno));
251 +
252 char *input_log_file = NULL;
253 char *output_log_file = NULL;
254 char *error_log_file = NULL;
@@ -247,6 +261,8 @@ int main(int argc, char **argv)
261
262 sprintf(buffer, "0x%08llx", 0ULL);
263 char *flags = config_get("global", "debug flags", buffer);
264 + setenv("NETDATA_DEBUG_FLAGS", flags, 1);
265 +
266 debug_flags = strtoull(flags, NULL, 0);
267 debug(D_OPTIONS, "Debug flags set to '0x%8llx'.", debug_flags);
268
@@ -259,6 +275,7 @@ int main(int argc, char **argv)
275 // --------------------------------------------------------------------
276
277 global_host_prefix = config_get("global", "host access prefix", "");
278 + setenv("NETDATA_HOST_PREFIX", global_host_prefix, 1);
279
280 // --------------------------------------------------------------------
281
@@ -332,6 +349,13 @@ int main(int argc, char **argv)
349 }
350 else debug(D_OPTIONS, "update timer set to %d.", rrd_update_every);
351
352 + // let the plugins know the min update_every
353 + {
354 + char buffer[50];
355 + snprintf(buffer, 50, "%d", rrd_update_every);
356 + setenv("NETDATA_UPDATE_EVERY", buffer, 1);
357 + }
358 +
359 // --------------------------------------------------------------------
360
361 for (i = 0; static_threads[i].name != NULL ; i++) {
src/rrd.c
+3 -3
@@ -281,14 +281,14 @@ char *rrdset_cache_dir(const char *id)
281 char *ret = NULL;
282
283 static char *cache_dir = NULL;
284 - if(!cache_dir) cache_dir = config_get("global", "database directory", CACHE_DIR);
284 + if(!cache_dir) cache_dir = config_get("global", "cache directory", CACHE_DIR);
285
286 char b[FILENAME_MAX + 1];
287 char n[FILENAME_MAX + 1];
288 rrdset_strncpy_name(b, id, FILENAME_MAX);
289
290 snprintf(n, FILENAME_MAX, "%s/%s", cache_dir, b);
291 - ret = config_get(id, "database directory", n);
291 + ret = config_get(id, "cache directory", n);
292
293 if(rrd_memory_mode == RRD_MEMORY_MODE_MAP || rrd_memory_mode == RRD_MEMORY_MODE_SAVE) {
294 int r = mkdir(ret, 0775);
@@ -964,7 +964,7 @@ unsigned long long rrdset_done(RRDSET *st)
964 // if the new is smaller than the old (an overflow, or reset), set the old equal to the new
965 // to reset the calculation (it will give zero as the calculation for this second)
966 if(unlikely(rd->last_collected_value > rd->collected_value)) {
967 - info("%s.%s: Detect RESET or OVERFLOW. Last collected value = " COLLECTED_NUMBER_FORMAT ", current = " COLLECTED_NUMBER_FORMAT
967 + debug(D_RRD_STATS, "%s.%s: Detect RESET or OVERFLOW. Last collected value = " COLLECTED_NUMBER_FORMAT ", current = " COLLECTED_NUMBER_FORMAT
968 , st->name, rd->name
969 , rd->last_collected_value
970 , rd->collected_value);