4 # real-time performance and health monitoring, done right!
5 # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
8 # This script is a helper to allow netdata collect tc data
9 # parsing tc output has been implemented in C, inside netdata
10 # This script allows setting names to dimensions.
12 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
16 PROGRAM_NAME="$(basename $0)"
17 PROGRAM_NAME="${PROGRAM_NAME/.plugin}"
19 # -----------------------------------------------------------------------------
22 date "+%Y-%m-%d %H:%M:%S"
29 echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
52 [ $debug -eq 1 ] && log DEBUG "${@}"
55 # -----------------------------------------------------------------------------
57 plugins_dir="${NETDATA_PLUGINS_DIR}"
58 [ -z "$plugins_dir" ] && plugins_dir="$( dirname $PROGRAM_FILE )"
60 config_dir=${NETDATA_CONFIG_DIR-/etc/netdata}
61 tc="$(which tc 2>/dev/null || command -v tc 2>/dev/null)"
62 fireqos_run_dir="/var/run/fireqos"
63 qos_get_class_names_every=120
66 # check if we have a valid number for interval
69 [ $((update_every)) -lt 1 ] && update_every=${NETDATA_UPDATE_EVERY}
70 [ $((update_every)) -lt 1 ] && update_every=1
72 # allow the user to override our defaults
73 if [ -f "${config_dir}/tc-qos-helper.conf" ]
75 source "${config_dir}/tc-qos-helper.conf"
78 # default sleep function
79 LOOPSLEEPMS_LASTWORK=0
84 # if found and included, this file overwrites loopsleepms()
85 # with a high resolution timer function for precise looping.
86 . "${plugins_dir}/loopsleepms.sh.inc"
88 if [ -z "${tc}" -o ! -x "${tc}" ]
90 fatal "cannot find command 'tc' in this system."
97 echo "SETCLASSNAME $3 $2"
101 local x="${1}" interface_dev interface_classes interface_classes_monitor
104 ${tc} -s class show dev ${x}
106 # check FireQOS names for classes
107 if [ ! -z "${fix_names}" -a -f "${fireqos_run_dir}/ifaces/${x}" ]
109 name="$(<"${fireqos_run_dir}/ifaces/${x}")"
110 echo "SETDEVICENAME ${name}"
114 interface_classes_monitor=
115 source "${fireqos_run_dir}/${name}.conf"
116 for n in ${interface_classes_monitor}
118 setclassname ${n//|/ }
120 [ ! -z "${interface_dev}" ] && echo "SETDEVICEGROUP ${interface_dev}"
126 cat /proc/net/dev | grep ":" | cut -d ':' -f 1 | while read dev
128 l=$(${tc} class show dev ${dev} | wc -l)
129 [ $l -ne 0 ] && echo ${dev}
133 # update devices and class names
134 # once every 2 minutes
135 names_every=$((qos_get_class_names_every / update_every))
137 # exit this script every hour
138 # it will be restarted automatically
139 exit_after=$((qos_exit_every / update_every))
149 if [ ${c} -le 1 -o ${c} -ge ${names_every} ]
153 devices="$( all_devices )"
161 echo "WORKTIME ${LOOPSLEEPMS_LASTWORK}"
163 loopsleepms ${update_every}
165 [ ${gc} -gt ${exit_after} ] && exit 0