Hmm. This is sort of working, but maybe one of the gurus can explain an odd bit of behavior I'm seeing.
when HTTP_REQUEST {
log local0. "rule starting, count is: [STATS::get counter "counter"] "
if {[STATS::get counter "counter"] == 40} {
reset the clock
STATS::set counter "counter" 0
log local0. "Clock was reset to 0."
}
if {[STATS::get counter "counter"] == 33} {
HTTP::redirect http://www.google.com
log local0. "redirect issued!"
}
STATS::incr counter "counter"
log local0. "Incremented the current count to: [STATS::get counter "counter"]"
}
I have a stats profile called "counter" with a single field in it, also called "counter". What I see in the logs sort of indicates that the number isn't being incremented correctly - a CMP issue, perhaps?
Nov 12 14:55:35 v10bigip tmm tmm[5000]: Rule redirect_some_percent : Incremented the current count to: 1
Nov 12 14:55:39 v10bigip tmm1 tmm1[5001]: Rule redirect_some_percent : rule starting, count is: 40
Nov 12 14:55:39 v10bigip tmm1 tmm1[5001]: Rule redirect_some_percent : Clock was reset to 0.
Nov 12 14:55:39 v10bigip tmm1 tmm1[5001]: Rule redirect_some_percent : Incremented the current count to: 1
Nov 12 14:55:47 v10bigip tmm tmm[5000]: Rule redirect_some_percent : rule starting, count is: 1
Nov 12 14:55:47 v10bigip tmm tmm[5000]: Rule redirect_some_percent : Incremented the current count to: 2
Nov 12 14:55:50 v10bigip tmm1 tmm1[5001]: Rule redirect_some_percent : rule starting, count is: 1
Nov 12 14:55:50 v10bigip tmm1 tmm1[5001]: Rule redirect_some_percent : Incremented the current count to: 2
At 33, the request to google was issued as expected.
Notice that it stayed 1 for 2 iterations there. In the final rule, we'd want to basically roll through a 0-99 count, then issue the redirect 3 times, at 33, 66 and 99 for example. This is sort of a quick proof of concept, but it's pretty close. It's possible that it could be tightened up considerably, speed- and efficiency-wise.
JQ