|
本帖最后由 java 于 2018-4-24 12:36 编辑
- '$remote_addr - $remote_user [$time_local] "$request" $http_host '
- '$status $request_length $body_bytes_sent "$http_referer" '
- '"$http_user_agent" $request_time';
- 字段解释:
- remote_addr : 客户端地址
- remote_user : 客户端用户名
- time_local : 服务器时间
- request : 请求内容,包括方法名,地址,和http协议
- http_host : 用户请求时使用的http地址
- status : 返回的http 状态码
- request_length : 请求大小
- body_bytes_sent : 返回的大小
- http_referer : 来源页
- http_user_agent : 客户端名称
- request_time : 整体请求延时
- 日志格式:'$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"'
-
- 日志记录:27.189.231.39 - - [09/Apr/2016:17:21:23 +0800] "GET /Public/index/images/icon_pre.png HTTP/1.1" 200 44668 "http://www.test.com/Public/index/css/global.css" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36" "-"
- 配置log_format
- nginx.conf
- log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent $request_body "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for" "$request_time"';
- 主要使用的是grep,awk,cut等工具来对nginx日志进行统计和分析
- Awk中数组称为关联数组,因为它的下标(索引)可以是数字也可以是字符串。
- 下标通常称为键,数组元素的键和值存储在Awk程序内部的一个表中,该表采用散列算法,因此数组元素是随机排序。
- cat:输入文件内容
-
- grep:过滤文本
- 'sort':排序
- 'uniq':去重
- 'awk':文本处理
- 命令组合使用,单个命令可以使用多次,来达到多重过滤的效果,前面一个命令的输出就是后一个命令的输入,流式处理,只要学会这个命令,有多看似复杂的东西,都变得异常简单。
复制代码 问题:nginx如何计算请求在队列中的等待时间
https://stackoverflow.com/questions/46319833/log-nginx-queue-time 好像不支持
- $request_time
- request processing time in seconds with a milliseconds resolution; time elapsed between the first bytes were read from the client and the log write after the last bytes were sent to the client
- $upstream_response_time
- keeps time spent on receiving the response from the upstream server; the time is kept in seconds with millisecond resolution.
- $upstream_header_time
- keeps time spent on receiving the response header from the upstream server (1.7.10); the time is kept in seconds with millisecond resolution.
- but all of them report the same time, about 5 second, for both requests.
复制代码 |
|