2011-11-04

Apacheのログに処理時間を残す

Apacheのaccess_logに、レスポンスを返すまでの処理時間が記録されるようにするには、httpd.confの設定を少し変更すればよい。
LogFormatで、「%D」と指定することによって、処理時間がマイクロ秒単位で記録される。
Linuxの場合は、
  # vi /etc/httpd/conf/httpd.conf
とやって、

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

と書く。httpd.confの前後の部分も抜粋すると次のようになる:
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %D" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# "combinedio" includes actual counts of actual bytes received (%I) and sent (%O); this
# requires the mod_logio module to be loaded.
#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio