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

10,155

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

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

Solution 3

  • 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 4

Run sysstat on your server through cron; the network information (sar -n ALL) will give you rxkB/s and txkB/s which you can easily turn into a total traffic figure.

Solution 5

snmp + mrtg / rrdtool (cacti)

Share:
10,155

Related videos on Youtube

jasondewitt
Author by

jasondewitt

some guy

Updated on September 17, 2022

Comments

  • jasondewitt
    jasondewitt almost 2 years

    I have a linux email server that I am thinking about moving into "the cloud". After investigating the pricing I see that my major cost is going to be in bandwidth. How would you guys suggest measuring the total amount of data transferred over a period of time?

  • David Rickman
    David Rickman almost 15 years
    Check out bandwidthd as well. bandwidthd.sourceforge.net
  • jasondewitt
    jasondewitt almost 15 years
    thanks! vnstat shows me just what I need. Very easy setup for vnstat and the php frontend.
  • Travis Bear
    Travis Bear about 10 years
    +1 for simplicity and availability. Nice.