How to log page latency and url host in apache log

Apache log can give you lot of insight into the performance of your site. The default configuration of apache does not log the page serving time and url host name in apache log. Here is the apache configuration which can be used for logging server page serving time and url host name.

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"V:%V D:%D\"" mycombined

This appends an extra field in apache log containing page serving time (after “D:”) and url host field “V:”. The host field is pretty handy if you are hosting multiple sites on same machine. It also helps you identify if there are duplicate pages with www and non-www domains.

Once you have configured the log format (we named it mycombined above) you can use the following config in your virtual host configuration

<VirtualHost *:80>
CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/myaccess_log.%Y-%m-%d 86400" mycombined

Some points to note

  1. The page serving time is only from server perspective. It does not include the network latency, browser rendering time, etc.
  2. Usually a latency of more than 500 milliseconds points to some problem somewhere.
  3. You should not have presence of both www and non-www in apache log. In case you are using non-www domain for your site, you should redirect www domain to non-www domain.
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments