`
happyqing
  • 浏览: 3187718 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

nginx日志打印响应时间request_time和upstream_response_time

阅读更多

 

设置log_format,添加request_time,$upstream_response_time,位置随意

og_format  main  '"$request_time" "$upstream_response_time" $remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

 

日志输出效果:

"0.015" "0.015" 10.1.2.3 - - [20/Mar/2017:04:05:49 +0800] "GET /myApp/servlet/TestServlet HTTP/1.1" 200 52 "-" "Mozilla/4.0 (compatible; MSIE 4.0; Windows NT)" "-"

 

-------------------------------------------------------------------------------

 

笔者在根据nginx的accesslog中$request_time进行程序优化时,发现有个接口,直接返回数据,平均的$request_time也比较大。原来$request_time包含了用户数据接收时间,而真正程序的响应时间应该用$upstream_response_time。

 

下面介绍下2者的差别:

 

1、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 。

指的就是从接受用户请求的第一个字节到发送完响应数据的时间,即包括接收请求数据时间、程序响应时间、输出

响应数据时间。

 

2、upstream_response_time

官网描述:keeps times of responses obtained from upstream servers; times are kept in seconds with a milliseconds resolution. Several response times are separated by commas and colons like addresses in the $upstream_addr variable

 

是指从Nginx向后端(php-cgi)建立连接开始到接受完数据然后关闭连接为止的时间。

 

从上面的描述可以看出,$request_time肯定比$upstream_response_time值大,特别是使用POST方式传递参数时,因为Nginx会把request body缓存住,接受完毕后才会把数据一起发给后端。所以如果用户网络较差,或者传递数据较大时,$request_time会比$upstream_response_time大很多。

 

所以如果使用nginx的accesslog查看php程序中哪些接口比较慢的话,记得在log_format中加入$upstream_response_time。

 

参考:

nginx优化之request_time 和upstream_response_time差别

http://wuzhangshu927.blog.163.com/blog/static/114224687201310674652147/

 

分享到:
评论

相关推荐

    nginx优化之request_time 和upstream_response_time差别1

    本文将深入探讨两个关键的响应时间指标:`request_time` 和 `upstream_response_time`,以及它们在实际应用中的区别。 `request_time` 是Nginx记录的从开始接收客户端的第一个字节到完成写入日志(即发送完所有响应...

    Nginx设置日志打印post请求参数的方法

    "realtime": "$upstream_response_time", "status": $status, "x_forwarded": "$http_x_forwarded_for", "referer": "$http_referer", "request": "$request", "upstr_addr": "$upstream_addr", "bytes":$...

    基于ELK的nginx-qps监控解决方案.docx

    bytes_sent,"upstream_response_time":$upstream_response_time,"request":"$request","request_length":$request_length,"request_time":$request_time,"status":"$status","http_referer":"$http_referer",...

    nginx常用内部错误.docx

    * $upstream_response_time:请求过程中,upstream 响应时间 通过这些变量,你可以获取到用户的访问信息、请求信息、终端信息等,从而对网站的访问情况进行分析和优化。 三、错误日志 错误日志记录了客户端访问 ...

    log_format为Nginx设置日志格式1

    14. `$upstream_response_time`:后端服务器响应的时间。 15. `$request_time`:从接收完请求到发送完响应的总时间。 配置示例: ```nginx log_format access '$remote_addr - $remote_user [$time_local]"$...

    Nginx-Log-Analyzer

    Nginx日志分析器一个简易的nginx log分析器,你值得拥有!...addr #$upstream_response_time ' '#$body_bytes_sent #$request_time #$remote_user #$request ' '#$http_referer #$http_user_agent';环境要求oracle jdk

    nginx-ingress 日志持久化

    - `$upstream_response_time`:上游服务器响应时间 - `$connection`:当前连接号 - `$connection_requests`:该连接上的请求次数 对于更复杂的日志格式,例如JSON格式,你可以通过配置Nginx的`log_format`指令来...

    关于nginx日志增加cookie信息

    log_format main '[$time_local] - $remote_addr:$remote_port - $remote_user - $upstream_addr $upstream_status $upstream_response_time - ' '"$request" $status $bytes_sent $request_time ' '"$...

    Nginx应用之Location路由反向代理及重写策略示例

    一、常用设置 1、日志格式 log_format main '$time_iso8601|$remote_addr|$remote_user|$request_method|$uri|' '$status|$request_time|$request_length|$... '$upstream_response_time|$args|$http_referer|$http

    使用log_format为Nginx服务器设置更详细的日志格式方法

    例如,增加`$request_time`和`$upstream_response_time`字段: ```nginx log_format detailed '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$...

    Nginx状态监控以及日志分析详解

    - $upstream_response_time:上游服务器响应时间 分析Nginx日志可以使用各种Linux命令,例如: - 统计唯一访问者(UV): ```bash awk '{print $1}' access.log | sort -n | uniq | wc -l ``` - 查找访问频率...

    Nginx 日志改成 JSON 格式的方法

    '"up_resp_time": "$upstream_response_time",' '"request_time": "$request_time" }'; ``` 这里,我们使用了Nginx内置变量,如`$time_local`(时间戳)、`$remote_addr`(客户端IP)和`$status`(HTTP状态码)...

    基于nginx access日志格式详解

    9. **$upstream_response_time**: 上游服务器处理请求所需的时间。 10. **$upstream_status**: 上游服务器返回的HTTP状态码。 11. **$http_referer**: 用户通过哪个页面链接到达当前页面,即HTTP Referer头。 12. **...

    关于nginx没有跳转到upstream地址的解决

    在使用Nginx作为反向代理服务器时,有时可能会遇到一个问题:当客户端发起请求时,Nginx没有正确地将请求转发到上游服务器(upstream),而是直接暴露了upstream的内部地址,导致404错误。这种情况通常发生在前端...

    ELK日志收集系统讲析

    '"upstream_response_time": "$upstream_response_time",' '"request_time":"$request_time",' '"status":"$status",' '"request":"$request",' '"request_method":"$request_method",' '"http_referrer":"$...

    Nginx访问日志及错误日志参数说明

    15. `$upstream_response_time`:上游服务器响应时间,如0.002秒。 错误日志(Error.log)记录了Nginx在处理请求时遇到的问题,格式固定,不能自定义。常见的错误信息包括"upstream prematurely closed connection ...

    nginx超时设置详细介绍

    接下来是`client_body_timeout`,这个配置项决定了在一次读取请求体(request body)过程中,Nginx等待客户端发送数据的时间。如果在此期间内客户端没有发送任何数据,Nginx同样返回HTTP状态码408。在http、server和...

    Nginx常见错误

    10. **`"upstream sent invalid header while reading response header from upstream"`**:后端服务器发送的响应头部无效。 11. **`"client intended to send too large body"`**:客户端发送的数据体超过了配置的...

    python实现实时监控文件的方法

    在业务稳定性要求比较高的情况下,运维为能及时发现问题,有时需要对应用程序的日志进行实时分析,当符合某个条件时就立刻报警,而不是被动等待出问题后去解决,比如要监控nginx的$request_time和$upstream_response_...

Global site tag (gtag.js) - Google Analytics