Nginx$connections\u每个服务器块处于活动状态

Nginx$connections\u每个服务器块处于活动状态,nginx,proxy,lua,Nginx,Proxy,Lua,是否可以从每个服务器块的存根nginx激活$connections\u?这样我就可以知道每个网站每秒有多少个请求。这仅适用于整个代理的全局连接。如果没有,我怎么做 我正在使用openresty和lua编程。以下是使用nginx和lua的方法: lua_shared_dict live_hosts 1M; rewrite_by_lua_block { local dict = ngx.shared.live_hosts; if (not ngx.var.http_counted) the

是否可以从每个服务器块的存根nginx激活$connections\u?这样我就可以知道每个网站每秒有多少个请求。这仅适用于整个代理的全局连接。如果没有,我怎么做


我正在使用openresty和lua编程。

以下是使用nginx和lua的方法:

lua_shared_dict live_hosts 1M;

rewrite_by_lua_block {
  local dict = ngx.shared.live_hosts;
  if (not ngx.var.http_counted) then
     ngx.req.set_header("counted", "true");
     dict:incr(ngx.var.host, 1, 0);
  end
}

log_by_lua_block {
  local dict = ngx.shared.live_hosts;
  dict:incr(ngx.var.host, -1);
}
然后您可以访问
ngx.shared.live\u主机:get('foo.com')


注意:
counted
添加的头是处理nginx内部重定向所必需的:在这种情况下,rewrite_by_lua被调用两次,而log_by_lua只被调用一次
ngx.ctx
无法使用(内部重定向时会清除)

以下44行所做的工作超出了预期范围:。我已经搜索了几个小时的解决方案,我想知道为什么谷歌没有把我带到这里。谢谢,顺便说一句!