Forum Discussion
iRule logging HTTP/SSL session times
script I'm running is as follows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
when CLIENT_ACCEPTED {
Get time for start of TCP connection in milleseconds
set tcp_start_time [clock clicks -milliseconds]
}
when HTTP_REQUEST {
Get time for start of HTTP request
if {[HTTP::uri] ends_with ".html"} {
set url [HTTP::host][HTTP::uri]
set content_type [HTTP::header Content-Type]
set http_request_time [clock clicks -milliseconds]
} elseif {[HTTP::uri] ends_with ".htm"} {
set url [HTTP::host][HTTP::uri]
set content_type [HTTP::header Content-Type]
set http_request_time [clock clicks -milliseconds]
} elseif {[HTTP::uri] ends_with ".cgi"} {
set url [HTTP::host][HTTP::uri]
set content_type [HTTP::header Content-Type]
set http_request_time [clock clicks -milliseconds]
}
log "URL:$url "
}
when HTTP_RESPONSE {
Get time for end of HTTP request
set http_response_time [clock clicks -milliseconds]
set node [IP::server_addr]:[TCP::server_port]
}
when CLIENT_CLOSED {
set close_time [clock clicks -milliseconds]
set http_time [expr $close_time - $http_response_time]
set tcp_time [expr $close_time - $tcp_start_time]
Log the end time of the TCP connection
if {![info exists $url]} {
log "Content:$content_type URL:$url Client:[IP::client_addr] VIP:[IP::local_addr]:[TCP::local_port] Node:$node (HTTP response time $http_time ms) (TCP open for: $tcp_time ms) "
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
My issue is that the script keeps spitting out errors in the log
Any help is appreciated
regards
John Zammit
- hooleylistCirrostratusHi John,
- Michael_YatesNimbostratusI've had to create a similar iRule to measure the entire Client Connection as well as the individual HTTP Requests made by that client in their connection.
when CLIENT_ACCEPTED { Get time for start of TCP Connection in milliseconds set tcp_start_time [clock clicks -milliseconds] Log the start of a new HTTP Request set local0. "(TCP Connection - Start) [IP::client_addr]:[TCP::client_port] to [IP::local_addr]:[TCP::local_port]" } when HTTP_REQUEST { Get time for start of HTTP Request in milliseconds set http_request_time [clock clicks -milliseconds] Log the start of new HTTP Request with URI set LogString "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::uri]" Log the start of new HTTP Request without URI set LogString "Client [IP::client_addr]:[TCP::client_port]" log local0. "(HTTP - Request) $LogString" } when HTTP_RESPONSE { Recieved the response headers from the server. Log the pool name, IP and port, status and time delta Detailed Log Output - Client Communication - Pool Information - Status Messages - and Communication Delta log local0. "(Response) $LogString - pool info: [LB::server] - status: [HTTP::status] (Request / Response Delta: [expr [clock clicks -milliseconds] - $http_request_time]ms)" Response and Communication Delta log local0. "(HTTP - Response) $LogString - (Request / Response Delta: [expr [clock clicks -milliseconds] - $http_request_time]ms)" } when CLIENT_CLOSED { Log the end time of the TCP Connection Detailed Connection Closed - Transaction can be located by using the Client IP Address and Port to Load Balancer IP Address and Port for additional matching parameters. log local0. "(TCP Connection - Close) $LogString [IP::client_addr]:[TCP::client_port] to [IP::local_addr]:[TCP::local_port] (Connection Open for: [expr [clock clicks -milliseconds] - $tcp_start_time]ms)" }
- hooleylistCirrostratusThanks for that Michael. Note that you can save some CPU cycles by wrapping expr operands in curly braces (which prevents double substitution of the variables):
- Michael_YatesNimbostratusHadn't thought about that.
- Michael_YatesNimbostratusI made Aaron's suggested modifications and retested the functionaltiy. There was an error in the original. This works fine.
- Michael_YatesNimbostratus
when CLIENT_ACCEPTED { Get time for start of TCP Connection in milliseconds set tcp_start_time [clock clicks -milliseconds] Log the start of a new HTTP Request set local0. "(TCP Connection - Start) [IP::client_addr]:[TCP::client_port] to [IP::local_addr]:[TCP::local_port]" } when HTTP_REQUEST { Get time for start of HTTP Request in milliseconds set http_request_time [clock clicks -milliseconds] Log the start of new HTTP Request with URI set LogString "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::uri]" Log the start of new HTTP Request without URI set LogString "Client [IP::client_addr]:[TCP::client_port]" log local0. "(HTTP - Request) $LogString" } when HTTP_RESPONSE { Recieved the response headers from the server. Log the pool name, IP and port, status and time delta Detailed Log Output - Client Communication - Pool Information - Status Messages - and Communication Delta log local0. "(Response) $LogString - pool info: [LB::server] - status: [HTTP::status] (Request / Response Delta: [expr {[clock clicks -milliseconds] - $http_request_time}]ms)" Response and Communication Delta log local0. "(HTTP - Response) $LogString - (Request / Response Delta: [expr {[clock clicks -milliseconds] - $http_request_time}]ms)" } when CLIENT_CLOSED { Log the end time of the TCP Connection Detailed Connection Closed - Transaction can be located by using the Client IP Address and Port to Load Balancer IP Address and Port for additional matching parameters. log local0. "(TCP Connection - Close) Client [IP::client_addr]:[TCP::client_port] to [IP::local_addr]:[TCP::local_port] (Connection Open for: [expr {[clock clicks -milliseconds] - $tcp_start_time}]ms)" }
- Nicola_DTNimbostratus
Hi, just fix line 7
set local0. "(TCP Connection - Start) [IP::client_addr]:[TCP::client_port] to [IP::local_addr]:[TCP::local_port]"
}
to
log local0. "(TCP Connection - Start) [IP::client_addr]:[TCP::client_port] to [IP::local_addr]:[TCP::local_port]"
}
Cheers, Nicola
when CLIENT_ACCEPTED { Get time for start of TCP Connection in milliseconds set tcp_start_time [clock clicks -milliseconds] Log the start of a new HTTP Request set local0. "(TCP Connection - Start) [IP::client_addr]:[TCP::client_port] to [IP::local_addr]:[TCP::local_port]" } when HTTP_REQUEST { Get time for start of HTTP Request in milliseconds set http_request_time [clock clicks -milliseconds] Log the start of new HTTP Request with URI set LogString "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::uri]" Log the start of new HTTP Request without URI set LogString "Client [IP::client_addr]:[TCP::client_port]" log local0. "(HTTP - Request) $LogString" } when HTTP_RESPONSE { Recieved the response headers from the server. Log the pool name, IP and port, status and time delta Detailed Log Output - Client Communication - Pool Information - Status Messages - and Communication Delta log local0. "(Response) $LogString - pool info: [LB::server] - status: [HTTP::status] (Request / Response Delta: [expr {[clock clicks -milliseconds] - $http_request_time}]ms)" Response and Communication Delta log local0. "(HTTP - Response) $LogString - (Request / Response Delta: [expr {[clock clicks -milliseconds] - $http_request_time}]ms)" } when CLIENT_CLOSED { Log the end time of the TCP Connection Detailed Connection Closed - Transaction can be located by using the Client IP Address and Port to Load Balancer IP Address and Port for additional matching parameters. log local0. "(TCP Connection - Close) Client [IP::client_addr]:[TCP::client_port] to [IP::local_addr]:[TCP::local_port] (Connection Open for: [expr {[clock clicks -milliseconds] - $tcp_start_time}]ms)" }
- Nicola_DTNimbostratus
Hi, just fix line 7
set local0. "(TCP Connection - Start) [IP::client_addr]:[TCP::client_port] to [IP::local_addr]:[TCP::local_port]"
}
to
log local0. "(TCP Connection - Start) [IP::client_addr]:[TCP::client_port] to [IP::local_addr]:[TCP::local_port]"
}
Cheers, Nicola
- hooleylistCirrostratusThat looks better :). Can you post sample log output so others can see what the logging looks like for a request/response and connection?
- Michael_YatesNimbostratusThese are a few lines of the log output. They have been sanitized, but it give a basic view of the type of information that the above iRule will provide by default.
Mar 14 15:54:27 local/tmm info tmm[4903]: Rule irule.name : (HTTP - Request) Client 192.168.1.100:15251 -> /website/common/scripts/confirmit.js Mar 14 15:54:27 local/tmm info tmm[4903]: Rule irule.name : (HTTP - Response) Client 192.168.1.100:15251 -> /website/common/scripts/confirmit.js - (Request / Response Delta: 7ms) Mar 14 15:54:27 local/tmm info tmm[4903]: Rule irule.name : (HTTP - Request) Client 192.168.1.100:15252 -> /website/Style/Scripts/mbox.js Mar 14 15:54:27 local/tmm info tmm[4903]: Rule irule.name : (HTTP - Response) Client 192.168.1.100:15252 -> /website/Style/Scripts/mbox.js - (Request / Response Delta: 4ms) Mar 14 15:54:27 local/tmm info tmm[4903]: Rule irule.name : (TCP Connection - Close) Client 192.168.1.100:54635 to 192.168.1.101:80 (Connection Open for: 2068ms)
- John_Zammit_459NimbostratusThanks for the replies so far am going to test out aarons script first thing in the morning
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