OpenVZ Forum


Home » General » Support » How to limit traffic per vps?
Re: How to limit traffic per vps? [message #31651 is a reply to message #31580] Fri, 04 July 2008 14:01 Go to previous messageGo to previous message
silentninja is currently offline  silentninja
Messages: 37
Registered: September 2007
Member
This is my script.

- Modification: I've added an if so if the vps has 768 ram, It gets a 256kbit limit and if the vps has a higher limit 512kbit limit.
- Modification: The SHAPEIPS gets filled with the IP's on the vz conf files automatically.
- Modification: I've changed the total ammount of the webserver to 4mbit since I cannot afford 100mbit like your example and even if all 8 vps has 512kbit limit, it should never go further the 4mbits.

This is my script:

#!/bin/bash

IFSPEED="4mbit"
SHAPEIPS=`grep IP_ADDRESS /etc/vz/conf/* | cut -d\" -f2 | sed 's/ /\n/'`
STARTSHAPECLASS=10

addtc()
{
        tc qdisc del dev $DEV root
        tc qdisc add dev $DEV root handle 1: htb
        tc class add dev $DEV parent 1: classid 1:1 htb rate "$IFSPEED" burst 15k quantum 60000
        SHAPECLASS=$STARTSHAPECLASS
        for IP in `echo "$SHAPEIPS"`
        do
                if [ `grep "IP_ADDR" /etc/vz/conf/* | grep "$IP" | cut -d: -f1 | xargs -iFILE grep VMGUAR FILE | grep -c 768` -eq 1 ]; then SPEEDLIMIT="256kbit"; else SPEEDLIMIT="512kbit"; fi;
                tc class add dev $DEV parent 1:1 classid 1:"$SHAPECLASS" htb rate "$SPEEDLIMIT" quantum 3000
                SHAPECLASS=$(($SHAPECLASS+1))
        done
        SHAPECLASS=$STARTSHAPECLASS
        for IP in `echo "$SHAPEIPS"`
        do
                tc filter add dev $DEV protocol ip parent 1:1 prio 1 u32 match ip $1 "$IP" flowid 1:"$SHAPECLASS"
                SHAPECLASS=$(($SHAPECLASS+1))
        done
}

# Trafico saliente
DEV="eth0"
addtc src
# Trafico entrante
DEV="venet0"
addtc dst

[Updated on: Fri, 04 July 2008 14:02]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: [solved] 3ware 9690SA and 2.6.18-53.1.19.el5.028stab053.14
Next Topic: Xfce Openvz
Goto Forum:
  


Current Time: Thu Jul 24 22:48:37 GMT 2025

Total time taken to generate the page: 0.24825 seconds