Forum Discussion
iRule Issue - Calculate Average Page Response Time using Table Command
I don't have a way to retrieve average response time per page through iControl, so I wrote an iRule to do that. The iRule works fine on my local F5 but not on production. The iRule is attached to a particular virtual server on production with over 1,000 client connections on an average, I was only able to retrieve the average response time through iRule a few times, and then it always returns empty string, not sure why. I can't add logging on production because I have no control over deploying the iRule. Can someone please tell me if they see any issues from the following iRule?
when HTTP_REQUEST {
use virtual server name as subtable name in Table command
set tbl [virtual name]
set requestTime [clock clicks -milliseconds]
flag to track specified page extensions: aspx, ashx, asmx and svc
set track 0
constant threshold to check against and reset accumulated TotalResponseTime value if surpassed. this is a fault tolerance feature to prevent TotalResponseTime becoming too large, and
to enable this iRule to be self-contained and be able to run even if "resetstats" below is never called.
set timeThreshold 3000000
if { ([HTTP::path] ends_with ".aspx") or ([HTTP::path] ends_with ".ashx") or ([HTTP::path] ends_with ".asmx") or ([HTTP::path] ends_with ".svc") }{
set track 1
}
retrieve or reset all key/value pairs stored in a subtable in HTTP_RESPONSE event
set kvPair ""
switch [string tolower [HTTP::uri]]
{
"/getstats"
{
if { [info exists tbl] } {
foreach tkey [table keys -subtable $tbl] {
lappend kvPair "$tkey:[table lookup -notouch -subtable $tbl $tkey]"
}
}
HTTP::respond 200 content $kvPair
}
"/resetstats"
{
if { [info exists tbl] } {
foreach tkey [table keys -subtable $tbl] {
table set -subtable $tbl -mustexist $tkey "" indefinite indefinite
}
}
HTTP::respond 200 content "success"
}
}
}
when HTTP_RESPONSE {
set current page request response time
set curResponseTime [expr {[clock clicks -milliseconds] - $requestTime}]
if { $track == 1 }{
lookup current TotalResponseTime stored in subtable
set storedTotal [table lookup -notouch -subtable $tbl "TotalResponseTime"]
reset values stored in subtable if passed threshold
if { $storedTotal > $timeThreshold }
{
table set -subtable $tbl -mustexist "TotalResponseTime" "" indefinite indefinite
table set -subtable $tbl -mustexist "TotalRequests" "" indefinite indefinite
table set -subtable $tbl -mustexist "AvgResponseTime" "" indefinite indefinite
}
increase TotalResponseTime value in subtable by curResponseTime
set totalResponseTime [table incr -subtable $tbl "TotalResponseTime" $curResponseTime]
increase TotalRequests counter in subtable by 1
set totalRequests [table incr -subtable $tbl "TotalRequests"]
calculate and set AvgResponseTime value in subtable
table set -subtable $tbl "AvgResponseTime" [expr { $totalResponseTime / $totalRequests }] indefinite indefinite
}
}
1 Reply
- danz_123652
Nimbostratus
It looks like I am experiencing intermittent "clock clicks -milliseconds overflow time" issue here, and when that happens, curResponseTime becomes invalid. Still trying to confirm that. Anyone else had that before? Thanks, Dan
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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