knyar / nginx-lua-prometheus

Prometheus metric library for Nginx written in Lua
MIT License
1.46k stars 231 forks source link

Compatible ngnix image to be used for nginx, any suggestions about my issue #111

Closed ravikiranr26 closed 3 years ago

ravikiranr26 commented 3 years ago

Hello Guys, I'm running on Ubuntu, while I used nginx:1.15-alpine and latest nginx alpine and also openresty nginx docker image to build from, but still not able to run without errors.

I cloned the current nginx-lua repo and placed inside /etc/nginx/nginx-lua-prometheus and referenced in the lua_package_path

nginx.conf load_module modules/ndk_http_module.so; load_module modules/ngx_http_lua_module.so;

http { lua_shared_dict prometheus_metrics 10M; lua_package_path "/etc/nginx/nginx-lua-prometheus/?.lua;/usr/local/lib/lua/?.lua;;"; init_worker_by_lua_block { prometheus = require("prometheus").init("prometheus_metrics") metric_requests = prometheus:counter( "nginx_http_requests_total", "Number of HTTP requests", {"host", "status"}) metric_latency = prometheus:histogram( "nginx_http_request_duration_seconds", "HTTP request latency", {"host"}) metric_connections = prometheus:gauge( "nginx_http_connections", "Number of HTTP connections", {"state"}) } log_by_lua_block { metric_requests:inc(1, {ngx.var.server_name, ngx.var.status}) metric_latency:observe(tonumber(ngx.var.request_time), {ngx.var.server_name}) } }

Error: [error] 1#1: lua_load_resty_core failed to load the resty.core module from https://github.com/openresty/lua-resty-core; ensure you are using an OpenResty release from https://openresty.org/en/download.html (rc: 2, reason: module 'resty.core' not found: nginxexporter | no field package.preload['resty.core'] nginxexporter | no file '/etc/nginx/nginx-lua-prometheus/resty/core.lua'

DockerFile FROM nginx:1.15-alpine

RUN apk add --no-cache nginx-mod-http-lua

RUN rm -r /etc/nginx/conf.d && rm /etc/nginx/nginx.conf

RUN mkdir -p /run/nginx

COPY nginx.conf /etc/nginx/nginx.conf COPY nginx-lua-prometheus/ /etc/nginx/nginx-lua-prometheus

CMD ["nginx", "-g", "daemon off;"]

knyar commented 3 years ago

It does not seem like a problem related to this library. Please make sure you get lua working first before trying to use nginx-lua-prometheus.

I am not very familiar with Alpine, but it seems that your nginx lua library cannot find the resty.core lua module. I would recomment to begin by checking whether resty.core is installed (does nginx-mod-http-lua include it, or install it as a dependency?) and whether it is available in a directory listed in lua_package_path.