Home > DD-WRT > Usage Details on DD-WRT Router

Usage Details on DD-WRT Router

February 4th, 2014

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 project on code.google

This example was done on my router a ASUS RT-N16
Firmware Version: DD-WRT v24-sp2 (11/21/10) big (SVN revision 15778)

Step 1

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

Step 2

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”

Step 3

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 

Step 4

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.

Step 5

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

Step 6

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

Step 7

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

Step 8

For some reason the symlink above does not seem to work correctly so the link to the new application will be:

http://IP ADDRESS/user/www/monitor.html

Step 9

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.

vi /jffs/www/monitor.html

You will need to change the following line, it was line 92 in my html file:


This needs to change to:

src=’http://IP ADDRESS/user/www/user_details.js’

Step 10

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

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

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

Step 11

If you have used the exact script I created above, we will need to create some directories

mkdir /jffs/monitor 
mkdir /jffs/monitor/history

Step 12

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

Step 13

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

Step 14

You should now be able to open a browser and see the usage on the screen

http://IP ADDRESS/user/www/monitor.html

Step 15

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/

If this files exists “monitor-started.lock” the it is running.

  1. Adrian
    March 27th, 2014 at 11:45 | #1

    Hi Dan,
    I followed your tutorial and I could like at this:
    Refresh in Stop Start
    Internet Usage Cap: [USAGE_CAP] GB
    Internet Usage Resets on day [RESET_DAY] of Every Month

    0 bytes
    0 bytes
    0 bytes

    Day Usage (Defaults to current day)


    Monthly Usage – Daily Breakdown
    User Total Down/Up
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

    Monthly Usage – Summary

    Monthly Usage – Breakdown

    Looks very good for a start. However, I need to see some numbers. USAGE-CAP & RESET DAY are empty, I guess I need to initialize them somehow. Hyperlinks don’t work. The numbers on the report screen don’t change. What I am doing wrong? I am using Firefox and the router is using this: Firmware: DD-WRT v24-sp2 (06/08/12) mini. Linksys.

    • April 3rd, 2014 at 00:08 | #2


      I hope my response to your other comment assists you with this issue.


  2. Adrian
    March 28th, 2014 at 04:01 | #3

    The script seems to be running. However, I had to manually start it.
    I do not see the file that indicates ok (monitor-started.lock). Below is what I got.
    root@Main Gate:~# cd /tmp/
    root@Main Gate:/tmp# ls
    cron.d etc nvram udhcpc
    crontab hosts oet udhcpc.expires
    dnsmasq.conf igmpproxy.conf resolv.conf var
    dnsmasq.leases loginprompt resolv.dnsmasq www
    dnsmasq2users.file nas.wl0lan.pid root
    root@Main Gate:/tmp#
    root@Main Gate:/tmp#


    • April 3rd, 2014 at 00:07 | #4


      When I run the same command on mine I get the following:

      root@ROUTER:/tmp# ls
      bcmupnp.pid dnsmasq2users.file loginprompt oet udhcpc
      cron.d etc monitor-started.lock resolv.conf udhcpc.expires
      crontab hosts nas.wl0lan.pid resolv.dnsmasq var
      dnsmasq.conf igmpproxy.conf nvram root www

      Notice the monitor-started.lock

      When you run it manually does this file appear? And the report start to be generated?

      If yes, then the issue will be with your automatic execution of the script. This is all controlled placing the .startup file in the directory /jffs/etc/config/. The file needs to have an extension of .startup or the router will not start the script.

      Apart from this, I’m not sure why it is not working. The only other difference is that I am using “big” version of the firmware and not the “mini”. You may need to do some googling to ensure the startup scripts work the same way on the mini script.


  3. Saad Bashir
    April 16th, 2014 at 21:12 | #5

    Its a nice detailed article. I am trying to install the package to make this command “echo “3 + 7″ | bc” work but unfortunately no success. I tried using wget it said “wget: invalid option — d”. I removed -d and then it says “Connecting to downloads.openwrt.org (” and nothing ever happens even though the internet is working. Secondly I also noticed there is no option to enable JFFS2 “– Administration -> Management -> JFFS2 Support -> JFFS2 -> “Enable”.
    I am using Firmware: DD-WRT v24-sp2 (03/25/13) std.
    Any help in this regard would be highly appreciated.


    • April 29th, 2014 at 22:58 | #6


      I suspect it is due to you using the “std” version of the firmware. But other than that I am not sure.


  4. Cody
    April 17th, 2014 at 08:24 | #7

    I’m having trouble getting the changes I’ve made to save. I have a flash drive and jffs2 enabled. I mount /jffs and run everything. However I’m getting a permission error running ./bw_monitor.startup even though it says it has -x permissions. Did I do something wrong how to I make it persistent and run that file.

  5. Zeeshan
    May 11th, 2014 at 21:40 | #8


    Thanks for this awesome solution. I am able to execute all the steps suggested.
    However the only problem I am seeing is that monitor.html file is unable to display the statistics collected.

    I can see stats collected in files @ /jffs/monitor/usage.backup usage.db but they are not displayed.
    I only see:-

    Internet Usage Cap: [USAGE_CAP] GB
    Internet Usage Resets on day [RESET_DAY] of Every Month

    0 bytes
    0 bytes
    0 bytes

    The Hyperlinks are also working (though they do not have a finger pointer)

    Here is a list of all the files in /jffs

    root@ZeeE2500RM:~# ls -Rl /jffs/
    drwxr-xr-x 3 root root 0 May 11 13:53 etc
    drwxr-xr-x 3 root root 0 May 11 14:24 monitor
    drwxr-xr-x 3 root root 0 May 11 13:47 tmp
    drwxr-xr-x 4 root root 0 May 11 13:47 usr
    drwxr-xr-x 2 root root 0 May 11 17:03 www

    drwxr-xr-x 2 root root 0 May 11 13:57 config

    -rwxr-xr-x 1 root root 467 May 11 13:57 bw_monitor.start

    drwxr-xr-x 2 root root 0 May 11 13:58 history
    -rw-r–r– 1 root root 355 May 11 16:53 usage.backup
    -rw-r–r– 1 root root 355 May 11 17:04 usage.db


    drwxr-xr-x 2 root root 0 May 11 13:47 ipkg


    drwxr-xr-x 2 root root 0 May 11 13:47 bin
    drwxr-xr-x 3 root root 0 May 11 13:45 lib

    -rwxr-xr-x 1 root root 83307 Dec 6 2009 bc

    drwxr-xr-x 4 root root 0 May 11 13:47 ipkg

    drwxr-xr-x 2 root root 0 May 11 13:47 info
    drwxr-xr-x 2 root root 0 May 11 13:45 lists
    -rw-r–r– 1 root root 68 May 11 13:47 status

    -rw-r–r– 1 root root 30 May 11 13:47 bc.list


    -rwxr-xr-x 1 root root 28170 May 11 13:49 bw_monitor.sh
    -rw-r–r– 1 root root 555 May 11 13:49 bw_monitor.start
    -rw-r–r– 1 root root 27118 May 11 13:52 monitor.html
    -rw-r–r– 1 root root 87825 May 11 17:03 user_details.js

    And tmp is:
    root@ZeeE2500RM:~# ls -l /tmp/
    drwx—— 2 root root 0 May 11 14:07 cron.d
    -rw-r–r– 1 root root 0 May 11 14:07 crontab
    -rw-r–r– 1 root root 861 Jan 1 1970 dnsmasq.conf
    -rw-r–r– 1 root root 350 May 11 17:06 dnsmasq.leases
    -rw-r–r– 1 root root 647 May 11 15:30 dnsmasq2users.file
    drwx—— 2 root root 0 Jan 1 1970 etc
    -rw-r–r– 1 root root 291 Jan 1 1970 hosts
    -rw-r–r– 1 root root 206 May 11 14:07 igmpproxy.conf
    -rw-r–r– 1 root root 87 Jan 1 1970 loginprompt
    -rw-r–r– 1 root root 0 May 11 14:07 monitor-started.lock
    -rw-r–r– 1 root root 5 May 11 14:07 nas.wl0lan.pid
    drwx—— 2 root root 0 Jan 1 2000 nvram
    drwxr-xr-x 3 root root 0 May 11 14:07 oet
    -rw-r–r– 1 root root 26 Jan 1 1970 resolv.conf
    -rw-r–r– 1 root root 63 Jan 1 1970 resolv.dnsmasq
    drwx—— 3 root root 0 Jan 1 1970 root
    drwxr-xr-x 8 root root 0 Jan 1 1970 var
    drwx—— 2 root root 0 May 11 14:07 www

    My Router is Cisco/LinkSys E2500 with DD-WRT v24-sp2 (06/08/12) mini

    Please suggest

  6. July 13th, 2014 at 19:16 | #9

    Good way of telling, and nice article to obtain information concerning my presentation topic, which i am going to present in institution of higher education.

  7. Rob
    October 11th, 2014 at 08:53 | #10

    Hi, Thanks for posting this tool, I have installed it, I got the web page to show but with no numbers. I looked at usage.db and it is being populated.
    I running Firmware: DD-WRT v24-sp2 (10/10/09) mini on a Linksys WRT54G/GL/GS

    Any ideas what I can do to get the script to populate the web page?

    • November 3rd, 2014 at 22:04 | #11

      How did you go with this?

      I found that sometimes when looking at the page it would look as no data was present, but if you scrolled to the right you would see the days of the month when data started to be recorded.

Comments are closed.
%d bloggers like this: