From d849dd5f0aa2150fda857a923fcc109096b5ee91 Mon Sep 17 00:00:00 2001 From: "Costa Tsaousis (ktsaou)" Date: Wed, 21 Dec 2016 00:37:23 +0200 Subject: [PATCH] tc-qos-helper.sh optimization to avoid forks; added support for reading class names from /etc/iproute2/tc_cls; fixes #837 --- plugins.d/loopsleepms.sh.inc | 2 +- plugins.d/tc-qos-helper.sh | 78 +++++++++++++++++++++++++++++------- 2 files changed, 64 insertions(+), 16 deletions(-) diff --git a/plugins.d/loopsleepms.sh.inc b/plugins.d/loopsleepms.sh.inc index 4f2e0235..ef3db192 100644 --- a/plugins.d/loopsleepms.sh.inc +++ b/plugins.d/loopsleepms.sh.inc @@ -139,7 +139,7 @@ loopsleepms() { # calculate ms since last run [ ${LOOPSLEEPMS_LASTRUN} -gt 0 ] && \ - LOOPSLEEPMS_LASTWORK=$((now_ms - LOOPSLEEPMS_LASTRUN - LOOPSLEEPMS_LASTSLEEP)) + LOOPSLEEPMS_LASTWORK=$((now_ms - LOOPSLEEPMS_LASTRUN - LOOPSLEEPMS_LASTSLEEP + current_time_ms_accuracy)) # echo "# last loop's work took $LOOPSLEEPMS_LASTWORK ms" # remember this run diff --git a/plugins.d/tc-qos-helper.sh b/plugins.d/tc-qos-helper.sh index 7e1e92cf..94d0a62f 100755 --- a/plugins.d/tc-qos-helper.sh +++ b/plugins.d/tc-qos-helper.sh @@ -5,8 +5,8 @@ # (C) 2016 Costa Tsaousis # GPL v3+ # -# This script is a helper to allow netdata collect tc data -# parsing tc output has been implemented in C, inside netdata +# This script is a helper to allow netdata collect tc data. +# tc output parsing has been implemented in C, inside netdata # This script allows setting names to dimensions. export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin" @@ -90,21 +90,34 @@ if [ -z "${tc}" -o ! -x "${tc}" ] fatal "cannot find command 'tc' in this system." fi -devices= +tc_devices= fix_names= setclassname() { echo "SETCLASSNAME $3 $2" } -show_tc() { - local x="${1}" interface_dev interface_classes interface_classes_monitor +show_tc_cls() { + local x="${1}" - echo "BEGIN ${x}" - ${tc} -s class show dev ${x} + if [ -f /etc/iproute2/tc_cls ] + then + local classid name rest + while read classid name rest + do + [ -z "${classid}" -o -z "${name}" -o "${classid}" = "#" -o "${name}" = "#" -o "${classid:0:1}" = "#" -o "${name:0:1}" = "#" ] && continue + setclassname "" "${name}" "${classid}" + done