Adverts

Here's a little utility that you might find useful or interesting. It's a bandwidth monitoring application that will read /proc/net/dev and report some interesting statistics. You should be able to see it doing its thing a the bottom of this page.

The code is released under the GPL Version 2 license and can be downloaded here: Java Bandwidth Utilization Monitor.

To use the monitor first download and unpack the zip. You should have a bunch of .java files. Incorporate those files into your regular build process (yes, I know I should write an ant script for them and release a binary version as well but I haven't got round to it yet).

Using the bandwidth monitor in your code is as simple as modifying the code snippet below so that it does what you want. In most cases this code should be correct as is. I suggest this code goes in a ServletContextListener:

BandwidthUsageConfiguration configuration = new BandwidthUsageConfiguration();
configuration.setInterfaceName( "eth0" );
configuration.setDelay( 5000 );
BandwidthUsage usage = new BandwidthUsage( configuration );

Bind the BandwidthUsage class created above into the ServletContext then access it in a JSP(X) page like this:

<p class="dark">\${bandwidth_monitor.bandwidthUsage}<br/>
\${bandwidth_monitor.maxBandwidthUsage}<br/>
\${bandwidth_monitor.totalBandwidth}<br/>
Monitoring started: \${bandwidth_monitor.started}</p>

If you like this code please tell me. There are other statistics that I could gather from the information that is available but without a prod I probably won't get round to gathering it. Many thanks to the guys who wrote bwbar (H. Peter Anvin and Brian Towne) which is the inspiration for this project.

You can download the original bwbar program here: http://www.kernel.org/bwbar.html and an advanced version of it here: http://www.mythica.org/bwbar/.

Adverts

Donate and Help

Please support this site and
Bandwidth doesn't grow on trees y' know :o)

Adverts

Get Adsense