Forum Discussion
ebeng_278441
Aug 31, 2016Altocumulus
Log the count of the STREAM hits
I'm trying to figure out how it will be possible, how many times a
STREAM::expression
is being executed.
when HTTP_RESPONSE {
if { $http_host equals "avv.com" or $http_host equals "acc.com" }{
STREAM::expression "@aa@bb@"
STREAM::expression "@rr@ff"
STREAM::expression "@gg@qaqa@"
STREAM::enable
log local0. "RESPONSE: $http_host to IP: [IP::client_addr]"
}
}
So in the log i want to see like:
Total STREAM hit 80 (40aa - 20rr - 20gg)
Hi Ebeng,
you can count the individual
hits using the[STREAM::expression]
event. But its not that easy to accumulate the total hit numbers, since STREAM happens after theSTREAM_MATCHED
event. You have to accumulate the hit numbers either on the very nextHTTP_RESPONSE_RELEASE
(if keep-alive is used) or onHTTP_REQUEST
.CLIENT_CLOSE
You may take a look to the iRule below. It will count the individual STREAM hits and finally accumulate the results.
when STREAM_MATCHED { set stream_result(path) $http_path if { [info exists stream_result(Pattern:[STREAM::match])] } then { incr stream_result(Pattern:[STREAM::match]) } else { set stream_result(Pattern:[STREAM::match]) 1 } } when HTTP_REQUEST { set http_path [HTTP::path] if { [info exists stream_result(path)] } then { set stream_result(match_total) 0 log local0.debug "Debug [array names stream_result Pattern:*]" foreach stream_result(pattern) [array names stream_result Pattern:*] { incr stream_result(match_total) $stream_result($stream_result(pattern)) append stream_result(match_detailed) "( $stream_result(pattern) = $stream_result($stream_result(pattern)) | " } log local0.debug "STREAM hits on URL $stream_result(path): $stream_result(match_total) [string trimright $stream_result(match_detailed) " |"] )" unset -nocomplain stream_result } } when CLIENT_CLOSED { if { [info exists stream_result(path)] } then { set stream_result(match_total) 0 log local0.debug "Debug [array names stream_result Pattern:*]" foreach stream_result(pattern) [array names stream_result Pattern:*] { incr stream_result(match_total) $stream_result($stream_result(pattern)) append stream_result(match_detailed) "( $stream_result(pattern) = $stream_result($stream_result(pattern)) | " } log local0.debug "STREAM hits on URL $stream_result(path): $stream_result(match_total) [string trimright $stream_result(match_detailed) " |"] )" unset -nocomplain stream_result } }
Note: Keep in mind, that you can't specify multiple STREAM::expression during HTTP_RESPONSE. But you can combine multiple expression into a single STREAM::expression (e.g.
STREAM::expression "@aa@bb@@rr@ff@@gg@qaqa@")
Cheers, Kai
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects