We have a customer that is have issues with serveral sources creating loads of connections that brings that application to it’s knees from time to time. We need an iRule that can track how many active connections from sources that currently have more then 10 connections. We have the below iRule that is providing most of what we need but we are trying to get an actual count of the active connections that exceed the threshold number of 10. For some reason we can’t seem to get the total connections value to report out of the array. The logs will show the source IP that exceeds the 10 connection threshold but it logs one more then that threshold and then stops. It never logs more then 11 connections. Here is the current rule. Can you see where our logic is failing?
when RULE_INIT {
array set ::active_clients { }
set conn_threshold 10
}
when CLIENT_ACCEPTED {
set client_ip [IP::remote_addr]
if { [info exists ::active_clients($client_ip)] } {
set total_cons $::active_clients($client_ip)
if {$total_cons > $conn_threshold } {
log local0.info “$client_ip $total_cons using VS [IP::local_addr]”
return
} else {
incr ::active_clients($client_ip)
}
} else {
set ::active_clients($client_ip) 1
}
}
when CLIENT_CLOSED {
if { [info exists ::active_clients($client_ip)] } {
incr ::active_clients($client_ip) -1
if { $::active_clients($client_ip) <= 0 } {
unset ::active_clients($client_ip)
}
}
}