CLI Magic: Monitoring bandwidth from the command line

758

Author: Joe Barr

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.

Category:

  • Linux