I would like to have a irule that sends back content via
HTTP::respond 200 content $html_content
When a virtual server has hit its connection limit. I’ve seen examples of how to do it on a per member basis but not on a per virtual server but we only have limits set on a virtual server.
I think something like this should work. It’s untested though.
when RULE_INIT {
set ::active_connections 0
set ::max_connections 1000
set ::html_content "over limit"
set ::debug 1
}
when CLIENT_ACCEPTED {
Initialize a variable to track whether we're over the limit
and should send a response from the rule for this request
set over_limit 0
Check if we're over the maximum allowed connections
if {$::active_connections > $::max_connections } {
set over_limit 1
} else {
We're not over the max, so don't respond to the request
incr ::active_connections 1
}
}
when HTTP_REQUEST {
If we're over the limit for this connection, send a response
if {$over_limit}{
Send a response
HTTP::respond 200 content $::html_content
Close the connection
HTTP::close
Log a message to /var/log/ltm if debug is enabled
if {$::debug}{log local0. "Over limit (current/max: $::active_connections/$::max_connections). Sent response to [IP::client_addr]"}
}
}
when CLIENT_CLOSED {
A connection was closed, so decrement the global counter
incr ::active_connections -1
}
Can you try TCP::close instead? Worst case, if you remove the close command altogether and the client makes additional HTTP requests on the same TCP connection after the connection limit is reached, the client will get redirected again.