nginx日志时间

  |   0 评论   |   0 浏览

nginx时间格式

col1col2col3
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_connect_time和上游服务器建立连接耗时keeps time spent on establishing a connection with the upstream server (1.9.1); the time is kept in seconds with millisecond resolution. In case of SSL, includes time spent on handshake. Times of several connections are separated by commas and colons like addresses in the $upstream_addr variable.
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. Times of several responses are separated by commas and colons like addresses in the $upstream_addr variable.
upstream_response_time收到上游响应的耗时keeps time spent on receiving the response from the upstream server; the time is kept in seconds with millisecond resolution. Times of several responses are separated by commas and colons like addresses in the $upstream_addr variable.

nginx json格式输出

   map $time_iso8601 $time_iso8601_p1 {
     ~([^+]+) $1;
   }
   map $time_iso8601 $time_iso8601_p2 {
     ~\+([0-9:]+)$ $1;
   }
   map $msec $millisec {
     ~\.([0-9]+)$ $1;
   }

    log_format log_json '{"timestamp":"$time_iso8601_p1.$millisec+$time_iso8601_p2",'
                         '"remote_addr": "$remote_addr", '
                         '"remote_port": "$remote_port", '
                         '"remote_user": "$remote_user", '
                         '"request": "$request", '
                         '"status": "$status", '
                         '"body_bytes_sent": "$body_bytes_sent", '
                         '"http_x_forwarded_for": "$http_x_forwarded_for", '
                         '"request_time": "$request_time", '
                         '"upstream_connect_time": "$upstream_connect_time", '
                         '"upstream_header_time": "$upstream_header_time", '
                         '"upstream_response_time": "$upstream_response_time", '
                         '"http_record_id": "$http_record_id"'
                         '}';

参考

  1. Module ngx_http_log_module
  2. Module ngx_http_upstream_module