New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prometheus metrics /metrics in kong does not work #7673
Comments
@fffonion Any clue whats going wrong here? |
It could be caused by an aborted init_worker phase, which may resulted from buggy code elsewhere or the enviroment. @albertforweb please check for any error logs before the stack trace and use keyword "init_worker". |
i remembered the init_worker from two workers has no errors, all started normally. not sure what really caused the issue on that day. two days later I reinstalled the kong, could not reproduce it anymore. but will try some time later. thanks. |
I am running into the same issue and I checked the logs before the stack trace for keyword init_worker, there are no errors. When I start Kong and try to hit the /metrics API, i run into the same error: Interesting point to note here here is, if I exec in kong pod I am able to get the metrics with kong:8001/metrics but localhost:8001/metrics or <pod_ip>/metrics, both are giving Unexpected error. Any help will be appreciated. |
@curious2k Could you share the log around |
environment variables used: KONG_PG_DATABASE=kong not sure why the PrometheusHandler.init_worker() is not called: Starting kong |
FYI. as a workaround, i have to modify the prometheus exporter, by detecting whether init_worker is called or not in the collect() method. if prometheus:init_worker was not called then call it before the other logic. this worked, but still have no clue why Prometheus:init_worker was not called by kong. |
Closing for inactivity, please re-open if the necessary ; ) |
the prometheus metrics /metrics in kong does not work with default kong configuration
similar like this : Kong/kong-plugin-prometheus#102
What api is tested?
curl http://localhost:8001/metrics
What versions are tested ?
2.1.0
2.1.4
2.2.0
2.4.1
What environment is used?
Ubuntu "20.04.2 LTS (Focal Fossa)"
postgresql-12
How to reproduce ?
1 follow steps here https://docs.konghq.com/install/ubuntu/?_ga=2.14922879.811534633.1622575399-740554415.1600964794 to install , config and start kong
2 run command "curl http://localhost:8001/metrics"
What is the problem?
constantly run "curl http://localhost:8001/metrics" every 1 seconds, sometimes you get list of metrics, sometimes you get below error:
2021/06/03 09:47:20 [error] 205436#0: *33469 lua coroutine: runtime error: ...cal/share/lua/5.1/kong/plugins/prometheus/prometheus.lua:620: attempt to index field '_counter' (a nil value)
stack traceback:
coroutine 0:
...cal/share/lua/5.1/kong/plugins/prometheus/prometheus.lua: in function 'metric_data'
...cal/share/lua/5.1/kong/plugins/prometheus/prometheus.lua:666: in function 'collect'
...local/share/lua/5.1/kong/plugins/prometheus/exporter.lua:239: in function 'collect'
/usr/local/share/lua/5.1/kong/plugins/prometheus/api.lua:6: in function 'fn'
/usr/local/share/lua/5.1/kong/api/api_helpers.lua:258: in function </usr/local/share/lua/5.1/kong/api/api_helpers.lua:241>
coroutine 1:
[C]: in function 'resume'
/usr/local/share/lua/5.1/lapis/application.lua:397: 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:167: in function </usr/local/share/lua/5.1/lapis/application.lua:165>
[C]: in function 'xpcall'
/usr/local/share/lua/5.1/lapis/application.lua:173: in function 'dispatch'
/usr/local/share/lua/5.1/lapis/nginx.lua:230: in function 'serve'
/usr/local/share/lua/5.1/kong/init.lua:1219: in function 'admin_content'
content_by_lua(nginx-kong.conf:239):2: in main chunk, client: 127.0.0.1, server: kong_admin, request: "GET /metrics HTTP/1.1", host: "localhost:8001"
2021/06/03 09:47:20 [error] 205436#0: *33469 [lua] api_helpers.lua:429: handle_error(): /usr/local/share/lua/5.1/lapis/application.lua:401: ...cal/share/lua/5.1/kong/plugins/prometheus/prometheus.lua:620: attempt to index field '_counter' (a nil value)
stack traceback:
...cal/share/lua/5.1/kong/plugins/prometheus/prometheus.lua: in function 'metric_data'
...cal/share/lua/5.1/kong/plugins/prometheus/prometheus.lua:666: in function 'collect'
...local/share/lua/5.1/kong/plugins/prometheus/exporter.lua:239: in function 'collect'
/usr/local/share/lua/5.1/kong/plugins/prometheus/api.lua:6: in function 'fn'
/usr/local/share/lua/5.1/kong/api/api_helpers.lua:258: in function </usr/local/share/lua/5.1/kong/api/api_helpers.lua:241>
stack traceback:
[C]: in function 'error'
/usr/local/share/lua/5.1/lapis/application.lua:401: 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:167: in function </usr/local/share/lua/5.1/lapis/application.lua:165>
[C]: in function 'xpcall'
/usr/local/share/lua/5.1/lapis/application.lua:173: in function 'dispatch'
/usr/local/share/lua/5.1/lapis/nginx.lua:230: in function 'serve'
/usr/local/share/lua/5.1/kong/init.lua:1219: in function 'admin_content'
content_by_lua(nginx-kong.conf:239):2: in main chunk, client: 127.0.0.1, server: kong_admin, request: "GET /metrics HTTP/1.1", host: "localhost:8001"
The text was updated successfully, but these errors were encountered: