rycus86 / prometheus_flask_exporter

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

Possible to easily concatenate additional metrics? #147

Closed howardjones closed 1 year ago

howardjones commented 1 year ago

Before I added prometheus-flask-exporter to my flask app, I already had a metrics page for statistics about some internal caching. Is it possible to either register that view with prometheus_flask_exporter somehow, or otherwise combine the two?

rycus86 commented 1 year ago

Yeah, you can use the underlying prometheus_client library to define other metrics to expose. As long as they use the same Registry, those will also show up on the metrics endpoint, and by default they do use that same registry.

howardjones commented 1 year ago

Ah thanks, I will give that a try. The prometheus_client docs are not super clear on how this should work for multiple instances of a class, but I'll figure that out :-)

rycus86 commented 1 year ago

Found an example from one of my apps: https://github.com/rycus86/webhook-proxy/blob/master/src/server.py#L51

So basically, just import the metric class from the client and initialise it as needed, then as long as the registries match it should work - and if you don't explicitly specify those them both the Flask metrics and your custom metrics will use the same default one.