OpenVZ Forum


Home » General » HowTo » Bandwidth Accounting for VPS
Bandwidth Accounting for VPS [message #187] Mon, 03 October 2005 13:29 Go to next 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

Re: Bandwidth Accounting for VPS [message #1325 is a reply to message #187] Mon, 06 February 2006 20:54 Go to previous messageGo to next message
Emitkins is currently offline  Emitkins
Messages: 7
Registered: February 2006
Junior Member
If you would like create a file called ip.sh
chmod +x ip.sh
edit the SUBNET1 FIRST1 AND LAST1

subnet1 being your 1st 3 rangs numbers.
first1 being your 1st ip
last1 being your last ip
Hope this saves everyone some time
#! /bin/sh -x
IPTABLES="/sbin/iptables"
EXTERNAL_INTERFACE="eth0"
SUBNET1="72.2.23"
FIRST1=129
LAST1=254

I=$FIRST1;

while [ $I -le $LAST1 ]; do
$IPTABLES -A FORWARD -o $EXTERNAL_INTERFACE -s $SUBNET1.$I
$IPTABLES -A FORWARD -i $EXTERNAL_INTERFACE -d $SUBNET1.$I

let I=$I+1;
done;
Re: Bandwidth Accounting for VPS [message #2045 is a reply to message #1325] Thu, 16 March 2006 14:20 Go to previous messageGo to next message
jbond007 is currently offline  jbond007
Messages: 78
Registered: January 2006
Location: Miami
Member
Nice job
how can limited traffic bandwhit from VPS

example vps 101 total bandwhit use 50 GB !

please post the iptables code
Razz
Re: Bandwidth Accounting for VPS [message #2060 is a reply to message #2045] Fri, 17 March 2006 15:25 Go to previous messageGo to next message
Emitkins is currently offline  Emitkins
Messages: 7
Registered: February 2006
Junior Member
I use tc this however will only limit outgoing bandwidth
see the full description here.
http://www.docum.org/docum.org/tests/htb/parent/

tc qdisc add dev venet0 root handle 1: cbq bandwidth 10Mbit cell 8 avpkt 1000 mpu 64

tc filter add dev venet0 parent 1:0 protocol ip prio 5 handle 1: u32 divisor 1

tc class add dev venet0 parent 1:0 classid 1:1 cbq bandwidth 1Mbit rate 1Mbit avpkt 1000 prio 5 bounded isolated allot 1514 weight 1 maxburst 21

tc filter add dev venet0 parent 1:0 prio 5 u32 match ip src 255.255.255.255 flowid 1:1
(255.255.255.255 is the ip you want to rate limit)
Re: Bandwidth Accounting for VPS [message #2061 is a reply to message #2060] Fri, 17 March 2006 15:35 Go to previous messageGo to next message
jbond007 is currently offline  jbond007
Messages: 78
Registered: January 2006
Location: Miami
Member
Relly good this call comunitid !

dear please make one sample of setup let say

vps 101
give 50 gb bandwhit

how your setup te vps 101 for 50gb
Please respond ASAP
Re: Bandwidth Accounting for VPS [message #2064 is a reply to message #2061] Fri, 17 March 2006 16:26 Go to previous messageGo to next message
Emitkins is currently offline  Emitkins
Messages: 7
Registered: February 2006
Junior Member
There are no tools that i am aware of that do what your asking, you can only limit the speed to allow the set amount of bandwidth. With openvz anyways, i know that the vituozzo settings are easier for bandwidth however that is not free.
Pperhaps there is someone else that can suggest and idea or solution.
Re: Bandwidth Accounting for VPS [message #2073 is a reply to message #2064] Fri, 17 March 2006 22:25 Go to previous message
jbond007 is currently offline  jbond007
Messages: 78
Registered: January 2006
Location: Miami
Member
how you think manage the Speed ?

vzctl set ?

--numtcpsock items[:items]
Maximum number of TCP sockets. This parameter limits the number of TCP connections and, thus, the number of clients the server application can handle in parallel. Setting the barrier and the limit to different values does not make practical sense.
--numothersock items[:items]
Maximum number of non-TCP sockets (local sockets, UDP and other types of sockets). Setting the barrier and the limit to different values does not make practical sense

or

--tcpsndbuf bytes[:bytes]
Maximum size of TCP send buffers. Barrier should be not less than 64 KB, and difference between barrier and limit should be equal to or more than value of numtcpsock multiplied by 2.5 KB.
--tcprcvbuf bytes[:bytes]
Maximum size of TCP receive buffers. Barrier should be not less than 64 KB, and difference between barrier and limit should be equal to or more than value of numtcpsock multiplied by 2.5 KB.





right ?

[Updated on: Fri, 17 March 2006 22:26]

Report message to a moderator

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


Current Time: Sun Apr 28 04:57:49 GMT 2024

Total time taken to generate the page: 0.02543 seconds