Posted: Fri Jul 09, 2010 5:10 Post subject: Per-user Live Down/Upload Rate Monitoring [No PC needed!]
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.
# 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:
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
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.
Posted: Mon Jul 19, 2010 1:48 Post subject: Updated on 19 July 2010 to improve the script
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:
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.
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.
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.
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?
# 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
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.
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.
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.