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

Discuss the technical details of Gargoyle and ongoing development

Moderator: Moderators

Post Reply
oviano
Posts: 26
Joined: Sun Dec 20, 2015 7:41 am

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

Post 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)?

nworbnhoj
Posts: 916
Joined: Mon Jul 21, 2014 10:08 am
Location: Australia
Contact:

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

Post by nworbnhoj »

try

Code: Select all

/usr/bin/bw_get
/usr/bin/bw_print_history_file
Can you help someone else get Gargoyle up and running?
TL-WDR3600 : Gargoyle 1.9.0 : NBN FixedWireless
TL-WR1043ND-V2 : Gargoyle 1.8.0 : 3G Huawei E160E

oviano
Posts: 26
Joined: Sun Dec 20, 2015 7:41 am

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

Post 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.

nworbnhoj
Posts: 916
Joined: Mon Jul 21, 2014 10:08 am
Location: Australia
Contact:

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

Post 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
Can you help someone else get Gargoyle up and running?
TL-WDR3600 : Gargoyle 1.9.0 : NBN FixedWireless
TL-WR1043ND-V2 : Gargoyle 1.8.0 : 3G Huawei E160E

nworbnhoj
Posts: 916
Joined: Mon Jul 21, 2014 10:08 am
Location: Australia
Contact:

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

Post 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!
Can you help someone else get Gargoyle up and running?
TL-WDR3600 : Gargoyle 1.9.0 : NBN FixedWireless
TL-WR1043ND-V2 : Gargoyle 1.8.0 : 3G Huawei E160E

oviano
Posts: 26
Joined: Sun Dec 20, 2015 7:41 am

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

Post 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!

nworbnhoj
Posts: 916
Joined: Mon Jul 21, 2014 10:08 am
Location: Australia
Contact:

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

Post 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!
Can you help someone else get Gargoyle up and running?
TL-WDR3600 : Gargoyle 1.9.0 : NBN FixedWireless
TL-WR1043ND-V2 : Gargoyle 1.8.0 : 3G Huawei E160E

oviano
Posts: 26
Joined: Sun Dec 20, 2015 7:41 am

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

Post 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.

nworbnhoj
Posts: 916
Joined: Mon Jul 21, 2014 10:08 am
Location: Australia
Contact:

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

Post by nworbnhoj »

Thanks for posting - glad you got an outcome :-)
Can you help someone else get Gargoyle up and running?
TL-WDR3600 : Gargoyle 1.9.0 : NBN FixedWireless
TL-WR1043ND-V2 : Gargoyle 1.8.0 : 3G Huawei E160E

Post Reply