nginx.conf使用配置方式:html
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
'$connection $upstream_addr '
'upstream_response_time $upstream_response_time request_time $request_time ';linux
$request_time和$upstream_response_time之間差異:nginx
$request_time包含了用戶數據接收時間,而真正程序的響應時間應該用$upstream_response_time
因此若是用戶網絡較差,或者傳遞數據較大時,$request_time會比$upstream_response_time大不少
詳細參考:http://wuzhangshu927.blog.163.com/blog/static/114224687201310674652147/apache
2、Tomcat經過%D或%T統計請求響應時間tomcat
server.xml使用配置方式
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u [%{yyyy-MM-dd HH:mm:ss}t] %{X-Real_IP}i "%r" %s %b %D %F" />網絡
%D - 官方解釋:Time taken to process the request, in millis,處理請求的時間,以毫秒爲單位
%T - 官方解釋:Time taken to process the request, in seconds,處理請求的時間,以秒爲單位
%F - 官方解釋:Time taken to commit the response, in millis,提交響應的時間,以毫秒爲單位
詳細說明:http://tomcat.apache.org/tomcat-7.0-doc/config/valve.html#Access_Loggingspa
3、經過awk命令輔助統計access.log日誌
1.簡單統計nginx訪問日誌access log每分鐘請求數orm
awk -F: '{count[$2":"$3]++} END {for (minute in count) print minute, count[minute]}' /usr/local/nginx/logs/access.log | sort > count.logserver
結果以下所示(count.log)
18:30 2086
18:31 2184
18:32 2176
18:33 2122
18:34 2128
18:35 2179
...
參考:http://huoding.com/2013/01/26/215
2.統計請求響應時間超過10s的記錄
awk '($NF > 10){print $0}' /usr/local/tengine/logs/cut-log/access_2015-01-12.log >t10_0112.log
更多awk命令統計訪問日誌參考:http://www.ibm.com/developerworks/cn/linux/l-cn-awk-httplog/