@cryptotaxi247 / netdata-1 / commits / 93921bbb7

charts.d.plugin gives a chart per charts.d plugin for its execution time

Costa Tsaousis (ktsaou) committed Nov 19, 2015 at 22:10 UTC 93921bbb7cd15c3f3a4e4f52386cf3611eadd8d0
1 file changed +13 -3
plugins.d/charts.d.plugin
+13 -3
@@ -420,7 +420,7 @@ fi
420 declare -A charts_last_update=() charts_min_dt=()
421 global_update() {
422 local exit_after=$((restart_timeout / update_every)) \
423 - c=0 dt \
423 + c=0 dt ret exec_start_ms exec_end_ms \
424 chart now_charts=() next_charts=($run_charts)
425
426 # return the current time in ms in $now_ms
@@ -431,6 +431,9 @@ global_update() {
431 eval "charts_min_dt[$chart]=\$$chart$suffix_update_every"
432 test -z "${charts_min_dt[$chart]}" && charts_min_dt[$charts]=$update_every
433 charts_last_update[$chart]=$((now_ms - (charts_min_dt[$chart] * 1000) ))
434 +
435 + echo "CHART netdata.plugin_$chart '' 'Execution time for $chart plugin' 'milliseconds / run' netdata netdata area 90000 ${charts_min_dt[$chart]}"
436 + echo "DIMENSION run_time 'run time' absolute 1 1"
437 done
438
439 # the main loop
@@ -444,7 +447,6 @@ global_update() {
447 do
448 # return the current time in ms in $now_ms
449 current_time_ms
447 -
450 dt=$(( (now_ms - charts_last_update[$chart]) * 1000 ))
451 if [ $dt -ge $(( charts_min_dt[$chart] * 1000000 )) ]
452 then
@@ -454,13 +456,21 @@ global_update() {
456 # so that netdata calibrates to current time
457 test $c -eq 1 && dt=
458
459 + exec_start_ms=$now_ms
460 $chart$charts_update $dt
458 - if [ $? -eq 0 ]
461 + ret=$?
462 + current_time_ms; exec_end_ms=$now_ms
463 +
464 + echo "BEGIN netdata.plugin_$chart $dt"
465 + if [ $ret -eq 0 ]
466 then
467 + echo "SET run_time = $(( exec_end_ms - exec_start_ms ))"
468 next_charts+=($chart)
469 else
470 + echo "SET run_time = $(( (exec_end_ms - exec_start_ms) * -1 ))"
471 echo >&2 "$PROGRAM_NAME: chart '$chart' update() function reports failure. Disabling it."
472 fi
473 + echo "END"
474 else
475 next_charts+=($chart)
476 fi