Bandwidth Usage Report

General networking problems and issues. Questions about cabling, switches, hubs etc. can go here.
Post Reply
keyboardcowboy
Novice
Novice
Posts: 15
Joined: Wed Jul 21, 2010 1:02 pm

Bandwidth Usage Report

Post by keyboardcowboy » Sun Feb 12, 2012 6:32 pm

is it possible to have a monthly bandwidth usage report using routertech (how much GB/MB used), i tried darkstat but it does not show the total downloads/uploads
User avatar
thechief
RouterTech Team
RouterTech Team
Posts: 12067
Joined: Wed Feb 01, 2006 10:22 pm
Location: England, the Centre of Africa
Contact:

Re: Bandwidth Usage Report

Post by thechief » Sun Feb 12, 2012 8:27 pm

From the web interface - IPAccount
From a telnet/ssh session - showbandwidth.sh
The Chief: :afro: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
keyboardcowboy
Novice
Novice
Posts: 15
Joined: Wed Jul 21, 2010 1:02 pm

Re: Bandwidth Usage Report

Post by keyboardcowboy » Mon Feb 13, 2012 6:51 am

Is it possible to implement some type of quota system using IP Acount option, like disable internet when a particular amount of data has been downloaded,my modem is shared between different computers and have a 50GB monthly limit from the ISP
User avatar
thechief
RouterTech Team
RouterTech Team
Posts: 12067
Joined: Wed Feb 01, 2006 10:22 pm
Location: England, the Centre of Africa
Contact:

Re: Bandwidth Usage Report

Post by thechief » Mon Feb 13, 2012 8:04 am

Code: Select all

bandwidth.sh --help
The Chief: :afro: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
keyboardcowboy
Novice
Novice
Posts: 15
Joined: Wed Jul 21, 2010 1:02 pm

Re: Bandwidth Usage Report

Post by keyboardcowboy » Mon Feb 13, 2012 12:50 pm

will it reset if the router is rebooted
User avatar
thechief
RouterTech Team
RouterTech Team
Posts: 12067
Joined: Wed Feb 01, 2006 10:22 pm
Location: England, the Centre of Africa
Contact:

Re: Bandwidth Usage Report

Post by thechief » Mon Feb 13, 2012 6:16 pm

The Chief: :afro: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
keyboardcowboy
Novice
Novice
Posts: 15
Joined: Wed Jul 21, 2010 1:02 pm

Re: Bandwidth Usage Report

Post by keyboardcowboy » Mon Feb 13, 2012 6:52 pm

But the problem is will it be able to remember the previous amount downloaded, like for example what if 10gb was downloaded before the router got restarted won't autoexec.sh set it again to the initial value..10gb would be forgotten
User avatar
thechief
RouterTech Team
RouterTech Team
Posts: 12067
Joined: Wed Feb 01, 2006 10:22 pm
Location: England, the Centre of Africa
Contact:

Re: Bandwidth Usage Report

Post by thechief » Mon Feb 13, 2012 9:43 pm

keyboardcowboy wrote:But the problem is will it be able to remember the previous amount downloaded
No.
keyboardcowboy wrote: like for example what if 10gb was downloaded before the router got restarted won't autoexec.sh set it again to the initial value..10gb would be forgotten
Yep. If you want persistent data, you would have to write a script to do what you want, and you would need a writeable partition (e.g., minix or smbfs) to store the data.
The Chief: :afro: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
User avatar
hiteck
Regular
Regular
Posts: 47
Joined: Wed Dec 02, 2009 7:45 am
Location: N. America

Re: Bandwidth Usage Report

Post by hiteck » Fri Feb 17, 2012 3:22 am

Here is my latest stab at tracking usage.

This goes into /nvram/mac_watch.sh

Code: Select all

echo `date`>>/nvram/mac_log.txt
cat /var/tmp/landhcps0.leases >> /nvram/mac_log.txt
grep -v 'bytes_src = 0' /proc/net/ipt_account/mynetwork >> /nvram/mac_log.txt
echo "">>/nvram/mac_log.txt
tail /nvram/mac_log.txt -n 500 >/nvram/mac_log_tmp.txt
cp /nvram/mac_log_tmp.txt /nvram/mac_log.txt
rm /nvram/mac_log_tmp.txt
flush
The tail command keeps the partition from overfilling. I actually store 5000 lines. I have a 704kB minix partition (/nvram) in my GT701.


This goes into /nvram/startup.sh

Code: Select all

cp /nvram/mac_watch.sh /var/tmp/mac_watch.sh
write_crontab.sh '30' '1' '*' '*' '*' '/var/tmp/mac_watch.sh'

netshaper -d 192.168.1.201/24 5000
Be sure to set the script flags to executable. I used WinSCP. The script copy runs in ram (/var/tmp) so it can flush the nvram data. IP/mac and usage totals are logged once a day at 1:30am.

The netshaper command slows down an offending user to 5kB/sec. Their MAC and IP must first be allocated as a Lan Client in the web gui.
Any fool can make things complicated. It takes a genius to make things simple. - Einstein Jobs
User avatar
hiteck
Regular
Regular
Posts: 47
Joined: Wed Dec 02, 2009 7:45 am
Location: N. America

Re: Bandwidth Usage Report

Post by hiteck » Fri Feb 17, 2012 4:34 am

This makes the report a little easier to read. It uses showbandwidth.sh .

Code: Select all

echo `date`>>/nvram/mac_log.txt
cat /var/tmp/landhcps0.leases >> /nvram/mac_log.txt
showbandwidth.sh >> /nvram/mac_log.txt
echo "">>/nvram/mac_log.txt
tail /nvram/mac_log.txt -n 500 >/nvram/mac_log_tmp.txt
cp /nvram/mac_log_tmp.txt /nvram/mac_log.txt
rm /nvram/mac_log_tmp.txt
flush
Any fool can make things complicated. It takes a genius to make things simple. - Einstein Jobs
User avatar
thechief
RouterTech Team
RouterTech Team
Posts: 12067
Joined: Wed Feb 01, 2006 10:22 pm
Location: England, the Centre of Africa
Contact:

Re: Bandwidth Usage Report

Post by thechief » Fri Feb 17, 2012 8:06 am

This is very good :)

FYI - what is reported for 192.168.1.0 is the sum of the total bandwidth usage of the router's network (i.e., it is not attributable to any single client). So if you are on a metered ISP connection, that would be useful information to see whether you will get into trouble with your ISP!

Another thing - for this to work in respect of throttling the bandwidth of an errant user, that user must have a fixed IP - else he could bypass your actions by simply changing his IP address (alternatively, you might want to save the MAC address of the errant user, and so you will be able to tell if he changes his IP address).
The Chief: :afro: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
User avatar
hiteck
Regular
Regular
Posts: 47
Joined: Wed Dec 02, 2009 7:45 am
Location: N. America

Re: Bandwidth Usage Report

Post by hiteck » Wed Feb 22, 2012 9:06 pm

Here is a re-write of my Bandwidth and Mac address logger. It is nicer to the nvram and easier on ram usage. The sleep line is needed to allow the cp to finish before the flush is forced.

Code: Select all

echo "">/var/tmp/mac_log.txt
tail /nvram/mac_log.txt -n 600 >/var/tmp/mac_log.txt
echo `date`>>/var/tmp/mac_log.txt
cat /var/tmp/landhcps0.leases >> /var/tmp/mac_log.txt
showbandwidth.sh >> /var/tmp/mac_log.txt
echo "">>/var/tmp/mac_log.txt
cp /var/tmp/mac_log.txt /nvram/mac_log.txt
sleep 5
rm /var/tmp/mac_log.txt
flush /nvram
The initializer still goes into /nvram/startup.sh

Code: Select all

cp /nvram/mac_watch.sh /var/tmp/mac_watch.sh
write_crontab.sh '30' '1' '*' '*' '*' '/var/tmp/mac_watch.sh'
The end result is found in /nvram/mac_log.txt . I saw an average of about 60 bytes used per line, 2 lines per user. 100 days might use about 200 lines or 12kB of nvram per user.

Note that after loading these scripts into /nvram/mac_watch.sh you MUST issue flush /nvram or your script will get lost on reboot.
Any fool can make things complicated. It takes a genius to make things simple. - Einstein Jobs
User avatar
thechief
RouterTech Team
RouterTech Team
Posts: 12067
Joined: Wed Feb 01, 2006 10:22 pm
Location: England, the Centre of Africa
Contact:

Re: Bandwidth Usage Report

Post by thechief » Thu Feb 23, 2012 11:29 am

Looks good. There are two points though - first, the "sleep" line is not needed before calling "flush" - the script is executed sequentially and "cp" would have finished before the "flush" line is reached; secondly, the parameter supplied to "flush" is superfluous.
The Chief: :afro: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
Post Reply