Forum Discussion
The_Bhattman
Jun 08, 2009Nimbostratus
Well you could do it if you assume the fall back is working when there is a LB failure.
The following will trigger everytime the LB_FAILED event is triggered which assumes the fall back host is properly working)
when RULE_INIT {
log local0. "Initialize the count of requests: [STATS::set fallback "current_count" 0]"
set ::count 0
}
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/give-me-stats-baby" } {
set html_content "Fallback StatisticsIncremented the current count to: [STATS::incr fallback 'current_count']"
HTTP::respond 200 content $html_content
}
}
when LB_FAILED {
log local0. "Incremented the current count to: [STATS::incr fallback "current_count"]"
}
The output will be:
Rule stats_rule : Incremented the current count to: 100
You can also go further by adding /give-me-stats-baby it will output the count via HTML. However please be aware that if you reboot or re-initialize the irule it will go straight back to 0. Also keep in mind that I have tested this so there might be some syntax issue but the general logic is there.
Hope this helps,
CB