3 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
6 PROGRAM_NAME="$(basename $0)"
7 PROGRAM_NAME="${PROGRAM_NAME/.plugin}"
9 plugins_dir="${NETDATA_PLUGINS_DIR}"
10 [ -z "$plugins_dir" ] && plugins_dir="$( dirname $PROGRAM_FILE )"
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
18 # check if we have a valid number for interval
21 [ $((update_every)) -lt 1 ] && update_every=${NETDATA_UPDATE_EVERY}
22 [ $((update_every)) -lt 1 ] && update_every=1
24 # allow the user to override our defaults
25 if [ -f "${config_dir}/tc-qos-helper.conf" ]
27 source "${config_dir}/tc-qos-helper.conf"
30 # default time function
33 now_ms="$(date +'%s')000"
36 # default sleep function
37 LOOPSLEEPMS_LASTWORK=0
39 [ "$1" = "tellwork" ] && shift
43 # if found and included, this file overwrites loopsleepms()
44 # with a high resolution timer function for precise looping.
45 . "${plugins_dir}/loopsleepms.sh.inc"
47 if [ -z "${tc}" -o ! -x "${tc}" ]
49 echo >&2 "${PROGRAM_NAME}: Cannot find command 'tc' in this system."
57 echo "SETCLASSNAME $3 $2"
61 local x="${1}" interface_dev interface_classes interface_classes_monitor
64 ${tc} -s class show dev ${x}
66 # check FireQOS names for classes
67 if [ ! -z "${fix_names}" -a -f "${fireqos_run_dir}/ifaces/${x}" ]
69 name="$(<"${fireqos_run_dir}/ifaces/${x}")"
70 echo "SETDEVICENAME ${name}"
74 interface_classes_monitor=
75 source "${fireqos_run_dir}/${name}.conf"
76 for n in ${interface_classes_monitor}
78 setclassname ${n//|/ }
80 [ ! -z "${interface_dev}" ] && echo "SETDEVICEGROUP ${interface_dev}"
86 cat /proc/net/dev | grep ":" | cut -d ':' -f 1 | while read dev
88 l=$(${tc} class show dev ${dev} | wc -l)
89 [ $l -ne 0 ] && echo ${dev}
93 # update devices and class names
94 # once every 2 minutes
95 names_every=$((qos_get_class_names_every / update_every))
97 # exit this script every hour
98 # it will be restarted automatically
99 exit_after=$((qos_exit_every / update_every))
109 if [ ${c} -le 1 -o ${c} -ge ${names_every} ]
113 devices="$( all_devices )"
121 echo "WORKTIME ${LOOPSLEEPMS_LASTWORK}"
123 loopsleepms ${update_every}
125 [ ${gc} -gt ${exit_after} ] && exit 0