Rootop 服务器运维与web架构

nginx $upstream_response_time 里有2个值

在python分析nginx日志时会把upstream_response_time字符串转换为float数据类型,但报错:could not convert string to float: ‘0.000, 0.148’,发现出来2个值。日志中也是2个值。

{略过部分日志字段…,”upstream_response_time”:”0.000, 0.148″}
发现nginx日志中字段 $upstream_response_time 里有2个值,中间由逗号和空格分隔。正常情况下应该只有一个时间。像下面这样:
{略过部分日志字段…,”upstream_response_time”:”0.131″}

查nginx文档:http://nginx.org/en/docs/http/ngx_http_upstream_module.html#var_upstream_response_time

$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.
最后一句说多个响应时间由逗号和冒号分隔(但实际上是由逗号和空格分隔,可能此处文档有错误)和 $upstream_addr 变量的多个值类似
通过 $upstream_addr 变量查到描述说请求期间如果连接了多个服务器,就会出现2个值。
出现此问题的可能性一般是在upstream中定义了多个server,第一次分配的server无法响应,第二次分配处理成功,则此处就会出现2个值。
可以通过 proxy_next_upstream off; 关闭使用下一个upstream,但是客户端可能会响应为502错误。

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/4747.html

作者:Venus

服务器运维与性能优化

评论已关闭。