]> arthur.barton.de Git - netdata.git/commitdiff
find fireqos run dir automatically; fixes #1684
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Mon, 30 Jan 2017 23:47:39 +0000 (01:47 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Mon, 30 Jan 2017 23:47:39 +0000 (01:47 +0200)
plugins.d/tc-qos-helper.sh

index 6dd9bfb59b29da4b3e5e70c167547b99d2eed265..074fece9a5e3d571618a69a0c3942ac7b11cd0ea 100755 (executable)
 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
 export LC_ALL=C
 
+
+# -----------------------------------------------------------------------------
+# find /var/run/fireqos
+
+# the default
+fireqos_run_dir="/var/run/fireqos"
+
+function realdir {
+    local r="$1"
+    local t=$(readlink "$r")
+
+    while [ "$t" ]
+        do
+        r=$(cd $(dirname "$r") && cd $(dirname "$t") && pwd -P)/$(basename "$t")
+        t=$(readlink "$r")
+    done
+
+    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 [ ! -z "${fireqos}" ]
+        then
+
+        fireqos_exec_dir="$(realdir ${fireqos})"
+
+        if [ ! -z "${fireqos_exec_dir}" -a "${fireqos_exec_dir}" != "." -a -f "${fireqos_exec_dir}/install.config" ]
+            then
+
+            LOCALSTATEDIR=
+            source "${fireqos_exec_dir}/install.config"
+
+            if [ -d "${LOCALSTATEDIR}/run/fireqos" ]
+                then
+                fireqos_run_dir="${LOCALSTATEDIR}/run/fireqos"
+            fi
+        fi
+    fi
+fi
+
+# -----------------------------------------------------------------------------
+# logging functions
+
 PROGRAM_FILE="$0"
 PROGRAM_NAME="$(basename $0)"
 PROGRAM_NAME="${PROGRAM_NAME/.plugin}"
 
-# -----------------------------------------------------------------------------
-
 logdate() {
     date "+%Y-%m-%d %H:%M:%S"
 }
@@ -52,6 +98,7 @@ debug() {
     [ $debug -eq 1 ] && log DEBUG "${@}"
 }
 
+
 # -----------------------------------------------------------------------------
 
 plugins_dir="${NETDATA_PLUGINS_DIR}"
@@ -59,19 +106,33 @@ plugins_dir="${NETDATA_PLUGINS_DIR}"
 
 config_dir=${NETDATA_CONFIG_DIR-/etc/netdata}
 tc="$(which tc 2>/dev/null || command -v tc 2>/dev/null)"
-fireqos_run_dir="/var/run/fireqos"
+
+
+# -----------------------------------------------------------------------------
+# user configuration
+
+# time in seconds to refresh QoS class/qdisc names
 qos_get_class_names_every=120
+
+# time in seconds to exit - netdata will restart the script
 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
+
 t=${1}
 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
+
 if [ -f "${config_dir}/tc-qos-helper.conf" ]
     then
     source "${config_dir}/tc-qos-helper.conf"
@@ -87,7 +148,10 @@ case "${tc_show}" in
         ;;
 esac
 
+
+# -----------------------------------------------------------------------------
 # default sleep function
+
 LOOPSLEEPMS_LASTWORK=0
 loopsleepms() {
     sleep $1
@@ -97,6 +161,10 @@ loopsleepms() {
 # with a high resolution timer function for precise looping.
 . "${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."
@@ -105,6 +173,8 @@ fi
 tc_devices=
 fix_names=
 
+# -----------------------------------------------------------------------------
+
 setclassname() {
     if [ "${tc_show}" = "qdisc" ]
         then