iRule to count individual STREAM::expression hits
Problem this snippet solves:
Hi Folks,
the provided iRule below can be used to count and analyse individual
STREAM::expression
hits.
Imagine you have some more of less interesting HTML content that needs several content rewrites...
"On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks. When you create pictures, charts, or diagrams, they also coordinate with your current document look." -MSOffice
... and you apply a
STREAM::expression
with lots of individual translations to it...
STREAM::expression @a@A@@b@B@@c@C@@d@D@@e@E@@f@F@@g@G@@h@H@@i@I@@j@J@@k@K@@l@L@@m@M@@n@N@@o@O@@p@P@@q@Q@@r@R@@s@S@@t@T@@u@U@@v@V@@w@W@@x@X@@y@Y@@z@Z@
... then you could use the iRule below to
[log]
which individual expression has been triggered how many times on which ressource.
Thu Sep 8 16:07:43 CEST 2016 debug f5-02 tmm[16579] STREAM hits on URL /stream: 271 ( Pattern:p = 2 | ( Pattern:a = 18 | ( Pattern:r = 21 | ( Pattern:b = 4 | ( Pattern:c = 13 | ( Pattern:s = 19 | ( Pattern:d = 12 | ( Pattern:t = 28 | ( Pattern:u = 12 | ( Pattern:e = 36 | ( Pattern:f = 2 | ( Pattern:v = 2 | ( Pattern:w = 2 | ( Pattern:g = 6 | ( Pattern:h = 12 | ( Pattern:y = 4 | ( Pattern:i = 15 | ( Pattern:k = 3 | ( Pattern:l = 14 | ( Pattern:m = 5 | ( Pattern:n = 15 | ( Pattern:o = 26 )
Cheers, Kai
How to use this snippet:
- Attach the provided iRule to your Virtual Server which performs [STREAM] operations
- Request the streamed content as usual.
- Take a look to your LTM logfile.
Code :
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 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 -noname 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 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 -noname local0.debug "STREAM hits on URL $stream_result(path): $stream_result(match_total) [string trimright $stream_result(match_detailed) " |"] )" unset -nocomplain stream_result } }
Tested this on version:
12.0Updated Jun 06, 2023
Version 2.0Kai_Wilke
My name is Kai Wilke and I'm working as a Principal Consultant for IT-Security at itacs GmbH - a German consulting company specialized in Microsoft Security cloud solutions, F5 customizations as well as for classic IT-Consulting.
You can find additional information about me and my work here:
https://devcentral.f5.com/articles/q-a-with-itacs-gmbhs-kai-wilke-devcentrals-featured-member-for-february-24890MVP
No CommentsBe the first to comment