日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Nginx >内容正文

Nginx

通过Nginx,Tomcat访问日志(access log)记录请求耗时

發(fā)布時間:2025/6/15 Nginx 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 通过Nginx,Tomcat访问日志(access log)记录请求耗时 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一、Nginx通過$upstream_response_time $request_time統(tǒng)計請求和后臺服務(wù)響應(yīng)時間


nginx.conf使用配置方式:

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 ';


$request_time和$upstream_response_time之間差別:

$request_time包含了用戶數(shù)據(jù)接收時間,而真正程序的響應(yīng)時間應(yīng)該用$upstream_response_time
所以如果用戶網(wǎng)絡(luò)較差,或者傳遞數(shù)據(jù)較大時,$request_time會比$upstream_response_time大很多
詳細參考:http://wuzhangshu927.blog.163.com/blog/static/114224687201310674652147/


二、Tomcat通過%D或%T統(tǒng)計請求響應(yīng)時間

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 &quot;%r&quot; %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,提交響應(yīng)的時間,以毫秒為單位
詳細說明:http://tomcat.apache.org/tomcat-7.0-doc/config/valve.html#Access_Logging

?

三、通過awk命令輔助統(tǒng)計access.log

1.簡單統(tǒng)計nginx訪問日志access log每分鐘請求數(shù)

awk -F: '{count[$2":"$3]++} END {for (minute in count) print minute, count[minute]}'?/usr/local/nginx/logs/access.log | sort > count.log

結(jié)果如下所示(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.統(tǒng)計請求響應(yīng)時間超過10s的記錄

awk '($NF > 10){print $0}' /usr/local/tengine/logs/cut-log/access_2015-01-12.log >t10_0112.log

更多awk命令統(tǒng)計訪問日志參考:http://www.ibm.com/developerworks/cn/linux/l-cn-awk-httplog/

《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的通过Nginx,Tomcat访问日志(access log)记录请求耗时的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。