Web-server – ny standard log format that includes time taken to serve the request? Can i just add it without breaking standard logfile parsers

apache-2.2formattinglog-filesweb-server

I would like to log the %D and %O log format strings in apache 2.

They are the time taken to serve a request in microseconds and the total bytes sent.

This is useful to generate stats of the server file serving speeds and see whether connectivity to certain IP segments may have trouble. I also plan on doing some load scaling based on the metrics. I also changed to daily logfile extension and daily log for better parsing.

Unfortunately none of the standard log formats seems to include those two values. Or is there one?

I would really like to keep the same log and keep it compliable to awstats, webalizer or various other tools that may arise.

So if i just change

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined

to

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\" %D" vhost_combined

is it likely that usual tooks will still work well? I think i once heard that there is some sort of convention for webserver log files that you can change the format as long as you only append stuff in the end.

  • Can anyone confirm/disprove this?
  • Do you thing this is generally a good idea? Should the results be accurate?
  • Do you know of some alternative method that may work easier? Some sort of iptables logging or something?

Best Answer

I'm not sure if that will work or not, but I'd go for something a bit different. Setup another LogFormat and CustomLog just for your metrics gathering.

LogFormat "%O %D" metrics
CustomLog "|/usr/local/bin/gather_metrics" metrics