prometheus_flask_exporter icon indicating copy to clipboard operation
prometheus_flask_exporter copied to clipboard

Exposing metrics on a different HTTP server causes metrics to be available on every endpoint

Open Diggs27 opened this issue 4 years ago • 3 comments

Hi There,

Maybe I am doing something wrong in my configuration, but when I use Gunicorn to expose the metrics on another http server/port taken from the example config: GunicornPrometheusMetrics.start_http_server_when_ready(5005)

Although I can see the metrics on the "/metrics" endpoint, I can also see the metrics on ANY endpoint. /metrics, /metricsTEST, on /, etc. Is this intended behavior? Do I perhaps have something configured wrong?

Thanks!

Diggs27 avatar Sep 17 '20 15:09 Diggs27

Hello,

Yeah, I think I didn't really get to the bottom of this yet. :( See the last paragraph in the README at https://github.com/rycus86/prometheus_flask_exporter#multiprocess-applications

A final caveat is that the metrics HTTP server will listen on any paths on the given HTTP port, not only on /metrics, and it is not implemented at the moment to be able to change this.

rycus86 avatar Sep 18 '20 10:09 rycus86

Thanks for the quick response. I admit I completely missed that in the documentation. Is this because the start_http_server is just calling the underlying prometheus library under the hood? I take it that isn't tied to any sort of flask app?

Diggs27 avatar Sep 18 '20 12:09 Diggs27

Yeah, that function just calls into https://github.com/prometheus/client_python/blob/3be4faff2223c509b83cb5f2854a9e6d324aa3a7/prometheus_client/exposition.py#L75 which starts a new wsgi server on a new thread. Can't remember the exact reason now why it was hard to do it with Flask, but there might be ways to improve this.

rycus86 avatar Sep 19 '20 00:09 rycus86