Closed henrybit closed 7 years ago
在safe_add加nil判断后,又出现新错误 module 'ngx_metric.ngx_metric' not found:
@henrybit
module 'ngx_metric.ngx_metric' not found
这个一般是ngx的启动路径问题,ngx_metric.conf配置的是相对路径,所有你的环境需要在/usr/local/nginx
下面启动
@GuyCheung 在/usr/local/nginx下启动nginx,执行sbin/nginx, 会出来这个问题 2016/12/09 17:48:11 [error] 28452#0: 19 failed to run log_by_lua: modules/ngx_metric/util.lua:46: attempt to call method 'safe_add' (a nil value) stack traceback: modules/ngx_metric/util.lua:46: in function 'dict_safe_incr' modules/ngx_metric/counter.lua:14: in function 'add' modules/ngx_metric/ngx_metric.lua:38: in function 'query_count' modules/ngx_metric/ngx_metric.lua:91: in function 'record' /usr/local/nginx/modules/ngx_metric.lua:17: in function </usr/local/nginx/modules/ngx_metric.lua:1> while logging request, client: 127.0.0.1, server: www.baidu.com, request: "GET / HTTP/1.1", host: "127.0.0.1"
这个能怎么解决?
@henrybit
function _M.dict_safe_incr(dict, metric, value)
if tonumber(value) == nil then
return
end
local newval, err = dict:incr(metric, value)
if not newval and err == "not found" then
local ok, err = dict:safe_add(metric, value)
我看safe_add
主要是metric和value两个,value
如果是nil
在上面已进入函数就返回了,所以是metric
是nil?这种情况是必现吗?如果是必现要向前排查下,从逻辑上来讲metric
应该不会是nil
2016/12/08 14:46:13 [error] 25707#0: 633 lua entry thread aborted: runtime error: modules/ngx_metric/util.lua:9: attempt to call method 'get_keys' (a nil value) stack traceback: coroutine 0: modules/ngx_metric/util.lua: in function 'dict_get_keys' modules/ngx_metric/counter.lua:18: in function 'get_snapshot' /usr/local/nginx/modules/ngx_metric_output.lua:18: in function </usr/local/nginx/modules/ngx_metric_output.lua:1>, client: 127.0.0.1, server: 127.0.0.1, request: "GET /monitor/basic_status HTTP/1.1", host: "localhost:9091" 2016/12/08 14:46:13 [error] 25707#0: 633 failed to run log_by_lua*: modules/ngx_metric/util.lua:35: attempt to call method 'safe_add' (a nil value) stack traceback: modules/ngx_metric/util.lua:35: in function 'dict_safe_incr' modules/ngx_metric/counter.lua:14: in function 'add' modules/ngx_metric/ngx_metric.lua:58: in function 'err_count' modules/ngx_metric/ngx_metric.lua:92: in function 'record' /usr/local/nginx/modules/ngx_metric.lua:17: in function </usr/local/nginx/modules/ngx_metric.lua:1> while logging request, client: 127.0.0.1, server: 127.0.0.1, request: "GET /monitor/basic_status HTTP/1.1", host: "localhost:9091"