Procedure based HTML Debug-Page with elapsed time performance data
Problem this snippet solves:
The outlined iRule contains a debugging procedure that can become an useful tool while developing HTTP related iRules.
The debug
[proc]
can be plugged into existing iRules on a position of your choice, to break the iRule execution, collect various informations and display them in a easy to use HTML page. The debug [proc]
is also able to meassure the elapsed time between independent code positions to get a first impression which coding technique performs better than the other.
The debug
[proc]
will store the collected performance data of every single execution in a scaling window session [table]
for statistical calculation. It would output statistical information in a raw format and a #% cuttoff style to filter outliers.
Cheers, Kai
How to use this snippet:
Procedure functionality
To store debugging information use..
set debug(ORIG_HOST) "somedata [HTTP::host] [HTTP::uri]"
To meassure elapsed time between a given starting/ending point...
set time(YOUR_TIMER_NAME1) [clock clicks] ... your code... lappend time(YOUR_TIMER_NAME1) [clock clicks] set time(YOUR_TIMER_NAME2) [clock clicks] ... your code... lappend time(YOUR_TIMER_NAME2) [clock clicks]
To break the iRule execution and display the page...
eval [call YOUR_DEBUG_IRULE_NAME::DEBUGPAGE]
Sample iRule integration...
when HTTP_REQUEST { # # THIS IS JUST AN EXAMPLE CODE TO SHOW HOW THE DEBUG PAGE WORKS # YOU MAY USE YOUR OWN SNIPPETS TO TEST THE FUNCTIONALITY # # # Collect Debug information # # Note: Each debug(name) variable will be listed # in the response HTML page # set debug(ORIG_HOST) [HTTP::host] set debug(ORIG_URI) [HTTP::uri] # # Collect Timestamp information # # Note: Each time(name) variable will be a dedicated perf # counter and included in the HTML response page # # To start a timestamp: # # set time(timestamp_name) [clock clicks] # # To finish a timestamp: # # lappend time(timestamp_name) [clock clicks] # set time(Total) [clock clicks] if { [HTTP::uri] starts_with "/test1" } then { # Test 1: Meassure the time taken to generate a AES key set time(AES_Keygen) [clock clicks] set debug(aes_key) [AES::key 256] lappend time(AES_Keygen) [clock clicks] } elseif { [HTTP::uri] starts_with "/test2" } then { # Test 2: Meassure the time taken to rewrite HOST and URI set time(HOST_URI_rewrite) [clock clicks] HTTP::header replace Host "www.domain.de" HTTP::uri "/somefolder[HTTP::uri]" lappend time(HOST_URI_rewrite) [clock clicks] set debug(NEW_HOST) [HTTP::host] set debug(NEW_URI) [HTTP::uri] } lappend time(Total) [clock clicks] # # EVAL the TCL script fetched from the Debug Page procedure # # Note: The iRule used to store the Debug-Procedure is # "YOUR_DEBUG_IRULE_NAME" with "DEBUGPAGE" proc name. # eval [call YOUR_DEBUG_IRULE_NAME::DEBUGPAGE] }
Code :
when RULE_INIT { # # Proc based Debug-Page with statistical performance counters # # Configure the sample window size set static::sample_frame 60 ;# seconds # Configure the statistical cutoff value to supress outliers set static::sample_cutoff 10;# percent # Stop further iRule processing and TCP::close the connection set static::stop_futher_processing 1;# bolean } proc DEBUGPAGE { return { # # The proc will return a TCL script containing the debug page code. # # Rendering HTML response head/body set temp(http_response) "Debug Page Debug Information
$temp(var) | $debug($temp(var)) |
Last CPU clicks
Counter Name | Last CPU Clicks |
Avg CPU clicks (raw)
Counter Name | Min CPU Clicks | Max CPU Clicks | Avg CPU Clicks | # Samples |
Avg CPU clicks (-$static::sample_cutoff % cutoff)
Counter Name | Min CPU Clicks | Max CPU Clicks | Avg CPU Clicks | # Samples | # Cutoff |
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