Per-user bandwidth monitoring script

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Contributions Upload
Goto page 1, 2  Next
Author Message
xorglub
DD-WRT Novice


Joined: 04 May 2009
Posts: 7

PostPosted: Mon May 04, 2009 13:08    Post subject: Per-user bandwidth monitoring script Reply with quote
Hi all,

I have developed a small script that runs on most linux-based routers, but primarily targeted for dd-wrt.
It allows to monitor bandwidth usage on a per-mac address basis.

You can find it there : http://code.google.com/p/wrtbwmon/

At the moment it is not integrated and you have to know your way around the Linux OS to set it up (command line and cron jobs).

Please tell me what you think of it.
If a similar functionality could be integrated in the base dd-wrt firmware that would be awesome - no router firmware does that.
Sponsor
seocam
DD-WRT Novice


Joined: 09 Jun 2009
Posts: 1

PostPosted: Tue Jun 09, 2009 21:39    Post subject: Reply with quote
I need exactly the same here. I've just hired a fiber connection to share with some friends and we pay by bandwidth so we need to know how much each one uses.

Our solution until now is use a vnstat in each ones computer to measure, but have this integrated in the router would be great.

Unfortunately as our router (WRT54G2) only supports the DD-WRT micro we could not use your script mainly because we don't have a way to send the data do the server.

Is there any way to push data to a FTP server using the micro version?
greyback
DD-WRT Novice


Joined: 23 Apr 2009
Posts: 1

PostPosted: Wed Jun 10, 2009 1:08    Post subject: Good stuff Reply with quote
Hi xorglub,
this is what I've been searching for, for quite a while now. I share my bandwidth with 3 housemates, and someone is being naughty. I've struggled to set up a per-MAC log system using RFlow and Ntop on a server, but the data doesn't match that of the ISP or the simple dd-wrt bandwidth graph, and analysing every packet is overkill really.

I've just set up your script now, with luck this is all I need. It would be great to incorporate this into the dd-wrt webUI.

I would also be curious to see if a 30 minutely backup of the usage file to the jffs would be a terrible thing or not. And a quick restore file is there on bootup script later, we've basic reboot-proofedness

Thanks v much
-G
xorglub
DD-WRT Novice


Joined: 04 May 2009
Posts: 7

PostPosted: Sat Jun 13, 2009 6:16    Post subject: Reply with quote
@seocam, the wget and ftpput commands are available in the micro-plus version of dd-wrt, see if you can flash it to your WRT54G2. They should be enough for all remote backup & restore purposes.
redhawk0
DD-WRT Guru


Joined: 04 Jan 2007
Posts: 10915
Location: Wherever the wind blows- North America

PostPosted: Sat Jun 13, 2009 13:03    Post subject: Reply with quote
xorglub wrote:
@seocam, the wget and ftpput commands are available in the micro-plus version of dd-wrt, see if you can flash it to your WRT54G2. They should be enough for all remote backup & restore purposes.


Agreed....the WRT54G2 unit will take micro_plus and micro_plus_ssh directly. It will give you the same set of busybox commands as other builds of dd-wrt and if you use the ssh build, you of course, get ssh too.

redhawk

_________________
I currently test dd-wrt on Asus, Buffalo, Linksys, and Netgear. Too many to list.

Looking for more test units (newer models) for the project...got a brick?...PM me to make a donation. (USA) A donation is not a debricking service....it is a way to "Give back" to the dd-wrt project.

I do NOT provide personal assistance through chat or phone....so please don't ask.
fluffyllama
DD-WRT Novice


Joined: 19 Jan 2009
Posts: 12
Location: Canada

PostPosted: Wed Feb 24, 2010 0:50    Post subject: Reply with quote
dewt wrote:
mmm...for bandwith Usege I use Protemac meter..on mac...


That seems to be a bandwidth monitor for only 1 computer at a time. It's also Mac only, meaning (for me) I'd need a similar solution on Windows and Linux too. They're talking about having the router monitor usage per mac-address, meaning it'll work with Windows, Mac, Linux, live distros, friend's computers, Xboxes/PS3/Wii's, etc. Also, it doesn't have to be installed on each and every computer on the network.

I'll be trying this script out later! Will let you know how it works for me.

*edit*

Seems to work pretty well. I played with the suggested cron jobs to have it update more often. Looks like it works well in 5-minute intervals, with the DB backed up to /mmc every 15 minutes. I added in a shutdown script to back up the DB as well.

I haven't looked at the original script too much, but is it possible to modify it to output ip address instead of mac address, or perhaps only a select few ip/mac addresses?

*EDIT*

Dug through the script a bit, and found that it pulls hostnames from /etc/dnsmasq.conf, /tmp/dnsmasq.conf, or a manually specified external file. It wasn't pulling the names on my setup, since dnsmasq.conf doesn't exist in my /etc or /tmp. This is most likely because I configure dnsmasq from an external script, not from the GUI. Manually specifying an external file didn't work, so I just made sure that there would be a copy of dnsmasq.conf in /tmp.

Script works pretty well though. I did have an issue with the instructions, though. The line in cron:
Code:
* * * * * root [ ! -f /tmp/usage.db ] && wget some_url/usage.db -O /tmp/usage.db

didn't work for me, but worked without the -O:
Code:
* * * * * root [ ! -f /tmp/usage.db ] && wget some_url/usage.db /tmp/usage.db


Otherwise, I think this would be great if it was integrated into the main GUI. Thank god I have this set up; now I can finally show the brother-in-law just how much bandwidth he uses, and can charge him any of the overage fees!

*EDIT ONE MORE TIME!*

I've added a couple lines to cron to backup the htm output and reset the stats at the end of the month:

Code:
59 23 28-31 * * root cp /tmp/www/usage.htm /mmc/usage-`date +%b%Y`.htm
0 0 1 * * root rm /tmp/usage.db


This copies the htm page to /mmc at the end of the month (had to make it run on the 28th to 31st, but it'll overwrite the file each time so it won't duplicate it. It automatically names the backup file to "usage-Feb2010.htm" or whatever the month is. Finally, it removes the old DB, and the next time the script is run, it'll create a new one with the new month's stats.

*EDIT LAST TIME I SWEAR*

I modified the script a bit to add in a "Total Usage" statistic. Basically it just adds all 4 other stats together and creates it's own column in the HTML output.

Fair warning: This has been tested for only 15 minutes or so, and hasn't been tested in the "Off-Peak" timeslot. Let me know if you think it causes any problems.
liverpoolatnight
DD-WRT User


Joined: 29 May 2008
Posts: 168
Location: United Kingdom

PostPosted: Fri Mar 05, 2010 15:54    Post subject: Reply with quote
Show do i run .sh scrips om dd wrt? and dos this work in WRT54G2 v1
_________________
D-Link DIR-615 D2: DD-WRT v24-sp2 (04/18/14) std (SVN revision 23919)
ISP1: Virgin Media UK Cable, 60/3
ISP2: Sky Broadband UK (Fibre to the cabinet, Speed 80/20
BasCom
DD-WRT Guru


Joined: 29 Jul 2009
Posts: 1334
Location: Germany

PostPosted: Fri Mar 05, 2010 16:07    Post subject: Reply with quote
works fine. but how can i access the generated webpage on dd-wrt? i own only mini build without cifs, so i cannot storage the htm file on my debian webserver.

so, is it possible to access it thorugh http://router/usage.htm ? where i have to save this file..

_________________
RT-N66U @ kongac Build 24200M K3.10.40
TL-WR842ND v1 @ BS-build 23919 WDS AP
TL-WR841ND @ BS-build 23919 WDS Client
TL-WR841ND @ BS-build 23919 Client Bridge ( Routed )
fluffyllama
DD-WRT Novice


Joined: 19 Jan 2009
Posts: 12
Location: Canada

PostPosted: Sat Mar 06, 2010 2:37    Post subject: Reply with quote
liverpoolatnight wrote:
Show do i run .sh scrips om dd wrt? and dos this work in WRT54G2 v1


It should work on anything that can run DD-WRT, so long as you have either jffs, an SD card, an FTP server, or a cifs share accessible to the router (or some other method of storage that I've missed). Follow the instructions here:
http://code.google.com/p/wrtbwmon/wiki/Deploying

BasCom wrote:
works fine. but how can i access the generated webpage on dd-wrt? i own only mini build without cifs, so i cannot storage the htm file on my debian webserver.

so, is it possible to access it thorugh http://router/usage.htm ? where i have to save this file..


The page is saved in /tmp/www, so it's in Ram I believe. The file is accessible from http://router/user/usage.htm but it's lost if the router reboots or is powered off. If you have jffs, USB, or an SD mod, use those, otherwise maybe ftpput will work?
BasCom
DD-WRT Guru


Joined: 29 Jul 2009
Posts: 1334
Location: Germany

PostPosted: Sat Mar 06, 2010 22:12    Post subject: Reply with quote
i have not enought space for jffs filesystem, no cifs in mini image, no sd mod, no usb Smile
_________________
RT-N66U @ kongac Build 24200M K3.10.40
TL-WR842ND v1 @ BS-build 23919 WDS AP
TL-WR841ND @ BS-build 23919 WDS Client
TL-WR841ND @ BS-build 23919 Client Bridge ( Routed )
fluffyllama
DD-WRT Novice


Joined: 19 Jan 2009
Posts: 12
Location: Canada

PostPosted: Sun Mar 07, 2010 8:59    Post subject: Reply with quote
BasCom wrote:
i have not enought space for jffs filesystem, no cifs in mini image, no sd mod, no usb Smile


Then you'll have to switch to a firmware with cifs in it. I use the nokaid_generic from here on my WRT150N, and it has jffs, cifs, and mmc in it, and is one of the recommended builds at the moment. Not enough space for JFFS on a 4mb router though.

Without that, you'll have to run an FTP server and use ftpput then. Don't ask me how to use it; I don't know! Maybe if you're running a Linux/Mac machine with an SSH server, then scp might work too...

Best would be an SD mod though. If you're good with soldering, then that's the route I took. It was pretty easy to probe for 3 GPIO's (4th for CS wasn't needed).

_________________
Buffalo WZR-HP-G300NH on 23919
BasCom
DD-WRT Guru


Joined: 29 Jul 2009
Posts: 1334
Location: Germany

PostPosted: Mon Mar 08, 2010 15:29    Post subject: Reply with quote
due to some vlan issues i was nor able to run cifs firmware ( mini ). no i am, because it is availible. :D

well, monitoring works fine, but ir does not work with cron.

in startup i have

stopservice cron
monitor setup
startservice cron

but the iptables rules in RRDIPT were not set.
i have to run it manually from telnet.

next thing is, that the cronjob is not working
Code:

root@gateway:/tmp# cat /tmp/cron.d/cron_jobs
0,5,10,15,20,25,30,35,40,45,50,55 * * * * monitor update /tmp/usage.db

the usage.db is missing, so i guess, cron is not working but the deamon is running. i added the cronjob via admin interface.

Code:

root@gateway:/tmp# ps | grep cron
 1255 root       976 S    cron


any hints ?

_________________
RT-N66U @ kongac Build 24200M K3.10.40
TL-WR842ND v1 @ BS-build 23919 WDS AP
TL-WR841ND @ BS-build 23919 WDS Client
TL-WR841ND @ BS-build 23919 Client Bridge ( Routed )
mark105
DD-WRT Novice


Joined: 18 Jun 2006
Posts: 1

PostPosted: Fri Jul 02, 2010 5:35    Post subject: Reply with quote
this doesn't quite work for me which is a bummer.

im running tomato 1.27 so maybe this isnt the right place to be posting this but i get these errors when i run "/cifs1/wrtbwmon update /cifs1/usage.db peak"

Code:

# /cifs1/wrtbwmon update /cifs1/usage.db peak
cat: can't open '/tmp/in_9750.tmp': No such file or directory
cat: can't open '/tmp/out_9750.tmp': No such file or directory
[: 0: unknown operand
cat: can't open '/tmp/in_9750.tmp': No such file or directory
cat: can't open '/tmp/out_9750.tmp': No such file or directory
[: 0: unknown operand
DEBUG : New traffic for "mac address" since last update : 124k:2799k
DEBUG : New traffic for "mac address" since last update : 22k:2k
#


also im not sure if the above is the issue but it seems to loose data as my usage.htm that gets generated contains some data but alot of it is unaccounted for.

im not sure how to fix the above so any help would be great.
Akaz1976
DD-WRT Novice


Joined: 04 Jan 2011
Posts: 3

PostPosted: Tue Jan 04, 2011 21:54    Post subject: Less technical install instructions Reply with quote
Hi,

Is it possible to install this without knowing code? I tried looking at the above link (for deployment instructions) and i can not understand them.

i have a WRT54GL installed with DD-WRT mini.

I am constantly going over my home bandwidth limits (8 users) but i do not know if its normal use or if some one is unwittingly (using bittorrent without throttling upload etc) going over.

I dont want to meddle with peoples PCs for privacy reason so i would like an option to check each users bandwidth use per month at router level.
fluffyllama
DD-WRT Novice


Joined: 19 Jan 2009
Posts: 12
Location: Canada

PostPosted: Tue Jan 04, 2011 22:51    Post subject: Re: Less technical install instructions Reply with quote
Akaz1976 wrote:
Hi,

Is it possible to install this without knowing code? I tried looking at the above link (for deployment instructions) and i can not understand them.

i have a WRT54GL installed with DD-WRT mini.



Follow my previous post:

fluffyllama wrote:
It should work on anything that can run DD-WRT, so long as you have either jffs, an SD card, an FTP server, or a cifs share accessible to the router (or some other method of storage that I've missed). Follow the instructions here:
http://code.google.com/p/wrtbwmon/wiki/Deploying


If you can't set up jffs, SD card, FTP etc, you can use RFlow (http://www.dd-wrt.com/wiki/index.php/Using_RFlow_Collector_and_MySQL_To_Gather_Traffic_Information) to monitor bandwidth, but that'll require a computer which is on at ALL times, otherwise the statistics will be inaccurate.

Alternatively, with 8 people sharing the router, is it not possible to bump to a higher level package from your ISP? Where I live, it's $10/month difference to go from 60gb to 100gb per month, and that increases DL speed to 15mbit from 7.5mbit. Also, with 8 people, a more powerful router may be helpful. Something like the Asus RT-N16, perhaps? That'd give you tons of room for bandwidth logs and the like.

_________________
Buffalo WZR-HP-G300NH on 23919
Goto page 1, 2  Next Display posts from previous:    Page 1 of 2
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Contributions Upload All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum