wrtbwmon: A Bandwidth Monitoring Tool for OpenWRT Routers

Years ago, I wrote about the various tools available for monitoring bandwidth usage for individual devices in a home network.

Now, I have a definitive solution that will help with the questions: wrtbwmon. This is based on several variants that are floating around the internet, each a fork of another.

Here is an excerpt from the README file:

Description
===========
OpenWRT Bandwidth Monitor (wrtbwmon) is a lightweight, efficient, yet feature rich bandwidth monitor for routers running OpenWRT.

Have you ever asked yourself the following questions:

- "What is eating up bandwidth in my home/office?",
- "Who uses the most bandwidth?",
- "Who is downloading stuff all the time",
- "Are malware infected computers on my network eating up bandwidth?"

If you asked yourself these questions, but never had the data to formulate an answer, then this script is for you.

The OpenWRT Bandwidth Monitor provides the following:
- Logs the number of kilobytes that each device uses per hour, day and month for upload and download
- Stores the above data for at least a year.
- Displays a graph of comparative device usage per hour, day, and month.
- Uses very little system resources (CPU and storage).

Requirements
============
OpenWRT Version:
----------------
Your router must be running a recent version of OpenWRT. This version of
wrtbwmon was successfully tested with bleeding edge r39729 built in February
2014, and with Barrier Breaker 14.07 stable release. It was not tested with
12.09.

External Storage:
-----------------
This version assumes that you have a permanent storage device to store the data on your router. The best case is that your router has a USB port, and you install the packages necessary for USB storage, and configure the router to automatically mount the USB disk on boot.

To configure USB storage for OpenWRT follow the instruction here: http://goo.gl/j4DU3B

If your router does not have a USB port, and you have an external server, you may be able to store the script and the data on a remote file system using NFS, SAMBA or SSHFS. There is more overhead for this approach vs. using a USB storage device, specially with NFS.

You can read about how to configure network file system clients on OpenWRT here: http://wiki.openwrt.org/doc/howto/client.overview

The version I use for wrtbwmon is attached below this article, as a gzipped tar archive. Please read the included README.txt file and follow the instructions to get it installed.

Further Reading

Contents: 

Tags: 

AttachmentSize
File wrtbwmon.tgz9.88 KB

Comments

nice blog

It is really a very good blog and also i want to tell you that you can visit us if you want to energize your self :)
thanks !!!

wrtbwmon for openwrt

I have successfully installed wrtbwmon on a ext4 formatted USB partion, and I can now see the graph and data updating.
Unfortunately the host names do not appear, only the MAC addresses.

I have edited the wrtbwmon script to refer DNSMASQ_CONF to the /etc/dhcp.leases file by changing the line below.
DNSMASQ_CONF="/tmp/etc/dnsmasq.conf"
to read
DNSMASQ_CONF="/tmp/dhcp.leases"
although this did not work.

When looking at my dnsmasq.conf file, there is no mention of host names in there. Do I need to change any settings in the openwrt web interface via LUCI?? I'm sure this is something simple, but my linux knowledge is not great. Please bear this in mind with any response. Many thanks in advance.

The way I did it ...

The way I did it had nothing to do with editing any of the dnsmasq files.

What I did was assign every MAC address on the network a static IP address and a name. Do do this go into the LuCI admin interface, and under "Network", select "DHCP and DNS". Then under "Static Leases" select the MAC address of the device, and assign a Hostname to it. In my case I assign an IP address as well, but that may not be necessary.

Try it that way, and it should work.

wrtbwmon openwrt

I recently posted a problem displaying Device Names on the wrtbwmon chart.html page. I now have this working.
The solution was
(i) to change the 1st line below to remove all of the commas and the IFS= statement, and
(ii) add a second '=' sign in the second line.

egrep -o "([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2},[^,]+,[^,]+" $DNSMASQ_CONF | while IFS=, read MAC IP NAME
changed to
egrep -o "([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2} [^ ]+ [^ ]+" $DNSMASQ_CONF | while read MAC IP NAME

and
if [ "${NAME}" = "*" ]; then
changed to
if [ "${NAME}" == "*" ]; then

I'm unsure whether it was action (i) or (ii) that resolved this, however it is all working now :-)

Works on Designated Driver

Changing line 286 to instead use Strum's new egrep was all I needed to do to present hostnames. Using Designated Driver r48631 / LuCI (git-16.034.34990-8ae57f6) on a Linksys EA4500 v1.

Thanks for this script. Please consider pushing it to GitHub.

Addedum

I neglected to mention that I added the following to wrtbwmon.conf:

USERSFILE="/tmp/etc/dnsmasq.conf"
BASE_DIR="/mnt/share/opt/wrtbwmon"

Designated Driver r48631 / LuCI (git-16.034.34990-8ae57f6)

Does wrtbwmon allow one to

Does wrtbwmon allow one to filter out local traffic? The reason I am using bandwidthd right now is that one can specify a pcap filter in /etc/bandwidth.conf and ensure that local traffic is not counted in the usage tallies.

For example, this is the relevant line in /etc/bandwidthd.conf (assuming your router is assigning IPs in the 192.168.2.X range):
filter "ip and not((src net 192.168.2.0/24) and (dst net 192.168.2.0/24))"

No

No.

Wrtbwmon is very simple, and does not have such feature. Maybe it can be added. If you do, please send me the changes (use the contact form from the top menu).

Bandwidthd has much more features, but it is CPU intensive from what I read.

Badly needed utility. Packaging as an OpenWRT/LEDE package?

Thanks for your skill and generosity, Khalid! That's just what I needed, so I can keep an eye on bandwidth use per device.

I think this is a need shared by many users among the advanced crowd using OpenWRT or LEDE; so have you ever thought of submitting it to be included in the packages feed?

That would be nice: it would give your software visibility and more widespread use. In addition, it would make it easier to integrate it automatically in one's build (just tick it in menuconfig), and to track updates (a simple implied make download would take care of checking for, and inserting, new versions as they come out).

Thank you again!