From 8a7b72f7cd1ccd547a03eb4243294e741d661d3f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 8 Feb 2019 08:30:37 +0100 Subject: Adding upstream version 1.12.0. Signed-off-by: Daniel Baumann --- collectors/tc.plugin/tc-qos-helper.sh.in | 309 +++++++++++++++---------------- 1 file changed, 145 insertions(+), 164 deletions(-) (limited to 'collectors/tc.plugin/tc-qos-helper.sh.in') diff --git a/collectors/tc.plugin/tc-qos-helper.sh.in b/collectors/tc.plugin/tc-qos-helper.sh.in index a15eab899..01353be45 100755 --- a/collectors/tc.plugin/tc-qos-helper.sh.in +++ b/collectors/tc.plugin/tc-qos-helper.sh.in @@ -12,46 +12,44 @@ export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin" export LC_ALL=C - # ----------------------------------------------------------------------------- # logging functions -PROGRAM_FILE="$0" -PROGRAM_NAME="$(basename $0)" -PROGRAM_NAME="${PROGRAM_NAME/.plugin}" +PROGRAM_NAME="$(basename "$0")" +PROGRAM_NAME="${PROGRAM_NAME/.plugin/}" logdate() { - date "+%Y-%m-%d %H:%M:%S" + date "+%Y-%m-%d %H:%M:%S" } log() { - local status="${1}" - shift + local status="${1}" + shift - echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}" + echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}" } warning() { - log WARNING "${@}" + log WARNING "${@}" } error() { - log ERROR "${@}" + log ERROR "${@}" } info() { - log INFO "${@}" + log INFO "${@}" } fatal() { - log FATAL "${@}" - exit 1 + log FATAL "${@}" + exit 1 } debug=0 debug() { - [ $debug -eq 1 ] && log DEBUG "${@}" + [ $debug -eq 1 ] && log DEBUG "${@}" } # ----------------------------------------------------------------------------- @@ -60,59 +58,55 @@ debug() { # the default fireqos_run_dir="/var/run/fireqos" -function realdir { - local r="$1" - local t=$(readlink "$r") +function realdir() { + local r + local t + r="$1" + t="$(readlink "$r")" - while [ "$t" ] - do - r=$(cd $(dirname "$r") && cd $(dirname "$t") && pwd -P)/$(basename "$t") - t=$(readlink "$r") - done + while [ "$t" ]; do + r=$(cd "$(dirname "$r")" && cd "$(dirname "$t")" && pwd -P)/$(basename "$t") + t=$(readlink "$r") + done - dirname "$r" + dirname "$r" } -if [ ! -d "${fireqos_run_dir}" ] - then - - # the fireqos executable - we will use it to find its config - fireqos="$(which fireqos 2>/dev/null || command -v fireqos 2>/dev/null)" +if [ ! -d "${fireqos_run_dir}" ]; then - if [ ! -z "${fireqos}" ] - then + # the fireqos executable - we will use it to find its config + fireqos="$(command -v fireqos 2>/dev/null)" - fireqos_exec_dir="$(realdir ${fireqos})" + if [ -n "${fireqos}" ]; then - if [ ! -z "${fireqos_exec_dir}" -a "${fireqos_exec_dir}" != "." -a -f "${fireqos_exec_dir}/install.config" ] - then + fireqos_exec_dir="$(realdir "${fireqos}")" - LOCALSTATEDIR= - source "${fireqos_exec_dir}/install.config" + if [ -n "${fireqos_exec_dir}" ] && [ "${fireqos_exec_dir}" != "." ] && [ -f "${fireqos_exec_dir}/install.config" ]; then + LOCALSTATEDIR= + #shellcheck source=/dev/null + source "${fireqos_exec_dir}/install.config" - if [ -d "${LOCALSTATEDIR}/run/fireqos" ] - then - fireqos_run_dir="${LOCALSTATEDIR}/run/fireqos" - else - warning "FireQoS is installed as '${fireqos}', its installation config at '${fireqos_exec_dir}/install.config' specifies local state data at '${LOCALSTATEDIR}/run/fireqos', but this directory is not found or is not readable (check the permissions of its parents)." - fi - else - warning "Although FireQoS is installed on this system as '${fireqos}', I cannot find/read its installation configuration at '${fireqos_exec_dir}/install.config'." - fi - else - warning "FireQoS is not installed on this system. Use FireQoS to apply traffic QoS and expose the class names to netdata. Check https://github.com/netdata/netdata/tree/master/collectors/tc.plugin#tcplugin" - fi + if [ -d "${LOCALSTATEDIR}/run/fireqos" ]; then + fireqos_run_dir="${LOCALSTATEDIR}/run/fireqos" + else + warning "FireQoS is installed as '${fireqos}', its installation config at '${fireqos_exec_dir}/install.config' specifies local state data at '${LOCALSTATEDIR}/run/fireqos', but this directory is not found or is not readable (check the permissions of its parents)." + fi + else + warning "Although FireQoS is installed on this system as '${fireqos}', I cannot find/read its installation configuration at '${fireqos_exec_dir}/install.config'." + fi + else + warning "FireQoS is not installed on this system. Use FireQoS to apply traffic QoS and expose the class names to netdata. Check https://github.com/netdata/netdata/tree/master/collectors/tc.plugin#tcplugin" + fi fi # ----------------------------------------------------------------------------- [ -z "${NETDATA_PLUGINS_DIR}" ] && NETDATA_PLUGINS_DIR="$(dirname "${0}")" -[ -z "${NETDATA_USER_CONFIG_DIR}" ] && NETDATA_USER_CONFIG_DIR="@configdir_POST@" +[ -z "${NETDATA_USER_CONFIG_DIR}" ] && NETDATA_USER_CONFIG_DIR="@configdir_POST@" [ -z "${NETDATA_STOCK_CONFIG_DIR}" ] && NETDATA_STOCK_CONFIG_DIR="@libconfigdir_POST@" plugins_dir="${NETDATA_PLUGINS_DIR}" -tc="$(which tc 2>/dev/null || command -v tc 2>/dev/null)" - +tc="$(command -v tc 2>/dev/null)" # ----------------------------------------------------------------------------- # user configuration @@ -126,7 +120,6 @@ qos_exit_every=3600 # what to use? classes or qdiscs? tc_show="qdisc" # can also be "class" - # ----------------------------------------------------------------------------- # check if we have a valid number for interval @@ -135,52 +128,46 @@ update_every=$((t)) [ $((update_every)) -lt 1 ] && update_every=${NETDATA_UPDATE_EVERY} [ $((update_every)) -lt 1 ] && update_every=1 - # ----------------------------------------------------------------------------- # allow the user to override our defaults -for CONFIG in "${NETDATA_STOCK_CONFIG_DIR}/tc-qos-helper.conf" "${NETDATA_USER_CONFIG_DIR}/tc-qos-helper.conf" -do - if [ -f "${CONFIG}" ] - then - info "Loading config file '${CONFIG}'..." - source "${CONFIG}" - [ $? -ne 0 ] && error "Failed to load config file '${CONFIG}'." - else - warning "Cannot find file '${CONFIG}'." - fi +for CONFIG in "${NETDATA_STOCK_CONFIG_DIR}/tc-qos-helper.conf" "${NETDATA_USER_CONFIG_DIR}/tc-qos-helper.conf"; do + if [ -f "${CONFIG}" ]; then + info "Loading config file '${CONFIG}'..." + #shellcheck source=/dev/null + source "${CONFIG}" || error "Failed to load config file '${CONFIG}'." + else + warning "Cannot find file '${CONFIG}'." + fi done case "${tc_show}" in - qdisc|class) - ;; +qdisc | class) ;; - *) - error "tc_show variable can be either 'qdisc' or 'class' but is set to '${tc_show}'. Assuming it is 'qdisc'." - tc_show="qdisc" - ;; +*) + error "tc_show variable can be either 'qdisc' or 'class' but is set to '${tc_show}'. Assuming it is 'qdisc'." + tc_show="qdisc" + ;; esac - # ----------------------------------------------------------------------------- # default sleep function LOOPSLEEPMS_LASTWORK=0 loopsleepms() { - sleep $1 + sleep "$1" } # if found and included, this file overwrites loopsleepms() # with a high resolution timer function for precise looping. +#shellcheck source=/dev/null . "${plugins_dir}/loopsleepms.sh.inc" - # ----------------------------------------------------------------------------- # final checks we can run -if [ -z "${tc}" -o ! -x "${tc}" ] - then - fatal "cannot find command 'tc' in this system." +if [ -z "${tc}" ] || [ ! -x "${tc}" ]; then + fatal "cannot find command 'tc' in this system." fi tc_devices= @@ -189,94 +176,91 @@ fix_names= # ----------------------------------------------------------------------------- setclassname() { - if [ "${tc_show}" = "qdisc" ] - then - echo "SETCLASSNAME $4 $2" - else - echo "SETCLASSNAME $3 $2" - fi + if [ "${tc_show}" = "qdisc" ]; then + echo "SETCLASSNAME $4 $2" + else + echo "SETCLASSNAME $3 $2" + fi } show_tc_cls() { - [ "${tc_show}" = "qdisc" ] && return 1 - - local x="${1}" - - if [ -f /etc/iproute2/tc_cls ] - then - local classid name rest - while read classid name rest - do - [ -z "${classid}" -o -z "${name}" -o "${classid}" = "#" -o "${name}" = "#" -o "${classid:0:1}" = "#" -o "${name:0:1}" = "#" ] && continue - setclassname "" "${name}" "${classid}" - done /dev/null)" + [ -n "${l}" ] && tc_devices="${tc_devices} ${dev}" + done } # update devices and class names @@ -289,27 +273,24 @@ exit_after=$((qos_exit_every / update_every)) c=0 gc=0 -while [ 1 ] -do - fix_names= - c=$((c + 1)) - gc=$((gc + 1)) +while true; do + fix_names= + c=$((c + 1)) + gc=$((gc + 1)) - if [ ${c} -le 1 -o ${c} -ge ${names_every} ] - then - c=1 - fix_names="YES" - find_tc_devices - fi + if [ ${c} -le 1 ] || [ ${c} -ge ${names_every} ]; then + c=1 + fix_names="YES" + find_tc_devices + fi - for d in ${tc_devices} - do - show_tc ${d} - done + for d in ${tc_devices}; do + show_tc "${d}" + done - echo "WORKTIME ${LOOPSLEEPMS_LASTWORK}" + echo "WORKTIME ${LOOPSLEEPMS_LASTWORK}" - loopsleepms ${update_every} + loopsleepms ${update_every} - [ ${gc} -gt ${exit_after} ] && exit 0 + [ ${gc} -gt ${exit_after} ] && exit 0 done -- cgit v1.2.3