Is there a way to specify a condition in apache httpd access_log to persist only requests which took longer than 500ms to process?
-
I'm confused. Are you trying to just create a log of slow requests or are you trying to make the server hang on to the connection if it takes a long time to process? If the latter, then you may want to look up the network term KeepAlive– Mike -- No longer hereJul 22, 2017 at 15:39
-
I want to get a list of HTTP requests which tool longer than expected. I need it in order to create a plan of website optimization.– AnthonyJul 22, 2017 at 17:06
1 Answer
The CustomLog
directive allows you to set a condition (in an optional 3rd argument) that is used to control when the request is logged. (On Apache 2.4+ this can take the form of an Apache Expression.) However, this condition is generally based on a property of the request (file type, request header, etc.), rather than something that is associated with the response. (Although it does seem possible to create a condition based on the HTTP response status, as this is explicitly made available in the REQUEST_STATUS
server variable.)
However, I don't see a way to create a conditon based on the server response time. (?)
A workaround might be to specifically include this information in your access log using the format string %msT
(if you specifically want this logged as milliseconds) in a custom log format. You can then filter this information using a log file analyzer.
%T
- The time taken to serve the request, in seconds.
%{UNIT}T
- The time taken to serve the request, in a time unit given by UNIT. Valid units arems
for milliseconds,us
for microseconds, ands
for seconds. Usings
gives the same result as%T
without any format; usingus
gives the same result as%D
. Combining%T
with a unit is available in 2.4.13 and later.
Reference:
http://httpd.apache.org/docs/current/mod/mod_log_config.html#formats