tc-qos-helper.sh follows the same rules with charts.d.plugin and it now supports custom configuration in /etc/netdata/tc-qos-helper.conf
Costa Tsaousis committed
Jul 2, 2016 at 00:07 UTC
6bf02f5f2f378d3bed501549748f731586b08f23
1 file changed
+49
-31
plugins.d/tc-qos-helper.sh
+49
-31
@@ -2,6 +2,31 @@
2
3
export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
4
5
+PROGRAM_FILE="$0"
6
+PROGRAM_NAME="$(basename $0)"
7
+PROGRAM_NAME="${PROGRAM_NAME/.plugin}"
8
+
9
+plugins_dir="${NETDATA_PLUGINS_DIR}"
10
+[ -z "$plugins_dir" ] && plugins_dir="$( dirname $PROGRAM_FILE )"
11
+
12
+config_dir=${NETDATA_CONFIG_DIR-/etc/netdata}
13
+tc="$(which tc 2>/dev/null)"
14
+fireqos_run_dir="/var/run/fireqos"
15
+qos_get_class_names_every=120
16
+qos_exit_every=3600
17
+
18
+# check if we have a valid number for interval
19
+t=${1}
20
+update_every=$((t))
21
+[ $((update_every)) -lt 1 ] && update_every=${NETDATA_UPDATE_EVERY}
22
+[ $((update_every)) -lt 1 ] && update_every=1
23
+
24
+# allow the user to override our defaults
25
+if [ -f "${config_dir}/tc-qos-helper.conf" ]
26
+ then
27
+ source "${config_dir}/tc-qos-helper.conf"
28
+fi
29
+
30
# default time function
31
now_ms=
32
current_time_ms() {
@@ -17,18 +42,11 @@ loopsleepms() {
42
43
# if found and included, this file overwrites loopsleepms()
44
# with a high resolution timer function for precise looping.
20
-. "$NETDATA_PLUGINS_DIR/loopsleepms.sh.inc"
21
-
22
-# check if we have a valid number for interval
23
-t=$1
24
-sleep_time=$((t))
25
-[ $((sleep_time)) -lt 1 ] && $NETDATA_UPDATE_EVERY
26
-[ $((sleep_time)) -lt 1 ] && sleep_time=1
45
+. "${plugins_dir}/loopsleepms.sh.inc"
46
28
-tc_cmd="$(which tc)"
29
-if [ -z "$tc_cmd" ]
47
+if [ -z "${tc}" -o ! -x "${tc}" ]
48
then
31
- echo >&2 "tc: Cannot find a 'tc' command in this system."
49
+ echo >&2 "${PROGRAM_NAME}: Cannot find command 'tc' in this system."
50
exit 1
51
fi
52
@@ -40,44 +58,44 @@ setclassname() {
58
}
59
60
show_tc() {
43
- local x="$1"
61
+ local x="${1}"
62
45
- echo "BEGIN $x"
46
- $tc_cmd -s class show dev $x
63
+ echo "BEGIN ${x}"
64
+ ${tc} -s class show dev ${x}
65
66
# check FireQOS names for classes
49
- if [ ! -z "$fix_names" -a -f /var/run/fireqos/ifaces/$x ]
67
+ if [ ! -z "${fix_names}" -a -f "${fireqos_run_dir}/ifaces/${x}" ]
68
then
51
- name="$(cat /var/run/fireqos/ifaces/$x)"
52
- echo "SETDEVICENAME $name"
69
+ name="$(cat "${fireqos_run_dir}/ifaces/${x}")"
70
+ echo "SETDEVICENAME ${name}"
71
72
interface_classes=
73
interface_classes_monitor=
56
- . /var/run/fireqos/$name.conf
57
- for n in $interface_classes_monitor
74
+ source "${fireqos_run_dir}/${name}.conf"
75
+ for n in ${interface_classes_monitor}
76
do
59
- setclassname $(echo $n | tr '|' ' ')
77
+ setclassname $(echo ${n} | tr '|' ' ')
78
done
61
- echo "SETDEVICEGROUP $interface_dev"
79
+ echo "SETDEVICEGROUP ${interface_dev}"
80
fi
63
- echo "END $x"
81
+ echo "END ${x}"
82
}
83
84
all_devices() {
85
cat /proc/net/dev | grep ":" | cut -d ':' -f 1 | while read dev
86
do
69
- l=$($tc_cmd class show dev $dev | wc -l)
70
- [ $l -ne 0 ] && echo $dev
87
+ l=$(${tc} class show dev ${dev} | wc -l)
88
+ [ $l -ne 0 ] && echo ${dev}
89
done
90
}
91
92
# update devices and class names
93
# once every 2 minutes
76
-names_every=$((120 / sleep_time))
94
+names_every=$((qos_get_class_names_every / update_every))
95
96
# exit this script every hour
97
# it will be restarted automatically
80
-exit_after=$((3600 / sleep_time))
98
+exit_after=$((qos_exit_every / update_every))
99
100
c=0
101
gc=0
@@ -87,21 +105,21 @@ do
105
c=$((c + 1))
106
gc=$((gc + 1))
107
90
- if [ $c -le 1 -o $c -ge $names_every ]
108
+ if [ ${c} -le 1 -o ${c} -ge ${names_every} ]
109
then
110
c=1
111
fix_names="YES"
112
devices="$( all_devices )"
113
fi
114
97
- for d in $devices
115
+ for d in ${devices}
116
do
99
- show_tc $d
117
+ show_tc ${d}
118
done
119
102
- echo "WORKTIME $LOOPSLEEPMS_LASTWORK"
120
+ echo "WORKTIME ${LOOPSLEEPMS_LASTWORK}"
121
104
- loopsleepms $sleep_time
122
+ loopsleepms ${update_every}
123
106
- [ $gc -gt $exit_after ] && exit 0
124
+ [ ${gc} -gt ${exit_after} ] && exit 0
125
done