日志格式
对于一个常见的日志输出内容。
log_format main ‘$remote_addr|$time_local]|$request|$request_time|$upstream_response_time|’
‘$status|$body_bytes_sent|$http_referer’
了解这个内容主要原因是 最近在看服务耗时告警,发现后台和nginx接入层俩个地方负载都比较低,但有部分告警一直报,有些请求耗时非常长。看了下请求的耗时部分有的是比较高,这个就很奇怪。因此研究下nginx的耗时输出介绍。
耗时字段介绍
1、请求分段
为了下文比较好的说明耗时,先简单把整个处理分为一下几个过程:
用户请求 ->[1 Nginx 与客户端连接完成][2后台链接建立和服务处理][3发送响应][4客户端接收响应完成][5关闭 Nginx 连接]
2、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
直接看官方介绍。其表达的意思是:
这个字段输出的耗时是从nginx接受到客户端第一个字节的时间作为开始,到客户端接受到所有服务端响应数据为止。这个过程包括上面1-5所有环节的耗时。
3、upstream_response_time