我们如何为Nginx创buildBlackbox日志?

在那里有一篇文章, 用Apache的Blackbox日志分析LAMP应用程序 ,它描述了如何创build一个日志,logging常见和组合日志格式中缺less的大量详细信息。 这些信息应该可以帮助您解决性能问题。 正如作者所指出的那样:“虽然常见的日志文件格式(和组合格式)非常适合点击跟踪,但它们不适合获取核心性能数据。

这篇文章描述了一个“黑匣子”日志格式,就像飞机上的黑匣子飞行logging器一样,收集用于分析服务器性能的信息,缺less命中跟踪日志格式:保持活动状态,远程端口,subprocess,字节发送等。

LogFormat "%a/%S %X %t \"%r\" %s/%>s %{pid}P/%{tid}P %T/%D %I/%O/%B" blackbox

我正在尝试重新创buildNginx的格式,并希望帮助填补空白。 这里是Nginx黑盒子格式的样子,未映射的Apache指令在名字后面有问号。

 access_log blackbox '$remote_addr/$remote_port X? [$time_local] "$request"' 's?/$status $pid/0 T?/D? I?/$bytes_sent/$body_bytes_sent' 

这是一个我已经能够从Nginx文档映射的variables表。

 %a = $remote_addr - The IP address of the remote client. %S = $remote_port - The port of the remote client. %X = ? - Keep alive status. %t = $time_local - The start time of the request. %r = $request - The first line of request containing method verb, path and protocol. %s = ? - Status before any redirections. %>s = $status - Status after any redirections. %{pid}P = $pid - The process id. %{tid}P = N/A - The thread id, which is non-applicable to Nignx. %T = ? - The time in seconds to handle the request. %D = $request_time - The time in milliseconds to handle the request. %I = ? - The count of bytes received including headers. %O = $bytes_sent - The count of bytes sent including headers. %B = $body_bytes_sent - The count of bytes sent excluding headers, but with a 0 for none instead of '-'. 

寻找帮助填写缺失的variables,或确认缺失的variables实际上在Nginx中不可用。

Nginx不像Apache – Nginx的强大function在于(1)服务器/位置匹配和URI重写,(2)代理/故障转移请求(对HTTP / FastCGI上游)和(3)caching结果。 所以当你需要测量你的后端服务如何响应以及哪个请求被caching的时候,你可能会遇到这些地方真正的问题。 我怀疑Nginx可以有任何通用的“黑盒子”格式,因为它有很多variables,而且它们是dynamic的(也就是说,你可以将cookie的“Registered”值和相应的caching状态写入日志以查看是否注册用户获得caching内容或不)

不过,扩展简短的“组合”日志格式是非常有用的。

一般

关于一般variables的一些提示:

 $uri - URI after rewrites $args - Query arguments $realpath_root - Value of "root" for this request $server_name - the name of server which is processing the request $connection - the number of connection 

代理

代理时的一些有用的variables。 这些variables可能包含多个值:分开时,上游依次询问并分隔:X-Accel-Redirect发出时:

 $upstream_addr - the upstream IPs $upstream_response_time - the upstream processing times $upstream_status - the upstream statuses 

高速caching

一个用于loggingcaching状态的variables:

 $upstream_cache_status = MISS | EXPIRED | UPDATING (stale answer used) | STALE (stale answer used) | HIT