Nginx, awstats and request time

awstatsnginx

How can I tune nginx to write request time to logs such that awstats can show time taken for each request?

Also, how can I see requests by time taken in awstats?

This is the current format

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

Best Answer

As @Vladimir mentioned, to logs request time, edit your log_format directive as belows:

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"'
                      ' $request_time';

and set the corresponding variables for LogFormat in awstats configuration file:

LogFormat="%host %other %host_r %time1 %methodurl %code %bytesd %refererquot %uaquot %other %extra1"

Here is an extra1 section example:

ExtraSectionName1="Time to serve requests (seconds)"
ExtraSectionCodeFilter1=""
ExtraSectionFirstColumnTitle1="Number of seconds to serve the request"
ExtraSectionFirstColumnValues1="extra1,(.*)"
ExtraSectionStatTypes1="H"

Building report:

awstats.pl -config=model -output -staticlinks > awstats.localhost.html

enter image description here