Measure bandwidth usage (GB's transferred) on a linux server

Solution 1:

I have successfully ran vnstat on servers in the past. It's avaliable packged for fedora & ubuntu (and probably other distros). There is also a php frontend avaliable that's very easy to setup.

Solution 2:

  • ifconfig tells you the usage for an interface, including the amount of data transferred.
  • ntop logs and analyses traffic in a lot of ways.
  • iftop and iptraf show you connections and other data at real time

Solution 3:

If you want the low tech version, you could just cat /proc/net/dev record the time, and then do it again, and calculate it from that. However, be aware that the counter wraps around at 2^32 bytes (4GB) (at least on my recent 32-bit kernels):

Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo:   51433     617    0    0    0     0          0         0    51433     617    0    0    0     0       0          0
  eth0:3270597247 14887385    0    0    0     0          0         0 694109632 7720886    0    0    0     0       0          0
  pan0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0

There is a perl routine to parse this in this blog post of mine: Debuging a script that parses /proc/net/dev