Forum Discussion
PeteWhite
Aug 08, 2016Employee
Changed the iRule to be v11-compliant
when RULE_INIT {
Set a global max for number of concurrent TCP connections
set static::max_connections 2
Set an HTML response to sent to clients who make a request while the VIP is over the max connection count
set static::html_content "over limit"
Print debug messages to /var/log/ltm? 1=yes, 0=no
set static::debug 1
Initialize a counter for active connections (don't modify this)
set static::active_connections 0
}
when HTTP_REQUEST {
If we're over the limit for this connection, send a response
if {$static::active_connections > $static::max_connections}{
Send a response
HTTP::respond 200 content $static::html_content
Close the connection
TCP::close
Log a message to /var/log/ltm if debug is enabled
if {$static::debug}{log local0. "Over limit (current/max: $static::active_connections/$static::max_connections). Sent response to [IP::client_addr]"}
We're not over the limit, so check if this is the first HTTP request on the TCP connection.
} elseif {[HTTP::request_num] == 1}{
set validrequest 1
Increment the TCP connection count.
incr static::active_connections 1
}
}
when CLIENT_CLOSED {
A connection was closed, so decrement the global counter
if {$validrequest == 1}{
incr static::active_connections -1
}
}