Sekhar
Feb 24, 2015Nimbostratus
Moving traffic from VIP to VIP
Hi,
How can I move 10% of traffic from a VIP
Requirement:
moving 10% of traffic from to www.abc.com and www.xyz.com
Thanks,
Sekhar
Hi Sekharchandra,
the following iRule is hopefully doing what you try to accomplish. Please replace the relevant values for hostnames to redirect to and the ratio values.
Turn off logging, if it works as expected. Please keep in mind, that there is no default pools needs to be associated with this iRule and there is no healthchecking considered.
No need to modify anything in the context of HTTP_REQUEST.
when RULE_INIT {
set servername to use for responses (default will be "BIGip"), turned off with "noserver" switch in HTTP::respond
set static::srvname "ServerLB"
set redirect code (301=moved permanently, 302=moved temporarily)
set static::statcode 301
set server ratio values
set static::ratioA 1
set static::ratioB 9
set server hostnames
set static::hostA "www.serverA.bit"
set static::hostB "www.serverB.bit"
activate logging (0=disabled, 1=enabled)
set static::debugRatioLb 1
}
when HTTP_REQUEST {
if { [expr {[table incr req_counter]%[expr {$static::ratioA+$static::ratioB}]}] < $static::ratioA } {
values from 0 to less than ratioA will be directed to serverA
if { $static::debugRatioLb > 0 } {
log local0. "total counter: <[table lookup req_counter]>; modulo <[expr {[table lookup req_counter]%[expr {$static::ratioA+$static::ratioB}]}]> match ratio <$static::ratioA>"
}
HTTP::respond $static::statcode noserver server $static::srvname Location http://$static::hostA[HTTP::uri]
return
} else {
values greater than ratioA will be directed to serverB
if { $static::debugRatioLb > 0 } {
log local0. "total counter: <[table lookup req_counter]>; modulo <[expr {[table lookup req_counter]%[expr {$static::ratioA+$static::ratioB}]}]> match ratio <$static::ratioB>"
}
HTTP::respond $static::statcode noserver server $static::srvname Location http://$static::hostB[HTTP::uri]
return
}
}
The iRule is designed for two target servers only but can be easily enhanced.
Thanks, Stephan