Search code examples
linuxtcpnetstat

Determine average transfer rate on linux system IP interface


I want to know, what the average transfer rate on a particular (VPN) interface of my linux system is.

I have the following info from netstat:

# netstat -i
Kernel Interface table
Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0       1500 0    264453      0      0 0        145331      0      0      0 BMRU
lo        16436 0    382692      0      0 0        382692      0      0      0 LRU
tun0       1500 0     13158      0      0 0         21264      0     12      0 MOPRU

The VPN interface is tun0. So this interface received 13158 packets and sent 21264 packets. My question based on this:

  • what is the time-frame during which these stats are collected? Since the computer was started?

    # uptime
    15:05:49 up 7 days, 20:40,  1 user,  load average: 0.19, 0.08, 0.06
    
  • how to convert the 13158 "packets" to kB of data so as to get kbps?

Or should I use a completely other method?


Solution

  • If you look in /proc/net/dev instead of netstat -i, you can get bytes transmitted/received (also available via ifconfig or netstat -ie, but more easily parsed from /proc/net/dev). The counts are typically since the interface was created, which is usually boot time for "real" interfaces. For a tun interface, it's likely when the tunnel was started, which might be different than system boot, depending on when/how you're creating it...