What's new

[EDIT]Real-time Quota Monitoring (Download/Upload/Data Used)

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

thanks for the reply, sounds very logical
If you issue
Code:
runner disable
fc disable
before running the script, hopefully the statistics are as expected?

You can then manually explicitly re-enable HW Acceleration or simply reboot.
 
So this runs on stock firmware without the need for QOS or Parental Controls to be enabled?
 
I am trying to get this running on my RT-AC68U. I am getting these errors. Can someone point me in the right direction?

1694034142751.png
 
Ah, sorry, it says:

./QuotaMonitor.sh: eval: line 1: 162100: not found
./QuotaMonitor.sh: eval: line 1: 198430: not found
./QuotaMonitor.sh: eval: line 1: 162100: not found
./QuotaMonitor.sh: eval: line 1: 198430: not found
./QuotaMonitor.sh: eval: line 1: 162100: not found
./QuotaMonitor.sh: eval: line 1: 198430: not found


Regards,
Dave
 
Sorry, no idea. It works for me, but then I have a different router. What firmware version are you using?

I suggest you reset everything and try it again without any IP addresses.
Code:
./QuotaMonitor.sh resetdel
./QuotaMonitor.sh init
./QuotaMonitor.sh monitor
 
Thanks. That was helpful. I went back and just added one IP address and then ran monitor. The monitor ran this time, but for some reason it shows the IP address of my DNS server rather than the IP address I added. I think that is why the "duplicate hostnames" were detected; it just added my DNS IP (and hostname) multiple times.
 
It sounds like it's glitching on an nslookup. Do you have any Entware packages or addon scripts installed (other than this script)?
 
It sounds like it's glitching on an nslookup. Do you have any Entware packages or addon scripts installed (other than this script)?
No. I was using the WAN failover scripts, but reformatted JFFS and started over to see if it would fix this issue...but it didn't.
 
Are you using any strange characters in your host names? QoS enabled?

Try running it with the verbose option:
Code:
# ./QuotaMonitor.sh verbose
Chain MyQUOTAi (1 references)
num   pkts bytes target     prot opt in     out     source               destination
1       34  7674            all  --  eth0   br0     0.0.0.0/0            192.168.1.49         /* zen */

Chain MyQUOTAo (1 references)
num   pkts bytes target     prot opt in     out     source               destination
1       38  4290            all  --  br0    eth0    192.168.1.49         0.0.0.0/0            /* zen */

Chain POSTROUTING (policy ACCEPT 1256K packets, 957M bytes)
num   pkts bytes target     prot opt in     out     source               destination

        v1.08 Quota/Rate Monitoring every 60 secs (Quota Rx/Tx Limit 50.00 MB/10.00 MB and Quota Data Usage Capped Limit is 50.00 GB)

                        There are 1 devices monitored

                        There are 0 devices BLOCKED
                        There are 0 devices throttled by QoS
 
Are you using any strange characters in your host names? QoS enabled?

Try running it with the verbose option:
Code:
# ./QuotaMonitor.sh verbose
Chain MyQUOTAi (1 references)
num   pkts bytes target     prot opt in     out     source               destination
1       34  7674            all  --  eth0   br0     0.0.0.0/0            192.168.1.49         /* zen */

Chain MyQUOTAo (1 references)
num   pkts bytes target     prot opt in     out     source               destination
1       38  4290            all  --  br0    eth0    192.168.1.49         0.0.0.0/0            /* zen */

Chain POSTROUTING (policy ACCEPT 1256K packets, 957M bytes)
num   pkts bytes target     prot opt in     out     source               destination

        v1.08 Quota/Rate Monitoring every 60 secs (Quota Rx/Tx Limit 50.00 MB/10.00 MB and Quota Data Usage Capped Limit is 50.00 GB)

                        There are 1 devices monitored

                        There are 0 devices BLOCKED
                        There are 0 devices throttled by QoS
Does an "_" count as a strange character? The one I am trying to add is shown with client name of "RZYHGCJ00001973_JIDU6001" in the GUI.

When I use the verbose option, I see this:

admin@RT-AC68U-5E80:/jffs/scripts# ./QuotaMonitor.sh verbose
Chain MyQUOTAi (1 references)
num pkts bytes target prot opt in out source destination
1 9522 13M all -- eth0 br0 0.0.0.0/0 192.168.2.44 /* dns */

Chain MyQUOTAo (1 references)
num pkts bytes target prot opt in out source destination
1 4490 329K all -- br0 eth0 192.168.2.44 0.0.0.0/0 /* dns */

Chain POSTROUTING (policy ACCEPT 97M packets, 85G bytes)
num pkts bytes target prot opt in out source destination
1 271K 69M MARK all -- * * 192.168.2.1 192.168.2.0/24 MARK set 0x9
2 271K 69M RETURN all -- * * 192.168.2.1 192.168.2.0/24

v1.08 Quota/Rate Monitoring every 60 secs (Quota Rx/Tx Limit 50.00 MB/10.00 MB and Quota Data Usage Capped Limit is 50.00 GB)

There are 1 devices monitored

There are 0 devices BLOCKED
There are 0 devices throttled by QoS


Looks about right, but even here it is somehow convinced that the IP address is "dns". Also, when I get it into a blocking state, it blocks DNS rather than the IP:

admin@RT-AC68U-5E80:/jffs/scripts# ./QuotaMonitor.sh verbose
Chain MyQUOTAi (1 references)
num pkts bytes target prot opt in out source destination
1 0 0 DROP all -- eth0 br0 0.0.0.0/0 8.8.8.8 /* Block dns */
2 348K 492M all -- eth0 br0 0.0.0.0/0 192.168.2.44 /* dns */

Chain MyQUOTAo (1 references)
num pkts bytes target prot opt in out source destination
1 0 0 DROP all -- br0 eth0 8.8.8.8 0.0.0.0/0 /* Block dns */
2 125K 35M all -- br0 eth0 192.168.2.44 0.0.0.0/0 /* dns */

Chain POSTROUTING (policy ACCEPT 1215K packets, 1325M bytes)
num pkts bytes target prot opt in out source destination
1 917 245K MARK all -- * * 192.168.2.1 192.168.2.0/24 MARK set 0x9
2 917 245K RETURN all -- * * 192.168.2.1 192.168.2.0/24

v1.08 Quota/Rate Monitoring every 60 secs (Quota Rx/Tx Limit 50.00 MB/10.00 MB and Quota Data Usage Capped Limit is 50.00 GB)

There are 1 devices monitored

There are 1 devices BLOCKED (dns)
There are 0 devices throttled by QoS



Is it possible there is a dependency related to the DNS settings in the GUI?
 
Does an "_" count as a strange character? The one I am trying to add is shown with client name of "RZYHGCJ00001973_JIDU6001" in the GUI.

When I use the verbose option, I see this:

admin@RT-AC68U-5E80:/jffs/scripts# ./QuotaMonitor.sh verbose
Chain MyQUOTAi (1 references)
num pkts bytes target prot opt in out source destination
1 9522 13M all -- eth0 br0 0.0.0.0/0 192.168.2.44 /* dns */

Chain MyQUOTAo (1 references)
num pkts bytes target prot opt in out source destination
1 4490 329K all -- br0 eth0 192.168.2.44 0.0.0.0/0 /* dns */

Chain POSTROUTING (policy ACCEPT 97M packets, 85G bytes)
num pkts bytes target prot opt in out source destination
1 271K 69M MARK all -- * * 192.168.2.1 192.168.2.0/24 MARK set 0x9
2 271K 69M RETURN all -- * * 192.168.2.1 192.168.2.0/24

v1.08 Quota/Rate Monitoring every 60 secs (Quota Rx/Tx Limit 50.00 MB/10.00 MB and Quota Data Usage Capped Limit is 50.00 GB)

There are 1 devices monitored

There are 0 devices BLOCKED
There are 0 devices throttled by QoS


Looks about right, but even here it is somehow convinced that the IP address is "dns". Also, when I get it into a blocking state, it blocks DNS rather than the IP:

admin@RT-AC68U-5E80:/jffs/scripts# ./QuotaMonitor.sh verbose
Chain MyQUOTAi (1 references)
num pkts bytes target prot opt in out source destination
1 0 0 DROP all -- eth0 br0 0.0.0.0/0 8.8.8.8 /* Block dns */
2 348K 492M all -- eth0 br0 0.0.0.0/0 192.168.2.44 /* dns */

Chain MyQUOTAo (1 references)
num pkts bytes target prot opt in out source destination
1 0 0 DROP all -- br0 eth0 8.8.8.8 0.0.0.0/0 /* Block dns */
2 125K 35M all -- br0 eth0 192.168.2.44 0.0.0.0/0 /* dns */

Chain POSTROUTING (policy ACCEPT 1215K packets, 1325M bytes)
num pkts bytes target prot opt in out source destination
1 917 245K MARK all -- * * 192.168.2.1 192.168.2.0/24 MARK set 0x9
2 917 245K RETURN all -- * * 192.168.2.1 192.168.2.0/24

v1.08 Quota/Rate Monitoring every 60 secs (Quota Rx/Tx Limit 50.00 MB/10.00 MB and Quota Data Usage Capped Limit is 50.00 GB)

There are 1 devices monitored

There are 1 devices BLOCKED (dns)
There are 0 devices throttled by QoS



Is it possible there is a dependency related to the DNS settings in the GUI?
Also, on the topic of special characters, I notice that when I do an nslookup it showns 8.8.8.8 as "dns.google". Perhaps the "." is causing an issue. Not sure how I change the configuration to use a different name, though.
 
Also, on the topic of special characters, I notice that when I do an nslookup it showns 8.8.8.8 as "dns.google". Perhaps the "." is causing an issue. Not sure how I change the configuration to use a different name, though.
That is correct. 8.8.8.8 is dns.google.
 
What do you get from these commands (post the output within a CODE block):
Code:
nslookup RZYHGCJ00001973_JIDU6001

nslookup 192.168.2.44
 
I think I've just realised what the problem is...

Log into the router and go to Tools - Other Settings. Change Wan: Use local caching DNS server as system resolver to Yes.
 
I may try your solution to see if it makes a different (I doubt it, given what is below), but I made a change to the script that fixes it on my system.

I changed this line:
IP_RANGE=$(nslookup $1 | grep "Address" | grep -v localhost | cut -d" " -f4)

to this:
IP_RANGE=$(nslookup $1 | grep "Address" | tail -n 1 | grep -v localhost | cut -d" " -f4)


The reason is that nslookup returns something that looks like this on my system:

admin@RT-AC68U-5E80:/jffs/scripts# nslookup 192.168.2.44
Server: 8.8.8.8
Address 1: 8.8.8.8 dns.google

Name: 192.168.2.44
Address 1: 192.168.2.44 myrouter


So without adding the "tail -n 1", that line from the script was returning:
dns.google
myrouter

As such...it kept picking out the "dns" and getting the wrong result. By adding the "tail" it just takes the last line returned.
 
I believe the problem occurs when the script tries to determine the IP address from the hostname. Without changing that GUI option, and if you haven't created a DHCP reservation for the host, it sends the request to the WAN DNS server which has no knowledge of a host called "RZYHGCJ00001973_JIDU6001".

Code:
# nslookup RZYHGCJ00001973_JIDU6001
Server:    8.8.8.8
Address 1: 8.8.8.8 dns.google

nslookup: can't resolve 'RZYHGCJ00001973_JIDU6001'

The script appears to be expecting you to be using localhost for your DNS (which was the default setting back in 2018), which is why it's grep'ing out that localhost line:
Code:
# nslookup zen
Server:    127.0.0.1
Address 1: 127.0.0.1 localhost.localdomain

Name:      zen
Address 1: 192.168.1.49 zen.home.lan
 
Last edited:
Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top