NginX - 响应时间计算与日志输出格式修改



日志输出配置

  • 日志输出

    • 默认调用 combined 格式:

      log_format combined '$remote_addr - $remote_user [$time_local] '
                          '"$request" $status $body_bytes_sent '
                          '"$http_referer" "$http_user_agent" ';
      
    • Nginx 也允许自定义日志格式,例如:

      log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" '
                      '"$request_time"';
      

      输出日志时,还需明确指定调用自定义格式名(示例中为 main):

      access_log logs/access.log main;
      

时间计算属性

主要涉及以下两个属性值,可根据需要应用计算:

  • 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.

    • 应用释义

      该属性计算的是从接收到用户发送请求中的第一个字节发送完完整响应数据的时间;

      可粗略理解为:request_time = 接收请求数据时间 + 后端服务响应时间 + 输出响应数据时间

  • 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与后端服务建立连接接收完数据关闭连接的时间;

      可粗略理解为: 后端服务响应时间(略去 Nginx 与后端服务之间的数据传输时间)

  • time_local

    日志输出时间


posted @ 2018-08-08 10:47  JustKidding  阅读(3351)  评论(0编辑  收藏  举报