@cryptotaxi247 / netdata-1 / commits / c4c7be1b1

find fireqos run dir automatically; fixes #1684

Costa Tsaousis (ktsaou) committed Jan 31, 2017 at 01:47 UTC c4c7be1b1ea78a5f74cc2247af2111d2b6ab8c1d
1 file changed +73 -3
plugins.d/tc-qos-helper.sh
+73 -3
@@ -12,12 +12,58 @@
12 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
13 export LC_ALL=C
14
15 +
16 +# -----------------------------------------------------------------------------
17 +# find /var/run/fireqos
18 +
19 +# the default
20 +fireqos_run_dir="/var/run/fireqos"
21 +
22 +function realdir {
23 + local r="$1"
24 + local t=$(readlink "$r")
25 +
26 + while [ "$t" ]
27 + do
28 + r=$(cd $(dirname "$r") && cd $(dirname "$t") && pwd -P)/$(basename "$t")
29 + t=$(readlink "$r")
30 + done
31 +
32 + dirname "$r"
33 +}
34 +
35 +if [ ! -d "${fireqos_run_dir}" ]
36 + then
37 +
38 + # the fireqos executable - we will use it to find its config
39 + fireqos="$(which fireqos 2>/dev/null || command -v fireqos 2>/dev/null)"
40 +
41 + if [ ! -z "${fireqos}" ]
42 + then
43 +
44 + fireqos_exec_dir="$(realdir ${fireqos})"
45 +
46 + if [ ! -z "${fireqos_exec_dir}" -a "${fireqos_exec_dir}" != "." -a -f "${fireqos_exec_dir}/install.config" ]
47 + then
48 +
49 + LOCALSTATEDIR=
50 + source "${fireqos_exec_dir}/install.config"
51 +
52 + if [ -d "${LOCALSTATEDIR}/run/fireqos" ]
53 + then
54 + fireqos_run_dir="${LOCALSTATEDIR}/run/fireqos"
55 + fi
56 + fi
57 + fi
58 +fi
59 +
60 +# -----------------------------------------------------------------------------
61 +# logging functions
62 +
63 PROGRAM_FILE="$0"
64 PROGRAM_NAME="$(basename $0)"
65 PROGRAM_NAME="${PROGRAM_NAME/.plugin}"
66
19 -# -----------------------------------------------------------------------------
20 -
67 logdate() {
68 date "+%Y-%m-%d %H:%M:%S"
69 }
@@ -52,6 +98,7 @@ debug() {
98 [ $debug -eq 1 ] && log DEBUG "${@}"
99 }
100
101 +
102 # -----------------------------------------------------------------------------
103
104 plugins_dir="${NETDATA_PLUGINS_DIR}"
@@ -59,19 +106,33 @@ plugins_dir="${NETDATA_PLUGINS_DIR}"
106
107 config_dir=${NETDATA_CONFIG_DIR-/etc/netdata}
108 tc="$(which tc 2>/dev/null || command -v tc 2>/dev/null)"
62 -fireqos_run_dir="/var/run/fireqos"
109 +
110 +
111 +# -----------------------------------------------------------------------------
112 +# user configuration
113 +
114 +# time in seconds to refresh QoS class/qdisc names
115 qos_get_class_names_every=120
116 +
117 +# time in seconds to exit - netdata will restart the script
118 qos_exit_every=3600
119
120 +# what to use? classes or qdiscs?
121 tc_show="qdisc" # can also be "class"
122
123 +
124 +# -----------------------------------------------------------------------------
125 # check if we have a valid number for interval
126 +
127 t=${1}
128 update_every=$((t))
129 [ $((update_every)) -lt 1 ] && update_every=${NETDATA_UPDATE_EVERY}
130 [ $((update_every)) -lt 1 ] && update_every=1
131
132 +
133 +# -----------------------------------------------------------------------------
134 # allow the user to override our defaults
135 +
136 if [ -f "${config_dir}/tc-qos-helper.conf" ]
137 then
138 source "${config_dir}/tc-qos-helper.conf"
@@ -87,7 +148,10 @@ case "${tc_show}" in
148 ;;
149 esac
150
151 +
152 +# -----------------------------------------------------------------------------
153 # default sleep function
154 +
155 LOOPSLEEPMS_LASTWORK=0
156 loopsleepms() {
157 sleep $1
@@ -97,6 +161,10 @@ loopsleepms() {
161 # with a high resolution timer function for precise looping.
162 . "${plugins_dir}/loopsleepms.sh.inc"
163
164 +
165 +# -----------------------------------------------------------------------------
166 +# final checks we can run
167 +
168 if [ -z "${tc}" -o ! -x "${tc}" ]
169 then
170 fatal "cannot find command 'tc' in this system."
@@ -105,6 +173,8 @@ fi
173 tc_devices=
174 fix_names=
175
176 +# -----------------------------------------------------------------------------
177 +
178 setclassname() {
179 if [ "${tc_show}" = "qdisc" ]
180 then