Per-user Live Down/Upload Rate Monitoring [No PC needed!]

Post new topic   Reply to topic    DD-WRT Forum Index -> Contributions Upload
Goto page 1, 2, 3 ... 10, 11, 12  Next
Author Message
Wolf Kodi
DD-WRT User


Joined: 13 Jun 2010
Posts: 126

PostPosted: Fri Jul 09, 2010 5:10    Post subject: Per-user Live Down/Upload Rate Monitoring [No PC needed!] Reply with quote
Hi guys,

I've modified Emmanuel Brucy's bandwidth monitoring script (wrtbwmon - http://code.google.com/p/wrtbwmon/), doing away with the peak and offpeak usage catagory division (instead there is only one total usage) and using it to calculate live traffic of individual users in 10 seconds intervals.

This thing runs entirely on your router! No PC needed! :D

Here is a sample of the script running:



IMPLEMENTATION [Updated 19 July 2010]
1) Download the monitoring script file (wrtbwmon) attached below or http://www.dd-wrt.com/phpBB2/download.php?id=15332. Place it somewhere your router will be able to access it. Make sure you give it execution permissions.

2) Instead of using Cron jobs, we need scripts to run in less than one minuite intervals. Add these lines to your router's startup script.

These start the monitoring scripts and backups the database file in 15 minuites intervals. The "sleep 10" is added at the first line to make sure that the router has fully started before running these scripts.

Make sure you change your wrtbwmon location depending on where you place it. I place mine on my SD card. Also change your MAC-to-PCname list's file path accordingly or remove that chain if you're not using it.

Code:

sleep 10

# Load database
cp /mmc/usage.db /tmp/usage.db

# Bandwidth Download/Upload Rate Counter
while :
do
/mmc/wrtbwmon setup
/mmc/wrtbwmon read
sleep 9
/mmc/wrtbwmon update /tmp/usage.db
/mmc/wrtbwmon publish /tmp/usage.db /tmp/www/usage.html /mmc/MAC-PCname.txt
done &

# Backup usage database file
while :
do
sleep 900
cp /tmp/usage.db /mmc/usage.db
done
# If you want to run other codes below this line, use "done &" instead of just "done" on the line above


3) Restart your router and wait for a while. You should be able to see your report page at http://192.168.X.X/user/usage.html where X.X is your router's ip address. The report will look something like this:




Additionally, if you want to password protect this page with your router's password or simply just integrate this page in the Web GUI, see this post: http://www.dd-wrt.com/phpBB2/viewtopic.php?p=468131#468131

Good luck! Very Happy
Feedback much appreciated.

To all scripters/developers/people-of-interest, please let me know how the script can be improved. I can't see any flaws but I doubt it's 100% accurate. However, it's good enough to see where your bandwidth is going and how much of it, live.


Last edited by Wolf Kodi on Sun Aug 01, 2010 4:44; edited 11 times in total
Sponsor
RobotBanana
DD-WRT Novice


Joined: 15 Jul 2010
Posts: 22

PostPosted: Thu Jul 15, 2010 22:46    Post subject: Reply with quote
This looks like it's exactly what I need. Thanks!

Only one problem...

root@DD-WRT:/tmp# sh wrtbwmon setup
: not foundine 26:
: not foundine 28:
wrtbwmon: line 29: syntax error: word unexpected (expecting "in")

I tried issuing the same command with Emmanuel Brucy's original script, and it works fine. Not sure what's going on, but any advice would be appreciated.

I'm running DD-WRT v24-sp2 (11/02/09) std (SVN revision 13064M VINT Eko) on a Linksys WRT54g v1.1.

Thanks.
Wolf Kodi
DD-WRT User


Joined: 13 Jun 2010
Posts: 126

PostPosted: Mon Jul 19, 2010 1:48    Post subject: Updated on 19 July 2010 to improve the script Reply with quote
I've shorten the script, now requiring you to use one piece of startup script only. I've also doubled the time interval to 10 seconds to minimize the load on the processor.

@RobotBanana
The "in" syntax is present and left untouch from Emmanuel Brucy's original script. I'm not sure why you're getting that error. Have you tired running:
Code:
root@DD-WRT:# /tmp/wrtbwmon setup
instead?
RobotBanana
DD-WRT Novice


Joined: 15 Jul 2010
Posts: 22

PostPosted: Mon Jul 19, 2010 2:39    Post subject: Reply with quote
I noticed it was in the original as well, which is what really confused me.

Code:
root@DD-WRT:/tmp# /tmp/wrtbwmon setup
-sh: /tmp/wrtbwmon: not found

root@DD-WRT:/tmp# ls
bcmupnp.pid      dnsmasq.leases   oet              rssiclients.lst
cron.d           etc              ppp              var
crontab          hosts            resolv.conf      wrtbwmon
ddns             igmpproxy.conf   resolv.dnsmasq   www
dnsmasq.conf     loginprompt      root


If I run "sh /tmp/wrtbwmon setup", I get the same error as before.

I tried the new version as well, but no luck.
Wolf Kodi
DD-WRT User


Joined: 13 Jun 2010
Posts: 126

PostPosted: Mon Jul 19, 2010 20:49    Post subject: Reply with quote
No, not run it while you're in /tmp/ folder. Get out to the root directory first by using "cp" like below:

Code:
root@DD-WRT:/tmp# cp
root@DD-WRT:# /tmp/wrtbwmon setup


if you still get errors, try this, also in root directory

Code:
root@DD-WRT:# /bin/sh /tmp/wrtbwmon setup


If all the above still fails, you can try this version with file lock funtions just like the original. I can't see how this helps but who knows? Good luck.

Download: http://www.dd-wrt.com/phpBB2/download.php?id=15506


Last edited by Wolf Kodi on Thu Jul 22, 2010 22:39; edited 2 times in total
RobotBanana
DD-WRT Novice


Joined: 15 Jul 2010
Posts: 22

PostPosted: Tue Jul 20, 2010 2:23    Post subject: Reply with quote
With the regular file:

Code:
root@DD-WRT:~# cp
root@DD-WRT:~# /tmp/wrtbwmon setup
-sh: /tmp/wrtbwmon: not found
root@DD-WRT:~# /bin/sh /tmp/wrtbwmon setup
: not foundon: line 26:
: not foundon: line 28:
/tmp/wrtbwmon: line 29: syntax error: word unexpected (expecting "in")


With the file lock version:

Code:
root@DD-WRT:~# /bin/sh /tmp/wrtbwmon setup
: not foundon: line 26:
: not foundon: line 28:
: not foundon: line 30: {
/tmp/wrtbwmon: line 46: syntax error: word unexpected (expecting "in")
root@DD-WRT:~# cp
root@DD-WRT:~# /tmp/wrtbwmon setup
-sh: /tmp/wrtbwmon: not found


There's gotta be something weird with my installation, because I can't even run scripts the way I've seen people posting in the forums. I'll poke around and see if I can find anything. My guess is the script is fine.

Thanks for trying!
Wolf Kodi
DD-WRT User


Joined: 13 Jun 2010
Posts: 126

PostPosted: Tue Jul 20, 2010 13:00    Post subject: Reply with quote
That's what I thought. Why don't you try upgrading your DD-WRT?
Wolf Kodi
DD-WRT User


Joined: 13 Jun 2010
Posts: 126

PostPosted: Thu Jul 22, 2010 22:47    Post subject: Reply with quote
Hey RobotBanana! GOOD NEWS for you!

Apparently, it was indeed a problem with my script. Not with the scripting but with the way I compiled it. Apparently using Notepad/Wordpad on Windows doesn't work dispite still seeing the same format when I open the file in WinSCP. But if I were to creat a new file using WinSCP and copy and paste this script from Notepad/Wordpad into WinSCP's file editor, it works!

Boy, these sorta problems are hard to detect because the format still looks 100% the same. I discovered this when I again wrote another script and tested it out and I'm getting the same exact errors as you get. lol

So yeah, I've updated both scripts, both with and without lock function. You can go ahead and download the script in the first post and safely use it. I'm sure it working now. Thanks.
RobotBanana
DD-WRT Novice


Joined: 15 Jul 2010
Posts: 22

PostPosted: Fri Jul 23, 2010 0:48    Post subject: Reply with quote
That did the trick! I'm using the version without the lock, and it's now working great. Thanks!
Wolf Kodi
DD-WRT User


Joined: 13 Jun 2010
Posts: 126

PostPosted: Fri Jul 23, 2010 0:57    Post subject: Reply with quote
Glad it's working.
Thanks for pointing out to me.
grant
DD-WRT Novice


Joined: 23 Jul 2010
Posts: 14

PostPosted: Fri Jul 23, 2010 21:01    Post subject: Reply with quote
Thanks for the modded file. Here's my simple setup. Is it fine to backup the file to the jffs folder on the router or would that be far too many write per day?

Quote:
sleep 10

wget ftp://192.168.1.133/wrtbwmon -O /tmp/wrtbwmon && chmod +x /tmp/wrtbwmon

# Load database

wget ftp://192.168.1.133/usage.db -O /tmp/usage.db

# Bandwidth Download/Upload Rate Counter
while :
do
/tmp/wrtbwmon setup
/tmp/wrtbwmon read
sleep 9
/tmp/wrtbwmon update /tmp/usage.db
/tmp/wrtbwmon publish /tmp/usage.db /tmp/www/usage.html
done &

# Backup usage database file
while :
do
sleep 900
cd /tmp && ftpput -u grant -p password 192.168.1.133 usage.db .
done
# If you want to run other codes below this line, use "done &" instead of just "done" on the line above
Wolf Kodi
DD-WRT User


Joined: 13 Jun 2010
Posts: 126

PostPosted: Sat Jul 24, 2010 0:43    Post subject: Reply with quote
Yes, that would be far too many writes per day. It's not advisable to backup to your jffs folder, especially since you can't conviniently replace your Flash memory with a new one. Using a MMC/SD card mod however allows you to replace the card easily. Additionally, current SD cards are capable of enduring more writes.

Which router are you using? You could try looking for the GPIOs and use a MMC/SD card mod. Another option is to use a free ftp host so you don't have to use your own.
grant
DD-WRT Novice


Joined: 23 Jul 2010
Posts: 14

PostPosted: Sat Jul 24, 2010 1:22    Post subject: Reply with quote
I'm using a WRT54Gv4. For some reason when I upload usage.db from the router to my ftp directory, the file is blank and yet I can see the results from 192.168.1.1/user/usage.html.

the uploaded usage.db file is blank.... and yet I can see the results from 192.168.1.1/user/usage.html.

EDIT: Apparently I need to upload in passive mode... which I have no idea how to do from dd-wrt.
grant
DD-WRT Novice


Joined: 23 Jul 2010
Posts: 14

PostPosted: Mon Jul 26, 2010 14:31    Post subject: Reply with quote
I just downloaded 7 GB of data through one computer and the script only detected 1 GB, while the official actual bandwidth consumed page reports the correct amount.
Wolf Kodi
DD-WRT User


Joined: 13 Jun 2010
Posts: 126

PostPosted: Tue Jul 27, 2010 5:35    Post subject: Reply with quote
Can you please clarify what do you mean by "the official actual bandwidth consumed page"?

Do you mean you had both the original and the modified scripts running together at once?
Goto page 1, 2, 3 ... 10, 11, 12  Next Display posts from previous:    Page 1 of 12
Post new topic   Reply to topic    DD-WRT 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