How to get current bandwidth usage from command line using built-in Linux tools?

11

4

I'm looking for a good way to get the current total bandwidth usage on a linux machine. I’ve tried iftop, nethogs, but they don’t show real bandwidth usage compared to system monitor; they don’t suit the needs of my project. I want a command which I execute and it returns the current usage for upload and download and nothing else.

I would like also to do it with native Linux tools without installing anything. In fact I’m making a monitoring application, and I want it to be able to monitor computers without the need to install something in each computer the user wants to monitor, that would be great!

Xsmael

Posted 2014-07-07T17:55:48.983

Reputation: 239

Very similar question: http://superuser.com/questions/328702/linux-get-single-bandwidth-usage-sample

– mrucci – 2014-07-07T18:42:57.740

Answers

5

Use iptraf - http://www.linuxcommand.org/man_pages/iptraf8.html

It's an ncurses based commandline utility which is able to give you statistics on all interfaces on the machine - including bandwidth usage.

Andrew

Posted 2014-07-07T17:55:48.983

Reputation: 479

1not built-in tool – Nicolas Thery – 2019-04-18T09:45:14.867

2

There's a lot of tools you can use: nload, bmon, iftop, vnstat, ifstat... and if you want to just get a specific part of their output (for example, upload and download), I'm pretty sure that you can grep/cut/awk the output to make it work for you.

18 commands to monitor network bandwidth on Linux server

jimm-cl

Posted 2014-07-07T17:55:48.983

Reputation: 1 469

bmon worked for me in Ubuntu, giving me the present TX and RX of every interface, and a simple graph of the last 60 seconds. – Leopoldo Sanczyk – 2017-10-03T04:06:06.623

1not built-in tool – Nicolas Thery – 2019-04-18T09:45:23.210

2

sysstat collects network stast as well. If you do a "man sar" you will see all the resources you can keep historical data for.

Set it up by putting in cron the command "/usr/lib/sa/sa1" (or /usr/lib64/sa/sa1) and have it run each time you want a data point (e.g. every 5 minutes)

Then you can use "sar" to view your data. Default is today. You can also view historical data for up to 30 days. You can also archive your data off so you can keep it forever (each day's data is about 8mb).

For networking, you would use "sar -n"

Wonderful tool :)

An example:

 testlinux:~ # sar -n DEV | head -10
 Linux 2.6.16.60-0.21-default (pCITFileSvr01)    11/07/10

 00:00:01        IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
 00:05:01           lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
 00:05:01         eth0      9.95      0.12      1.42      0.02      0.00      0.00      0.00
 00:10:01           lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
 00:10:01         eth0     10.20      0.04      1.44      0.00      0.00      0.00      0.00
 00:15:01           lo      0.00      0.00      0.00      0.00      0.00       0.00      0.00
 00:15:01         eth0     10.32      0.12      1.50      0.02      0.00      0.00      0.00
 00:20:01           lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
 testlinux:~ #

ben

Posted 2014-07-07T17:55:48.983

Reputation: 166

1not built-in tool – Nicolas Thery – 2019-04-18T09:45:29.357