Page 1 of 1

Determine if a QoS class is active from an ssh script?

Posted: Fri Jan 15, 2016 6:23 am
by oviano
With reference to this thread I started in the Feature Requests forum:

viewtopic.php?f=13&t=8117#wrap

Does anyone know how I can retrieve the current (or short-term averaged) load of a specific class inside an ssh script? Or whether a particular class is considered "active" (which I think I read somewhere equates to a load of 4kbps)?

Re: Determine if a QoS class is active from an ssh script?

Posted: Fri Jan 15, 2016 3:12 pm
by nworbnhoj
try

Code: Select all

/usr/bin/bw_get
/usr/bin/bw_print_history_file

Re: Determine if a QoS class is active from an ssh script?

Posted: Sun Jan 17, 2016 9:29 am
by oviano
Thanks for that, I'm not sure how to use those though - the bw_get one returns "ERROR: you must specify an id to query" and I don't know what id it is talking about.

bw_print_history_file doesn't give an error but I don't know what it has written and to where.

Re: Determine if a QoS class is active from an ssh script?

Posted: Sun Jan 17, 2016 4:49 pm
by nworbnhoj
Sorry - do not have time to chase it down for you today.

Gargoyle is a GUI and these files are part of the back-end system. You will need to get into the code a bit to see how they work.

Good luck - I will have some time tommorow if you get stuck

Re: Determine if a QoS class is active from an ssh script?

Posted: Mon Jan 18, 2016 3:45 am
by nworbnhoj
The qos config can be listed with

Code: Select all

uci show qos_gargoyle
You can get a list of current monitorName with

Code: Select all

cat /tmp/bw_backup/do_bw_backup.sh  | egrep "minute" | sed 's/^.*\-i \"//g' | sed 's/\".*$//g'
You will need to call bw_get

Code: Select all

bw_get -i $monitorName -h -m
tip: try the -h & -m options separately
h=history
m=something else

Love to know how you get on and what you learn!

Re: Determine if a QoS class is active from an ssh script?

Posted: Mon Jan 18, 2016 4:44 am
by oviano
Thankyou very much for that, I appreciate it! I think this should give me the tools I need.

I will probably make my script monitor the output of this for a few seconds:

bw_get -i "qos1-down-dclass_2-minute-15" | cut f2

This should allow me to derive a kbps for my IPTV class for the period I monitor, and I can then use that to switch on and off my additional QoS setting.

Although maybe I can get the kbps value more directly - essentially I want to get access to the figure that is displayed in the Load column under Firewall -> QoS (Download) -- Service Classes table for my class...is that stored somewhere or is it calculated on-the-fly from the web page?

Thanks again!

Re: Determine if a QoS class is active from an ssh script?

Posted: Mon Jan 18, 2016 7:09 am
by nworbnhoj
nworbnhoj wrote:is that stored somewhere or is it calculated on-the-fly from the web page?
Don't know - you had better have a look at the code!

Re: Determine if a QoS class is active from an ssh script?

Posted: Mon Jan 18, 2016 8:24 am
by oviano
Ok, so I managed to achieve what I wanted.

Here is my final script in case anyone ever finds some of it useful.

Code: Select all

#!/bin/sh
bytes1=$(bw_get -i "qos1-down-dclass_2-minute-15" | cut -f2)
sleep 5
bytes2=$(bw_get -i "qos1-down-dclass_2-minute-15" | cut -f2)
bytes=`expr $bytes2 - $bytes1`
bytes_per_second=`expr $bytes / 5`
bits_per_second=`expr $bytes_per_second \* 8`
kbits_per_second=`expr $bits_per_second / 1000`
dclass_1_max_bandwidth=`uci get qos_gargoyle.dclass_1.max_bandwidth -q`
if [ "$?" = "1" ]
then
  dclass_1_max_bandwidth=0
fi
if [ $kbits_per_second -gt 64 ]
then
  if [ $dclass_1_max_bandwidth -ne 2000 ]
  then
    uci set qos_gargoyle.uclass_1.max_bandwidth=200
    uci set qos_gargoyle.dclass_1.max_bandwidth=2000
    uci commit qos_gargoyle
    /etc/init.d/qos_gargoyle restart
  fi
else
  if [ $dclass_1_max_bandwidth -eq 2000 ]
  then
    uci delete qos_gargoyle.uclass_1.max_bandwidth
    uci delete qos_gargoyle.dclass_1.max_bandwidth
    uci commit qos_gargoyle
    /etc/init.d/qos_gargoyle restart
  fi
fi
exit 0
This is scheduled to run every minute. It first works out the kbps for a 5s period and if this is above a threshold (64kbps) then it will make sure that my additional QoS maximum bandwidths are set for upload and download for my non-IPTV classes, otherwise it makes sure they are not set.

Thanks for your help.

Re: Determine if a QoS class is active from an ssh script?

Posted: Mon Jan 18, 2016 3:32 pm
by nworbnhoj
Thanks for posting - glad you got an outcome :-)