TomatoUSB + Optware + rrdtool + dygraphs = cool bandwidth monitor

04 February 2012 2 minutes

I recently upgraded my Buffalo WHR-HP-G54 to an ASUS RT-N16 as I needed gigabit ethernet; and usb ports + wifi N are all welcoming upgrades to the aging buffalo. As an inevitability, I installed TomatoUSB and plugged in a 4GB USB stick. Now, TomatoUSB itself is a very good system with loads of features but you can extend even more by adding Optware. I will not go into the installation as there already is a very good guide to follow.

Once you have the USB stick mounted and Optware up and running, you can do lots of nifty things. For example, I installed zsh, screen, vim and a whole bunch of other essential stuff. A few examples can be found here.

One particular interest I had when found out about optware was the extension of tomato’s visual bandwidth log graphs. I said extension because the original one comes with tomato has a max 24 hour window. However, occasionally I want to see what happened in the previous week or even month. So first, I thought of rrdtool and rrdgraph. Now rrdtool is a good database for this purpose, however rrdgraph proved to be too resource intensive for the little cpu.

So I searched around and found dygraphs. This is a perfect solution as all you need is to feed the data in csv format and the graphing would be done on the client’s browser. Have a look at my example here (1 week window), you can click&drag the cursor to zoom in and double click to zoom out.

Cool? If you’re interested, let’s start. Assuming you already have a persistent storage (jffs,usb/sd card, etc.) setup at /opt, first, ssh to your router, then:

ipkg update
ipkg install perl rrdtool
wget http://zecoj.com/files/bwg/rrdtool.txt -O /opt/bin/rrdtool.sh
chmod +x /opt/bin/rrdtool.sh
cru a bwlog "*/1 * * * * /opt/bin/rrdtool.sh"

That will install rrdtool, perl and download my rrdtool collector script, put it in the crontab to be executed every 1 minute. Now, create a directory somewhere in your /opt to store the necessary files, mine is at /opt/share/www/cgi-bin.

pwd
/opt/share/www/cgi-bin

wget http://zecoj.com/files/bwg/bandwidth.txt -O bandwidth.cgi
chmod 755 bandwidth.cgi
wget http://zecoj.com/files/bwg/dygraph-combined.js
chmod 644 dygraph-combined.js
rm -rf /tmp/var/wwwext/cgi-bin
ln -s /opt/share/www/cgi-bin /tmp/var/wwwext/.

You should also append the these into /opt/.autorun. This will tell tomato to run these command right after mounting my usb stick.

echo 'cru a bwlog "*/1 * * * * /opt/bin/rrdtool.sh"' >> /opt/.autorun.
echo 'rm -rf /tmp/var/wwwext/cgi-bin' >> /opt/.autorun
echo 'ln -s /opt/share/www/cgi-bin /tmp/var/wwwext/.' >> /opt/.autorun

What just happened is we got the files we need, save them somewhere that will not disappear as the router restart, link them to the router’s cgi-bin directory. Now, assuming the router’s ip is 192.168.0.1, you can test everything by going to: http://192.168.0.1/ext/cgi-bin/bandwidth.cgi there you should already see a few data points collected by rrdtool.sh earlier. Download some big files, leave it running for a while (the page will auto refresh every minute) and you should see more pretty data come up :)


Previous

WHR-HP-G54 and SD card mod

I just got a Buffalo wireless router WHR-HP-G54 a few days ago. It’s small, covers a good range (has a built-in internal amplifier), has decent memory 4MB ROM/16MB RAM and it can be modded to have an sd/mmc card for storage.

Next

XBMC & TV Việt Nam

Plugin này cho phép bạn xem trực tiếp các kênh truyền hình Việt Nam (stream từ servers của VTC) ngay từ giao diện của XBMC mà không cần phải dùng browsers và flash player. Các kênh bao gồm, VTV{1,2,3,4} HTV{7,9} VTC{1,2,10} và 4 tần sóng của Đài TNVN, VOV{1,2,3,5}.