通过Nginx,Tomcat访问日志(access log)记录请求耗时
来源:互联网 发布:淘宝小手段 编辑:程序博客网 时间:2024/05/07 10:31
一、Nginx通过$upstream_response_time $request_time统计请求和后台服务响应时间
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包含了用户数据接收时间,而真正程序的响应时间应该用$upstream_response_time
所以如果用户网络较差,或者传递数据较大时,$request_time会比$upstream_response_time大很多
详细参考:http://wuzhangshu927.blog.163.com/blog/static/114224687201310674652147/
二、Tomcat通过%D或%T统计请求响应时间
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_Logging
三、通过awk命令辅助统计access.log
1.简单统计nginx访问日志access log每分钟请求数
awk -F: '{count[$2":"$3]++} END {for (minute in count) print minute, count[minute]}' /usr/local/nginx/logs/access.log | sort > count.log
结果如下所示(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/
http://www.cnblogs.com/huligong1234/p/4220017.html
- 通过Nginx,Tomcat访问日志(access log)记录请求耗时
- 通过Nginx,Tomcat访问日志(access log)记录请求耗时
- tomcat访问(access)日志配置、记录Post请求参数
- 在nginx日志的access log中记录post请求的参数值
- shell脚本检查统计nginx访问日志access.log
- nginx access.log 忽略favicon.ico访问记录的方法
- 使用Nginx如何配置Tomcat访问日志记录真实IP
- 使用Nginx如何配置Tomcat访问日志记录真实IP
- Tomcat 访问日志记录
- tomcat记录访问日志
- Tomcat的访问日志-localhost_access_log和记录Post请求参数
- Tomcat的访问日志-localhost_access_log和记录Post请求参数
- apache&tomcat access访问日志
- shell分析nginx access log日志
- shell分析nginx access log日志
- Nginx access.log日志分析shell命令
- shell分析nginx access log日志
- Nginx access.log日志分析shell命令
- android 全屏以及透明状态栏总结
- An overview of gradient descent optimization algorithms
- 简单的c语言程序
- GitHub上史上最全的iOS开源项目分类汇总
- 配置iis站点上放置的apk文件不能下载
- 通过Nginx,Tomcat访问日志(access log)记录请求耗时
- 位逻辑运算符与表达式
- maven学习
- 安装hadoop-eclipse-plugin-2.7.2.jar出现问题
- iOS10 更新后问题,获取相册,录音时候闪退问题
- Vue.js笔记-计算属性 class与style绑定
- RxJava操作符(一)Creating Observables
- 自学成才秘籍!机器学习&深度学习经典资料汇总
- Python 中数据结构以及操作列表、元组、字符串、字典