Tools such as MRTG provide network throughput / bandwidth graphs for the current network utilisation on specific interfaces, such as eth0. How can I return that information at the command line on Linux/UNIX?
Preferably this would be without installing anything other than what is available on the system as standard.
If you want just to get the value, you can use simple shell oneliner like this:
It will show you the average "received bytes per second" for period of 10 seconds (you can change period by changing
S=10
parameter, and you can measure transmitted BPS instead of received BPS by usingtx_bytes
instead ofrx_bytes
). Don't forget to changeeth0
to network device you want to monitor.Of course, you are not limited to displaying the average rate (as mentioned in other answers, there are other tools that will show you much nicer output), but this solution is easily scriptable to do other things.
For example, the following shell script (split into multiple lines for readability) will execute offlineimap process only when 5-minute average transmit speed drops below 10kBPS (presumably, when some other bandwidth-consuming process finishes):
Note that
/sys/class/...
is Linux specific (which is ok as submitter did chooselinux
tag), and needs non-archaic kernel. Shell code itself is /bin/sh compatible (so not only bash, but dash and other /bin/sh implementations will work) and /bin/sh is something that is really always installed.Besides iftop and iptraf, also check:
bwm-ng
(Bandwidth Monitor Next Generation)and/or
cbm
(Color Bandwidth Meter)ref: http://www.powercram.com/2010/01/bandwidth-monitoring-tools-for-ubuntu.html
nload is a great tool for monitoring bandwidth in real time and easily installed in Ubuntu or Debian with sudo apt-get install nload.
Another excellent tool is iftop, also easily apt-get'able:
Don't forget about the classic and powerful sar and netstat utilities on older *nix!
iftop does for network usage what top(1) does for CPU usage
-- http://www.ex-parrot.com/~pdw/iftop/I don't know how "standard" iftop is, but I was able to install it with
yum install iftop
on Fedora.You can use iperf to benchmark network performance (maximum possible throughput). See following links for details:
http://en.wikipedia.org/wiki/Iperf
https://iperf.fr/
https://code.google.com/p/iperf/
dstat
- Combines vmstat, iostat, ifstat, netstat information and moreiftop
- Amazing network bandwidth utility to analyse what is really happening on your ethnetio
- Measures the net throughput of a network via TCP/IPinq
- CLI troubleshooting utility that displays info on storage, typically Symmetrix. By default, INQ returns the device name, Symmetrix ID, Symmetrix LUN, and capacity.send_arp
- Sends out an arp broadcast on the specified network device (defaults to eth0), reporting an old and new IP address mapping to a MAC address.EtherApe
- is a graphical network monitor for Unix modeled after etherman. Featuring link layer, IP and TCP modes, it displays network activity graphically.iptraf
- An IP traffic monitor that shows information on the IP traffic passing over your network.More details: http://felipeferreira.net/?p=1194