vovolie/lua-nginx-prometheus

无法使用?

Chinaxiang opened this issue · 1 comments

你好,我按照你的文档进行安装,访问报错。

consul 和 openresty 正常启动。

ls /data
lua-nginx-prometheus  lua-resty-consul  nginx-lua-prometheus

把counter.conf拷贝到了 conf.d/counter.conf .

修改如下:

lua_package_path "/data/nginx-lua-prometheus/prometheus.lua;;/data/lua-resty-consul/lib/resty/consul.lua;;/data/lua-nginx-prometheus/lib/counter.lua;;";

lua_shared_dict prometheus_metrics 10M; 
lua_shared_dict uri_by_host 10M;
lua_shared_dict global_set 1M;
lua_code_cache off;

init_by_lua_block {
    counter = require 'counter'
    counter.init()
    consul_host = "192.168.111.11"
    consul_port = 8500
}

log_by_lua_block {
    counter.log()
}

server {
    listen 9145;
    allow all;
    location /metrics {
        content_by_lua 'prometheus:collect()';
    }

}

但是访问:http://192.168.111.12:9145/metrics 报500错误。

日志:

2018/04/14 20:23:56 [error] 5202#5202: *1 lua entry thread aborted: runtime error: content_by_lua(counter.conf:23):1: attempt to index global 'prometheus' (a nil value)
stack traceback:
coroutine 0:
        content_by_lua(counter.conf:23): in function <content_by_lua(counter.conf:23):1>, client: 192.168.111.1, server: , request: "GET /metrics HTTP/1.1", host: "192.168.111.12:9145"
2018/04/14 20:23:56 [error] 5202#5202: *1 failed to run log_by_lua*: log_by_lua(counter.conf:17):2: attempt to call field 'log' (a nil value)
stack traceback:
        log_by_lua(counter.conf:17):2: in function <log_by_lua(counter.conf:17):1> while logging request, client: 192.168.111.1, server: , request: "GET /metrics HTTP/1.1", host: "192.168.111.12:9145"

我不知道是不是lua_package_path配置的有问题,但是你的文档中没有写清晰,请告知如何配置???谢谢。

设置纯 Lua 扩展库的搜寻路径好像不用每段都;;分号,';;' 是默认路径。
lua_package_path '/foo/bar/?.lua;/blah/?.lua;;';

从报错信息上来看是全局prometheus这个对像没有被初始化,更新后的consul其实不用包含进去的了,只需要单独的http库就可以的了。

counter.lua里面还要改一改 sync_consul 这个function,因为url里面没有读进consul_host,consul_port这两个变量。