Forum Discussion
Response time iRule error
If your goal is to simply check the server's response time to a request, I'm including a small snippet of what I have done in the past.
Probably the best time to capture the actual response time is between HTTP_REQUEST_SEND and HTTP_RESPONSE.
ltm profile statistics DELAY_STAT {
field1 total
field2 webtest_total
field3 webtest_slow
field4 webtest_fast
}
ltm rule LOG-Delay {
when RULE_INIT {
what is a slow response in milliseconds
set static::slow_response 2000
}
when HTTP_REQUEST_SEND {
STATS::incr DELAY_STAT total
clientside {
if {[string tolower [HTTP::host]] contains "onpoint342labupgrade2013"} {
STATS::incr DELAY_STAT webtest_total
set URL [string tolower [HTTP::host]][HTTP::uri]
set SENT [clock clicks -milliseconds]
}
}
}
when HTTP_RESPONE {
exit event if variable is not set
if {![info exists SENT]} { return }
set TIME [expr {[clock clicks -milliseconds] - $SENT}]
if {$TIME >= $static::slow_response} {
STATS::incr DELAY_STAT webtest_slow
log local0. "[HTTP::status]: Client [IP::client_addr]; \
Server [IP::server_addr]:[TCP::server_port]; URL ${URL}; Time ${TIME}ms"
} else {
STATS::incr DELAY_STAT webtest_fast
}
unset SENT URL TIME
}
}
As long as HTTP pipelining is not being used, and hopefully it's not, this would be fine.
Notes
- If you expect a lot of logging, I recommend using HSL instead of the log command.
- I'm not logging every bit of information, you can add as needed.
- You should check out the request logging profile on the F5. It may be able to accomplish what you are looking for without an iRule, though I don't think you can control which URLs it is logging.
- I added STATS to track all/slow/fast requests. You would need to add the stats profile to the virtual server for it to work. In the past, I have found it handy to see how many requests were fast vs slow at a glance. Additional STATS fields can be added fairly easily to track other things without requiring you to sift through log messages.
- The delay between HTTP_REQUEST_SEND and HTTP_RESPONSE may not include the total response time. The HTTP_RESPONSE event fires when the F5 has received the complete HTTP header, which is not always the same as the response contents.
- RSpangler_17032Mar 27, 2017
Nimbostratus
This looks promising. Never setup and request logging profile. Is there a step by step doc somewhere?
- Jeremy_Church_3Mar 29, 2017
Cirrus
Hello,
In the F5 GUI, there are field names listed in the help tab on the left.
I find it easier to search for request logging on the internet. F5 documentation on request logging, though I am not sure about a step-by-step doc.
It is really not complicated, but I have found the GUI configuration is buggy, at least in the version I was using. If you configure a Request Logging profile in the GUI, then list it in the CLI, you will know if there is a problem. If configured in the GUI, the F5 will save line breaks in the config if the fields listed do not fit on a single line. To work around this, I copy the config, remove the line breaks and merge the profile back into the CLI.
- RSpangler_17032Apr 03, 2017
Nimbostratus
OK, I found how to setup the Request Logging but it doesn't seem to be working for me. I know I'm not doing something right just haven't figured it out yet.
I do have the iRule working but now I'm trying to figure out how I can get it to only log for the URL that I want and not every URL that comes through the VS. do you have an idea how I can accomplish this?
This is the iRule I am using:
when HTTP_REQUEST { set CLIENT_ADDR [IP::client_addr] set XFF [HTTP::header X-Forwarded-For] set ID "[TCP::local_port][expr { int(100000000 * rand()) }]" set REQUEST_RECEIVE [clock clicks -milliseconds] set HST "[HTTP::host]" set URI "[HTTP::uri]" } when HTTP_REQUEST_SEND { set REQUEST_SEND [clock clicks -milliseconds] set REQUEST_WAIT [expr {$REQUEST_SEND - $REQUEST_RECEIVE}] log local0. "SRC:$CLIENT_ADDR XFF:$XFF ID:$ID HST:$HST'/'$URI" } when HTTP_RESPONSE { set RESPONSE_TIME [expr {[clock clicks -milliseconds] - $REQUEST_SEND}] log local0. "SRC:$CLIENT_ADDR XFF:$XFF ID:$ID HST:$HST$URI - HTTP[HTTP::status] $RESPONSE_TIME\ms/$REQUEST_WAIT\ms [LB::server addr]" }I want to somehow tell this to log only if the URL is ex. website1.com log if it is website2.com ignore as they will both come into the same VS on the F5.
- RSpangler_17032Apr 05, 2017
Nimbostratus
Jeremy,
I also tried your code above but I get an error when trying to save it:
Exception caught in LocalLB::urn:iControl:LocalLB/Rule::create() Exception: Common::OperationFailed primary_error_code : 17236305 (0x01070151) secondary_error_code : 0 error_string : 01070151:3: Rule [/Common/Responce-times3] error: /Common/Responce-times3:2: error: [undefined procedure: ltm][ltm profile statistics DELAY_STAT { field1 total field2 webtest_total field3 webtest_slow field4 webtest_fast }] - Jeremy_Church_3Apr 05, 2017
Cirrus
Hello,
What I gave was not the rule by itself, but a configuration that can be merged. I provided it that way because the iRule is tracking statistics which requires a separate stats profile that must also be applied to the virtual server.
Also, the iRule I wrote has a check in HTTP_REQUEST_SEND to only track time requests.
- RSpangler_17032Apr 05, 2017
Nimbostratus
Jeremy,
Thank you for the reply. Sorry but I'm not a programmer. I learn a lot by doing and seeing how someone else has done what I'm trying to do. The error above looks like the LTM doesn't understand the procedure:
error: [undefined procedure: ltm][ltm profile statistics DELAY_STAT {
How can I get this to work or best bet would be to get my iRule above to work so that it only logs the URL that I want and not everything.
Thanks.
- Jeremy_Church_3Apr 06, 2017
Cirrus
Correct, ltm is not a procedure. You are receiving the error because you are attempting to paste what I provided into the F5 web interface as an iRule. It is not an iRule.
This is configuration for a profile:
ltm profile statistics DELAY_STAT { field1 total field2 webtest_total field3 webtest_slow field4 webtest_fast }What I provided is not iRule code, it's a snippet of configuration in tmsh format which includes both a statistics profile and an iRule.
What you are attempting to paste into the F5 is not an iRule, it is a snippet of configuration.
Here is the iRule configuration, not the iRule code:
ltm rule LOG-Delay { when RULE_INIT { what is a slow response in milliseconds set static::slow_response 2000 } when HTTP_REQUEST_SEND { STATS::incr DELAY_STAT total clientside { if {[string tolower [HTTP::host]] contains "onpoint342labupgrade2013"} { STATS::incr DELAY_STAT webtest_total set URL [string tolower [HTTP::host]][HTTP::uri] set SENT [clock clicks -milliseconds] } } } when HTTP_RESPONE { exit event if variable is not set if {![info exists SENT]} { return } set TIME [expr {[clock clicks -milliseconds] - $SENT}] if {$TIME >= $static::slow_response} { STATS::incr DELAY_STAT webtest_slow log local0. "[HTTP::status]: Client [IP::client_addr]; \ Server [IP::server_addr]:[TCP::server_port]; URL ${URL}; Time ${TIME}ms" } else { STATS::incr DELAY_STAT webtest_fast } unset SENT URL TIME } }If you want to use exactly what I provided, you would need to log into the CLI and run the command load sys config merge from-terminal. If you are not familiar with this process and its implications, I strongly recommend taking the time to understand how it works.
If you want to just paste in the iRule and do not care about the stats, here is just the iRule code without the STATS::incr command.
when RULE_INIT { what is a slow response in milliseconds set static::slow_response 2000 } when HTTP_REQUEST_SEND { clientside { if {[string tolower [HTTP::host]] contains "onpoint342labupgrade2013"} { set URL [string tolower [HTTP::host]][HTTP::uri] set SENT [clock clicks -milliseconds] } } } when HTTP_RESPONE { exit event if variable is not set if {![info exists SENT]} { return } set TIME [expr {[clock clicks -milliseconds] - $SENT}] if {$TIME >= $static::slow_response} { log local0. "[HTTP::status]: Client [IP::client_addr]; \ Server [IP::server_addr]:[TCP::server_port]; URL ${URL}; Time ${TIME}ms" } unset SENT URL TIME }Is that what you are looking for?
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