Custom nginx block for Prometheus - Error

#1

hi,

Follow the documentation: https://docs.konghq.com/hub/kong-inc/prometheus/
and the sample :
server {
server_name kong_prometheus_exporter;
listen 0.0.0.0:9542; # can be any other port as well

 location / {
     default_type text/plain;
     content_by_lua_block {
         local serve = require "kong.plugins.prometheus.serve"
         serve.prometheus_server()
     }
 }

 location /nginx_status {
     internal;
     access_log off;
     stub_status;
 }

}

Im getting this error:
/style>

Error

/usr/local/share/lua/5.1/kong/pdk/private/phases.lua:66: no phase in kong.ctx.core.phase

Traceback


stack traceback:
[C]: in function ‘error’
/usr/local/share/lua/5.1/kong/pdk/private/phases.lua:66: in function ‘check_phase’
/usr/local/share/lua/5.1/kong/pdk/response.lua:559: in function ‘exit’
/usr/local/share/lua/5.1/kong/plugins/prometheus/serve.lua:32: in function ‘handler’
/usr/local/share/lua/5.1/lapis/application.lua:130: in function ‘resolve’
/usr/local/share/lua/5.1/lapis/application.lua:161: in function </usr/local/share/lua/5.1/lapis/application.lua:159>
[C]: in function ‘xpcall’
/usr/local/share/lua/5.1/lapis/application.lua:159: in function ‘dispatch’
/usr/local/share/lua/5.1/lapis/nginx.lua:215: in function ‘prometheus_server’
content_by_lua(nginx-sample.conf:10):3: in function <content_by_lua(nginx-sample.conf:10):1>
lapis 1.6.0

Any idea?

0 Likes

#2

Solved
change for this:

location /monitoring/metrics {
default_type text/plain;
content_by_lua_block {
local promethus = require “kong.plugins.prometheus.exporter”
promethus:collect()
}
}

documentation is wrong

0 Likes

#3

Sorry about documentation being out of date.
I just opened up a PR to fix this:

1 Like