]> arthur.barton.de Git - netdata.git/commitdiff
moved tc-all.sh to charts.d/
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 2 May 2014 08:39:06 +0000 (11:39 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 2 May 2014 08:39:06 +0000 (11:39 +0300)
charts.d/tc-qos-collector.sh [new file with mode: 0755]
netdata.c

diff --git a/charts.d/tc-qos-collector.sh b/charts.d/tc-qos-collector.sh
new file mode 100755 (executable)
index 0000000..3398c68
--- /dev/null
@@ -0,0 +1,94 @@
+#!/bin/sh
+
+# let netdata know our PID
+# this is required to kill us when it exits
+echo "MYPID $$"
+
+# default sleep function
+loopsleepms() {
+       sleep $1
+}
+# if found and included, this file overwrites loopsleepms()
+# with a high resolution timer function for precise looping.
+. "`dirname $0`/loopsleepms.sh.inc"
+
+# check if we have a valid number for interval
+t=$1
+sleep_time=$(( t + 1 - 1 ))
+if [ "$sleep_time" -eq 0 ]
+       then
+       sleep_time=1
+fi
+
+devices=
+fix_names=
+
+setclassname() {
+       echo "SETCLASSNAME $3 $2"
+}
+
+show_tc() {
+       local x="$1"
+
+       echo "BEGIN $x"
+       
+       /sbin/tc -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=
+               . /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=`/sbin/tc 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
+
+       [ $gc -gt $exit_after ] && exit 0
+       
+       loopsleepms $sleep_time
+done
index 410db2b9a097f282edc708864d5803662d95b954..3d2cf41eb2565ae99783808910c67111c6f512fc 100644 (file)
--- a/netdata.c
+++ b/netdata.c
@@ -5153,7 +5153,7 @@ void *proc_main(void *ptr)
 
 // ----------------------------------------------------------------------------
 // /sbin/tc processor
-// this requires the script tc-all.sh
+// this requires the script charts.d/tc-qos-collector.sh
 
 #define PIPE_READ 0
 #define PIPE_WRITE 1
@@ -5354,7 +5354,7 @@ void *tc_main(void *ptr)
                struct tc_device *device = NULL;
                struct tc_class *class = NULL;
 
-               snprintf(buffer, TC_LINE_MAX, "exec %s %d", config_get("plugin:tc", "script to run to get tc values", "./tc-all.sh"), update_every);
+               snprintf(buffer, TC_LINE_MAX, "exec %s %d", config_get("plugin:tc", "script to run to get tc values", "charts.d/tc-qos-collector.sh"), update_every);
                fp = popen(buffer, "r");
                if(!fp) {
                        error("Cannot popen(\"%s\", \"r\").", buffer);