Linux.com

Feature: Linux

CLI Magic: Monitoring bandwidth from the command line

By Joe Barr on March 13, 2006 (8:00:00 AM)

Share    Print    Comments   

Volker Gropp's enhanced bandwidth monitor -- called bwm-ng, or Bandwidth Monitor Next Generation -- is a rewrite of an earlier bwm. It's simple to install and use, and I recently found it to be very helpful in getting data I needed for a story. You might find it useful,

User Level: Intermediate
In addition to the source code, you can find distro-specific installation packages for Gentoo, Ubuntu, Sourcemage, Red Hat, SUSE, and Debian on the project Web site.

I had to add the libstatgrab package in order to install bwm-ng on SUSE 10 from the RPM.

If you compile from source, it's as easy as the familar ./configure;make;make install mantra. bwm-ng has not made into the Ubuntu Dapper repositories yet, so that's what I did to compile the latest release.

bwm-ng does not need superuser privileges to run. The command to start the monitor can be as simple as bwm-ng. The first time I ran it, I got a screen like this:


 bwm-ng v0.5 (probing every 0.500s), press 'h' for help
  input: /proc/net/dev type: rate
  -       iface                  Rx                   Tx                Total
  ===========================================================================
            lo:           0.00 KB/s            0.00 KB/s            0.00 KB/s
          eth0:           0.00 KB/s            0.00 KB/s            0.00 KB/s
  ---------------------------------------------------------------------------
         total:           0.00 KB/s            0.00 KB/s            0.00 KB/s

As you can see, not much activity was going on, but that was fine, as what I needed to learn was the bandwidth consumption of an Asterisk SIP phone call. After connecting a call, I saw this on the bwm-ng real-time display at the console:

  bwm-ng v0.5 (probing every 0.500s), press 'h' for help
  input: /proc/net/dev type: rate
  |       iface                  Rx                   Tx                Total
  ===========================================================================
            lo:           0.00 KB/s            0.00 KB/s            0.00 KB/s
          eth0:          20.51 KB/s           20.51 KB/s           41.02 KB/s
  ---------------------------------------------------------------------------
         total:          20.51 KB/s           20.51 KB/s           41.02 KB/s

Bingo! bwm-ng showed me exactly what I needed to know. To learn what other options might be available, I pressed "h" for help, which produced this screen:

 ┌─bwm-ng v0.5 - Keybindings:───────────────────────────────────────────────┐
 │                                                                          │
 │ 'h'  show this help                                                      │
 │ 'q'  exit                                                                │
 │ '+'  increases timeout by 100ms                                          │
 │ '-'  decreases timeout by 100ms                                          │
 │ 'd'  switch KB and auto assign Byte/KB/MB/GB                             │
 │ 'a'  cycle: show all interfaces, only those which are up,                │
 │             only up and not hidden                                       │
 │ 's'  sum hidden ifaces to total aswell or not                            │
 │ 'n'  cycle: input methods                                                │
 │ 'u'  cycle: bytes,bits,packets,errors                                    │
 │ 't'  cycle: current rate, max, sum since start, average for last 30s     │
 │                                                                          │
 └─ press any key to continue... ───────────────────────────────────────────┘

I played with the "d," "u," and "t" options to cycle through the various ways the program can display results. Each time I did, the monitor quickly changed metrics and displayed the new data without so much as a blink.

You can cycle input too, though I am not sure this is something I would ever need to do. The input source seems to be driven more by the platform bwm-ng is running on than anything else: proc for Linux, getifaddrs for BSD, kstat for Solaris, and so on.

You also have choices for the type of output you want: curses is the default and it's what allows you to drive the monitor's real-time display by pressing keys; plain ASCII is available too for those poor souls without curses; and you can opt for HTML as well, making it easy to check the monitor from across the Web.

bwm-ng can handle as many interfaces as your PC can. By default, it shows all interfaces, but you override that by specifying which you want to see in a comma-separated list using the -I option, or which you do not want to see by using a % sign before the first interface in the list.

You can also drive bwm-ng from a config file instead of the command line if you prefer. For additional info, consult man, the sample config file, and the README in your installation directory or docs, depending on how you installed the program.

Share    Print    Comments   

Comments

on CLI Magic: Monitoring bandwidth from the command line

Note: Comments are owned by the poster. We are not responsible for their content.

iptraf

Posted by: Anonymous Coward on March 13, 2006 05:38 PM
Check <a href="http://iptraf.seul.org/about.html" title="seul.org">IPtraf</a seul.org>

#

Re:iptraf

Posted by: Administrator on March 27, 2006 11:05 PM
Best thing about IPTraf is that it is included with a lot of distributions and starts without any hassles.

#

Network monitor for processes?

Posted by: Anonymous Coward on March 13, 2006 05:41 PM
Is there any tool that not only allows you to see the network activity for each interface, but also see the network activity for each process?

#

Re:Network monitor for processes?

Posted by: Anonymous Coward on March 14, 2006 03:56 AM
I wrote a simple 'top' for networking that splits the TCP traffic per process. It requires root and only works on linux.

<a href="http://nethogs.sf.net/" title="sf.net">http://nethogs.sf.net/</a sf.net>

Let me know if you have any problems or whatever.

#

Re:Network monitor for processes?

Posted by: Anonymous Coward on March 15, 2006 12:24 PM
Nice program - thanks for this. Only thing is, I had to install libpcap0.8-dev in Debian to get it to compile (missing pcap.h).

#

Re:Network monitor for processes?

Posted by: Anonymous Coward on March 16, 2006 12:26 AM
Glad you like it. I added a note about libpcap to the webpage.

#

Perfect!

Posted by: Anonymous Coward on March 13, 2006 08:10 PM
This is *exactly* what I needed for monitoring some stats on my server. Simple, no muss, no fuss, and it works! Thanks for the article!

#

Remote Router

Posted by: Anonymous Coward on March 13, 2006 09:47 PM
More frequently, I need to monitor traffic across our gateway (router) rather than my local box.

For that I basically do:
<tt>  one=`snmpget 192.168.0.1 ifInOctets`
  while true; do
    sleep 1
    two=`snmpget ifInOctets`
    echo "($two - $one) * 8" | bc
    one=$two
  done</tt>
and<nobr> <wbr></nobr>/Voila!/ it gives me a running display of bits per second. [In reality, I track ifOutOctets as well, of course -- and "snmpget" requires more arguments. Fleshing that out is left as an exercise for the reader.]

#

An Alternative

Posted by: Anonymous Coward on March 14, 2006 01:47 AM
Another similar program is <a href="http://trash.net/~reeler/bmon/" title="trash.net">http://trash.net/~reeler/bmon/</a trash.net>

#

Dapper Drake

Posted by: Anonymous Coward on March 14, 2006 05:50 AM
I found that bwm-ng is now in Dapper Drake, if you edit<nobr> <wbr></nobr>/etc/apt/sources.list and enable the universe and backport repository lines by removing the "#" in front of them. Nice little utility - thank you for writing about it!

#

non root

Posted by: Anonymous Coward on March 14, 2006 07:16 AM
If you want something that you can run as a user and only has a single dependency (python) checkout ethstats.

<a href="http://precision.org/code/ethstats/ethstats.py" title="precision.org">http://precision.org/code/ethstats/ethstats.py</a precision.org>

Nothing to install, no fuss no muss.

#

nmon is a great tool

Posted by: Anonymous Coward on March 14, 2006 08:43 AM
I would also recommend looking at nmon
<a href="http://www-941.haw.ibm.com/collaboration/wiki/display/WikiPtype/nmon" title="ibm.com">http://www-941.haw.ibm.com/collaboration/wiki/dis<nobr>p<wbr></nobr> lay/WikiPtype/nmon</a ibm.com>

#

iftop

Posted by: Anonymous Coward on March 15, 2006 12:11 PM
<a href="http://www.ex-parrot.com/~pdw/iftop/" title="ex-parrot.com">iftop</a ex-parrot.com> is good one too. If you use debian, you can use apt-get.

#

libstatgrab

Posted by: Anonymous Coward on April 21, 2006 07:08 AM
Hi,

Thanks for you nice review. Just one note: libstatgrab is only optional on linux, but there was a ugly typo in the example config file, so<nobr> <wbr></nobr>/proc/net/dev support does not work with it (either remove or fix that line in the config file please). I guess thats why many packages need libstatgrab.

Volker Gropp

#

Try nload

Posted by: Administrator on March 15, 2006 05:19 AM
I have using Nload on FreeBSD 6 box, works great, give a try...:)

<a href="http://www.roland-riegel.de/nload/index.html?lang=en" title="roland-riegel.de">http://www.roland-riegel.de/nload/index.html?lang<nobr>=<wbr></nobr> en</a roland-riegel.de>

"Theres no "linux for dummies", linux its already for dummies"
Inu

#

CLI Magic: Monitoring bandwidth from the command line

Posted by: Anonymous [ip: 124.253.137.22] on February 23, 2008 01:35 PM
how to design a minial bandwidth monitoring tool using linux shell scripting, in which i can use linux conmmmands?
mail me at combat009@rediffmail.com

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya