开发者

Is there a way to have Apache log slow requests?

If a page takes over a couple of seconds to process, I'd like Apache to log that URL somewhere. Is this possible? I have a lot of sites, so I was looking for an automatic way to do th开发者_如何学JAVAis as opposed to proprietary code for each site.


Take a look at http://httpd.apache.org/docs/2.2/mod/mod_log_config.html. You can setup a custom log that includes the time it took to serve the request.

For example:

LogFormat "%h %l %u %t \"%r\" %>s %b %D" common-time

Would add the time in microseconds it took to serve the request as the last field of your logfile.

You would add that line to your httpd.conf, then in each virtualhost where you want to use it, add this line:

CustomLog logs/access_log_time common-time

You could also create a new LogFormat that contains only exactly what you want, maybe like this:

LogFormat "\"%r\" %D" measure-time

In your virtualhost, you can have multiple logs, so you could have:

CustomLog logs/access_log common
CustomLog logs/access_log_time measure-time

All that said, there's a huge caveat. This will measure only the time it takes the server to serve the page. It will not include the time it takes to execute any javascript in the browser. If you need to measure javascript execution time, you'll need to use a tool like firebug.

Once you've got the log, you could use something like apachelog to parse the logfile to get only the requests that took longer than whatever threshold you want to use.

I'm not sure if it's possible to log only the long requests and bypss the parsing step. It might be, but i have a feeling it would take a significant amount of work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜