rycus86 / prometheus_flask_exporter

Prometheus exporter for Flask applications
https://pypi.python.org/pypi/prometheus-flask-exporter
MIT License
642 stars 162 forks source link

Is working outside of request context possible #171

Open gautierrog opened 8 months ago

gautierrog commented 8 months ago

Hello,

I try to use the lib within a celery worker. I used a multiprocess metric and called metrics.start_http_server but the metrics I setup are never updated.

How does this lib work outside of flask http requests?

rycus86 commented 8 months ago

Hey,

This library is intended to use with Flask as it provides convenient wrappers for its HTTP handler functions. Underneath, it uses https://github.com/prometheus/client_python and all metrics exposed through that to the same registry will also show up on the metrics endpoint. Depending on your use-case, perhaps you'd just need the underlying library only and use its exposition options to expose them to your scraper? If not, perhaps a minimal example would help figuring out what options you have.

How does this lib work outside of flask http requests?

To answer this more directly, using metrics (counters, summary, etc.) from the underlying Prometheus library will all show up together with the Flask specific metrics, as long as they all use the same Prometheus registry. (there's a default one unless overridden)

Hope this helps?