Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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"';
share|improve this question

2 Answers 2

up vote 5 down vote accepted

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

share|improve this answer
1  
Can I drill down to the page level and see the page causing delays? –  Quintin Par Oct 5 '11 at 4:56

You can use the $request_time variable, as specified here, e.g.:

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

Edit: Oops, missed your second question. You can make AWStats parse the new format by using the LogFormat directive with an extraN variable and later use an ExtraSection to display the results.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.