Get network interface transfer rate on Linux

How can I get the current network interface transfer rate on a Linux box? I’ve been asked this question many times. There’re many ways to get this kind of info, and we’ll show some examples.

1, Using the command sar
Sar comes in the package sysstat which can be installed smoothly via yum/apt-get. When you have it ready, the network interface throughput statistics can be collected by the command below:

$ sar -n DEV 1 3
Linux 2.6.18-194.el5 (localhost.localdomain)    10/27/2010

02:40:56 PM     IFACE   rxpck/s   txpck/s   rxbyt/s   txbyt/s   rxcmp/s   txcmp/s  rxmcst/s
02:40:57 PM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:40:57 PM      eth0  10700.00   1705.05 15860765.66 124250.51      0.00      0.00      0.00
02:40:57 PM      eth1      0.00      0.00      0.00      0.00      0.00      0.00      0.00

02:40:57 PM     IFACE   rxpck/s   txpck/s   rxbyt/s   txbyt/s   rxcmp/s   txcmp/s  rxmcst/s
02:40:58 PM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:40:58 PM      eth0   8051.00   1438.00 11849206.00 105356.00      0.00      0.00      0.00
02:40:58 PM      eth1      0.00      0.00      0.00      0.00      0.00      0.00      0.00
...

2, Using nload – http://sourceforge.net/projects/nload/

You can either download the source code, compile it by yourself, or install it via yum/apt-get. It has an option to view traffic details in command-line GUI.
Additionally it can display transfer rate in a more real-time mode by defining the refreshing interval. It seems to not being maintained actively anymore.

3, Using the perl script nettraf.pl https://www.admon.org/tools/nettraf.pl
You can download the script and run it directly. It just reads from /proc/class/net/$dev/statistics every second, and prints out the current numbers and the average rate of change.

[joseph@admon tools]# perl nettraf.pl -i eth0
 (eth0) *         input         *             output
    time  kbytes  packets  Merrs  kbytes  packets  Merrs    colls
16:48:40       3       35      0      33       28      0        0
16:48:41       3       21      0      35       30      0        0
16:48:42       4       35      0      88       66      0        0
16:48:43       3       48      0     150      109      0        0

A similar perl script is available at stackoverflow.com, it did exactly the same thing.

4, Lots of other tools
Like iptraf, iftop and bwm-ng.

Share Button

Leave a comment

Your email address will not be published. Required fields are marked *