Nginx使用日志输出上游服务器和自身的处理时间

发布时间:2020-08-08 22:47:07 作者:牛平
来源:ITPUB博客 阅读:201
场景:
    Nginx的后端跟着Tomcat,现在要统计实现Nginx的处理时间以及后端服务器的返回时间。

目的:
    对于一个客户端请求,使用日志输出Nginx自身的处理时间,上游服务器的处理时间。

实现:
    通过upstream模块的upstream_response_time变量来获取相关信息。
配置:

1.定义logformat
log_format timed_combined '$remote_addr - $remote_user [$time_local] '
             '"$request" $status $body_bytes_sent '
             '"$http_referer" "$http_user_agent" '
             '$request_time $upstream_response_time $pipe';

request_time 表明,Nginx处理该请求所需花费的时间。
upstream_response_time 表明上游服务器的处理时间。
pipe 表示是否使用了http pipe

使用该条日志格式:

access_log /var/log/nginx/yourdomain.com.access.log timed_combined;

66.249.71.173 - - [08/Nov/2010:14:16:18 -0600] "GET /blog/2010/apr/30/installing-geodjango-dependencies-homebrew/ HTTP/1.1" 200 6569 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" 0.640 0.640 .

0.640 表示,Nginx使用了0.640s的时间去相应客户端,其中上游服务器占用了0.640s,Nginx本身没有花费任何时间,并且没有使用pipeline

推荐阅读:
  1. Nginx的配置和使用
  2. python如何使用time模块处理时间?

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

nginx 上游 使用

上一篇:我是如何替换Spring Cloud Netflix的?

下一篇:一文带你看懂 Web Worker

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》