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?
-
What distribution? – l0c0b0x Aug 12 '09 at 22:19
8 Answers
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.

- 8,365
- 1
- 31
- 44
-
thanks! vnstat shows me just what I need. Very easy setup for vnstat and the php frontend. – jasondewitt Aug 13 '09 at 14:36

- 9,268
- 2
- 24
- 24
-
Check out bandwidthd as well. http://bandwidthd.sourceforge.net/ – David Rickman Aug 13 '09 at 05:42
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

- 83,619
- 74
- 305
- 448
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.

- 96,255
- 29
- 175
- 230
As someone else mentioned, vnstat is a great tool that's easy to setup and should easily give you the information you need.
Note tho, your provider should give you a view into the tool they're using for bandwidth billing. There are multiple ways to track and bill for bandwidth usage (switch port measurements vs. virtual machine counters, 95% percentile vs. total bits sent, sent and received vs. sent only) that will have a substantial impact on your ultimate billing - it's quite important to base things off of the tool that they're using for billing in order to get a true picture of what your bandwidth costs will be. This way, you can accurately take action to shift or minimize your bandwidth usage before you get hit with a major bill for bandwidth.

- 441
- 4
- 3
I use collectd to collect interface traffic counts, amongst other things, and a slightly altered version of this script to generate pretty graphs and counts. The output looks something like this though is quite variable if you have specific preferences as you can see from the rrdtool gallery. If you need more detail than simple interface traffic counts, then you can use the iptables module from collectd to count more specific traffic groups.

- 22,754
- 45
- 67