OpenVZ Forum


Home » General » HowTo » Bandwidth Accounting for VPS
Bandwidth Accounting for VPS [message #187] Mon, 03 October 2005 13:29 Go to previous message
Ukyo is currently offline  Ukyo
Messages: 2
Registered: October 2005
Location: Dallas
Junior Member

Bandwidth Accounting for VPS

Bandwidth accounting allows you to track bandwidth usage of your VPS.
This is possible using the Linux iptables. You add an iptables entry for
the INBOUND, and OUTBOUND on the FORWARD chain. You can do this
with the following example:

# iptables -A FORWARD -o eth0 -s 10.69.69.201
# iptables -A FORWARD -i eth0 -d 10.69.69.201

Please note that the bandwidth accounting works by IP, not VPSID.
You must have BOTH lines to properly track traffic that is INBOUND as well
as OUTBOUND.

You can view the accounting results with the following command:

# iptables -L FORWARD -v -x

Chain FORWARD (policy ACCEPT 54 packets, 3240 bytes)
pkts bytes target prot opt in out source destination
11 660 all -- any eth0 10.69.69.201 anywhere
11 660 all -- eth0 any anywhere 10.69.69.201

You can also use the following command to only show
accounting information for specific IP 's:

# iptables -L FORWARD -v -x | grep '10.69.69.201'

14 840 all -- any eth0 10.69.69.201 anywhere
14 840 all -- eth0 any anywhere 10.69.69.201


To clear/reset the counters you can use the following command:

# iptables -Z

However, please note that this will simply reset all counters to 0.
If you want to get the latest accounting results before it resets the
counter you can use the following command:

# iptables -L FORWARD -Z -v

Chain FORWARD (policy ACCEPT 60 packets, 3600 bytes)
pkts bytes target prot opt in out source destination
0 0 all -- any eth0 10.69.69.201 anywhere
0 0 all -- eth0 any anywhere 10.69.69.201
Zeroing chain `FORWARD'

Please remember that using these commands will reset the counters for
ALL of your IP Addresses. If you want to just reset a single one, please
delete the counter, and recreate it.

To delete a counter, you use the same line that you created it with, except
you use a -D instead of -A. Here is an example:

# iptables -D FORWARD -o eth0 -s 10.69.69.201
# iptables -D FORWARD -i eth0 -d 10.69.69.201

The iptables WILL be cleared if the server resets.
Once the server restarts you will need to re-create
every counter. I suggest scripting it.



Jon Montroll / CEO
ColoGuys - Colocation, Dedicated Servers & More!
Http://www.ColoGuys.Com
24/7 Toll-Free Support - 1-866-510-5799

[Updated on: Mon, 03 October 2005 13:38]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: iptables Blocking for ALL VEs
Next Topic: Simple script to download rpm files.
Goto Forum:
  


Current Time: Sun May 12 10:37:08 GMT 2024

Total time taken to generate the page: 0.01441 seconds