I discovered how to watch the bandwidth of server today using a tool called bwm-ng. It’s in the Ubuntu Hardy repos, you can install with the following command:
sudo aptitude install bwm-ng
When you run it in a terminal without parameters, it displays a running update of how much bandwidth is being used. This makes it a handy tool to get an immediate idea of what your network traffic is like, and there are also options to examine disk IO. Besides the “live running commentary” mode, it can also output in other forms as well, for example CSV.
To create a poor man’s ntop, i.e. generate a log file of a servers bandwidth throughput over time; I wrote a script that is cronned every minute, the interesting part looks like this:
bwm-ng -o csv -c 6 -T rate -I eth0 >>bandwidth.log
Here‘s a run down of what the parameters do:
- -o csv
- Output to CSV format. Annoyingly you have to download the tarball from the site linked above to get the file which contains the legend for the CSV generated. Why not just include it in the man page? Being the considerate type I have included this information later in this post.
- -c 6
- Print only 6 reads. Not 6 lines, but 6 reads of all the interfaces, including a total line.
- -T rate
- Type rate. Show only the rate, other options for this parameter are avg and max. Without this parameter the output also show amount of data and packets transferred.
- -I eth0
- Comma separated whitelist of interfaces to show. Can also be used to blacklist interfaces. Even with only one interface this still prints a total line.
This generates the something which looks like this:
And as promised the legend for the output:
All this data is then appended to a file called bandwidth.log (