Usage Details on DD-WRT Router
I’ve been looking for a while for a simple way to add usage statistics of all IPs on my network, so I can see which PC / User is using all the bandwidth.
This example was done on my router a ASUS RT-N16
Firmware Version: DD-WRT v24-sp2 (11/21/10) big (SVN revision 15778)
You will need to login to the router via SSH to complete all the following configurations. To do this what you will need depends on the system you are connecting from:
MAC OSX — Nothing, Can be done from a terminal window
Linux — Nothing, Can be done from a terminal window (as long a SSH installed)
Windows — SSH Client required, I would suggest Putty
Settings that need to be enabled on the router via the web gui:
– Administration -> Management -> Web Access -> Enable Info Site -> “Enable”
– Administration -> Management -> JFFS2 Support -> JFFS2 -> “Enable”
Now you need to confirm that your router has all the correct applications installed, these will will be used by the script during its normal execution. The list of commands can be found on this page, under the heading of “Required Packages and Commands”.
When I ran this on my router the only one that did not run as expected was:
echo "3 + 7" | bc
To resolve this I needed to install the package and this was done by running the following commands, as guided by this:
ipkg update wget http://downloads.openwrt.org/kamikaze/8.09.2/brcm47xx/packages/bc_1.06.94-1_mipsel.ipk ipkg -d root install bc_1.06.94-1_mipsel.ipk
Open your terminal application and connect to the router via ssh, I was using Mac OSX so the following commands are based around my usage
ssh root@<IP ADDRESS>
Once prompted for your password key that in and you should now be connected.
Now your connected we need to store the scripts and files in a location that will be persistent with each reboot. And this location is the JFFS2 that you enabled earlier on.
mkdir /jffs/www cd /jffs/www
The next thing to do is to download the latest version of the scripts from this page. The latest version at time of writing this was “1.3_wrt-bandwidth-statistics”.
To download run the following commands:
wget http://lal-projects.googlecode.com/svn/tags/major/1.3_wrt-bandwidth-statistics/bw_monitor.sh wget http://lal-projects.googlecode.com/svn/tags/major/1.3_wrt-bandwidth-statistics/monitor.html wget http://lal-projects.googlecode.com/svn/tags/major/1.3_wrt-bandwidth-statistics/bw_monitor.startup
Now we need to create a symlink to map the /www/user directory to the new /jffs/www directory that we have just created.
ln -sf /jffs/www /www/user
For some reason the symlink above does not seem to work correctly so the link to the new application will be:
But before we get to using the application, we need to configure it and set it up to run.
For the next part you will need to “vi” text editor, if you do not know how to use this please research, this example will not explain how to you vi.
You will need to change the following line, it was line 92 in my html file:
This needs to change to:
Now you will need to create the .startup script that the router will run when starting. This can be either a .startup script or a .wanup script depending on when you want it run. I created mine as a .startup, which means it starts before the firewall and wan connection are connected.
The .startup script needs to be located in a certain directory and this directory is /jffs/etc/config/, if you place it in this directory the dd-wrt firmware will run it on startup.
The script you need to create is done in the following way:
mkdir /jffs/etc mkdir /jffs/etc/config vi /jffs/etc/config/bw_monitor.startup
Then insert the following text in to this script, please review all settings and configurations that you would like at this location
#!/bin/sh MONITOR_LOCK_FILE=/tmp/monitor-started.lock MONITOR_STOP_FILE=/tmp/monitor-stop MONITOR_STOPPED_FILE=/tmp/monitor-stopped ln -sf /jffs/www /www/user while [ ! -f $MONITOR_LOCK_FILE ] && [ ! -f $MONITOR_STOP_FILE ]; do /jffs/www/bw_monitor.sh 30 3 30 4 /tmp/dnsmasq.conf /jffs/monitor/usage.backup /jffs/monitor/history/ /jffs/monitor/usage.db /jffs/www/ 1 1 1 1 1 0 1 if [ ! -f $MONITOR_LOCK_FILE ]; then sleep 10 fi done
You will need to edit this line depending on the parameters you want to run
/jffs/www/bw_monitor.sh 30 3 30 4 /tmp/dnsmasq.conf /jffs/monitor/usage.backup /jffs/monitor/history/ /jffs/monitor/usage.db /jffs/www/ 1 1 1 1 1 0 1
If you have used the exact script I created above, we will need to create some directories
mkdir /jffs/monitor mkdir /jffs/monitor/history
The scripts that have now been created need to be set executable and this is done as follows
chmod +x /jffs/www/bw_monitor.sh chmod +x /jffs/etc/config/bw_monitor.startup
Now we can test the script and all the settings we have created by running the script we just created manually
cd /jffs/etc/config ./bw_monitor.startup
You should now be able to open a browser and see the usage on the screen
The last step is to reboot the router and make sure that the startup script is ran and the system start to log the information.
To check in the system is running, after the router has rebooted go this directory and if this file exists then it is running:
cd /tmp/ ls
If this files exists “monitor-started.lock” the it is running.