简体   繁体   中英

Sub second request time logging in Apache

While I can get microsecond resolution on the time taken to process a request (%D) to help reconstruct the sequence of requests I would like to look at this in relation to the times of multiple requests generated by a particular page. However as far as I can tell, the %t specifier only provides accuracy to the nearest second. Which makes it impossible to reconstruct the original sequence of events.

Is there another way to get this information in my access_log files?

TIA

This is now possible with Apache 2.4. Use for example the following log-format instead of %t:

[%{%d/%b/%Y:%H:%M:%S}t.%{msec_frac}t %{%z}t]

This will give times like [10/Apr/2012:10:47:22.027 +0000]

Unfortunately, no. This got covered a while back ( How to timestamp request logs with millisecond accuracy in Apache 2.0 ), and it's still true for the most recent stable (2.2.x) Apache branch.

I know of at least one workaround, though, if you're interested: You can pipe Apache's logs to an external process (see the docs page at http://httpd.apache.org/docs/current/mod/mod_log_config.html , under the "CustomLog" directive) which would add timestamps and actually write to the log file.

Note that this method does NOT capture the true request RX time. Apache doesn't output an access log entry until AFTER it's completed sending its response. Plus, there's an additional variable delay while Apache writes into the pipe and your timestamper reads from it (possibly including some buffering, there). If you turned on Apache's "BufferLogs" directive, there's going to be more variable buffering delay. When the system is under load, and perhaps in other edge cases, the average delay could easily grow to a second or more.

If the delays aren't too bad (ie, "BufferedLogs off", low system load), you can probably get a pretty tight estimate by subtracting the "%D" value from your external timestamp.

Some people (including me) pipe Apache's access logs to the local Syslog daemon (via the 'logger' command or whatever). The syslog daemon takes care of timestamping, among other things.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM