How to calculate throughput of particular interface in Linux?

Is there any way to calculate throughput per interface (e.g. eth0) in Linux system using ip command or ifconfig?

I tried bmon, nload - but is it possible to get the same result using some basic Linux command or basic commands in a script?

2

3 Answers

This other answer mentions /proc/net/dev. Below is an example script that roughly calculates "instantaneous" Bps by reading the file twice, (about) 1 second apart, then subtracting:

#!/bin/sh
[ "$#" -eq 1 ] || { printf 'usage: %s interface\n' "$0" >&2; exit 1; }
getstats () { grep "$1": /proc/net/dev
}
{ getstats "$1"; sleep 1; getstats "$1"; } \
| awk '{rcv=$2-rcv; trnsmt=$10-trnsmt} END {print rcv" "trnsmt}'

Example usage (assuming the script is saved as ./showband):

$ ./showband eth0 # the result appears after about 1 second
1272439 535768
$

The numbers are incoming_bytes_per_second outgoing_bytes_per_second.

Tested on Debian 9.

1

You can use the contents of /proc/net/dev:

  • one line per interface
  • first line is a header that explains what the columns are
2

why not use iftop?

sudo yum install iftop
sudo iftop -i eth0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like