summaryrefslogtreecommitdiffstats
path: root/plugins.d/tc-qos-helper.sh
diff options
context:
space:
mode:
authorFederico Ceratto <federico.ceratto@gmail.com>2016-03-30 21:40:42 +0000
committerFederico Ceratto <federico.ceratto@gmail.com>2016-03-30 21:40:42 +0000
commit9ce153ce7167c11adba8ac225edc7a707e97c6eb (patch)
tree9f6e849cce2dcc7e5b4e9e6252c843dc2d0787a2 /plugins.d/tc-qos-helper.sh
downloadnetdata-9ce153ce7167c11adba8ac225edc7a707e97c6eb.tar.xz
netdata-9ce153ce7167c11adba8ac225edc7a707e97c6eb.zip
Imported Upstream version 1.0.0upstream/1.0.0
Diffstat (limited to '')
-rwxr-xr-xplugins.d/tc-qos-helper.sh105
1 files changed, 105 insertions, 0 deletions
diff --git a/plugins.d/tc-qos-helper.sh b/plugins.d/tc-qos-helper.sh
new file mode 100755
index 000000000..86f717122
--- /dev/null
+++ b/plugins.d/tc-qos-helper.sh
@@ -0,0 +1,105 @@
+#!/bin/bash
+
+# default time function
+now_ms=
+current_time_ms() {
+ now_ms="$(date +'%s')000"
+}
+
+# default sleep function
+LOOPSLEEPMS_LASTWORK=0
+loopsleepms() {
+ [ "$1" = "tellwork" ] && shift
+ sleep $1
+}
+
+# if found and included, this file overwrites loopsleepms()
+# with a high resolution timer function for precise looping.
+. "$NETDATA_PLUGINS_DIR/loopsleepms.sh.inc"
+
+# check if we have a valid number for interval
+t=$1
+sleep_time=$((t))
+[ $((sleep_time)) -lt 1 ] && $NETDATA_UPDATE_EVERY
+[ $((sleep_time)) -lt 1 ] && sleep_time=1
+
+tc_cmd="$(which tc)"
+if [ -z "$tc_cmd" ]
+ then
+ echo >&2 "tc: Cannot find a 'tc' command in this system."
+ exit 1
+fi
+
+devices=
+fix_names=
+
+setclassname() {
+ echo "SETCLASSNAME $3 $2"
+}
+
+show_tc() {
+ local x="$1"
+
+ echo "BEGIN $x"
+ $tc_cmd -s class show dev $x
+
+ # check FireQOS names for classes
+ if [ ! -z "$fix_names" -a -f /var/run/fireqos/ifaces/$x ]
+ then
+ name="$(cat /var/run/fireqos/ifaces/$x)"
+ echo "SETDEVICENAME $name"
+
+ interface_classes=
+ interface_classes_monitor=
+ . /var/run/fireqos/$name.conf
+ for n in $interface_classes_monitor
+ do
+ setclassname $(echo $n | tr '|' ' ')
+ done
+ echo "SETDEVICEGROUP $interface_dev"
+ fi
+ echo "END $x"
+}
+
+all_devices() {
+ cat /proc/net/dev | grep ":" | cut -d ':' -f 1 | while read dev
+ do
+ l=$($tc_cmd class show dev $dev | wc -l)
+ [ $l -ne 0 ] && echo $dev
+ done
+}
+
+# update devices and class names
+# once every 2 minutes
+names_every=$((120 / sleep_time))
+
+# exit this script every hour
+# it will be restarted automatically
+exit_after=$((3600 / sleep_time))
+
+c=0
+gc=0
+while [ 1 ]
+do
+ fix_names=
+ c=$((c + 1))
+ gc=$((gc + 1))
+
+ if [ $c -le 1 -o $c -ge $names_every ]
+ then
+ c=1
+ fix_names="YES"
+ devices="$( all_devices )"
+ fi
+
+ for d in $devices
+ do
+ show_tc $d
+ done
+
+ echo "WORKTIME $LOOPSLEEPMS_LASTWORK"
+
+ loopsleepms $sleep_time
+
+ [ $gc -gt $exit_after ] && exit 0
+done