Example on how to expose metrics in a flask app#297
Conversation
There was a problem hiding this comment.
This doesn't pull in all the other logic and endpoint should have. Can you reuse one of the ones that handles this for you?
There was a problem hiding this comment.
I don't want this logic duplicated here, I want you to use one of the existing functions for it. This code will change over time, and copy&pasted code in user applications won't get updated.
There was a problem hiding this comment.
Do you mean using like so?
from prometheus_client import REGISTRY
def metrics():
r = REGISTRYIf not, I'm probably missing the point. In my initial implementation I was hoping/expecting to find a clean function that returns a response having parsed out the parameters and done its magic. A new public api could be added that does something like this
def generate_latest(registry=core.REGISTRY, query_string=None)
"""Generate the latest metrics taking the query string into account"""
metrics_subset = parse_qs(query_string).get('name[]') if query_string is not None else None
if metrics_subset:
r = r.restricted_registry(metrics_subset)
...There was a problem hiding this comment.
No, I mean reusing something like MetricsHandler that does all the http stuff.
There was a problem hiding this comment.
Since flask's response is a uwsgi application, I'll try to see how I can reuse make_wsgi_app as is.
There was a problem hiding this comment.
@brian-brazil I think the example should be good to go now.
db967e5 to
27d2caf
Compare
There was a problem hiding this comment.
Wsgi should stay first
There was a problem hiding this comment.
Keep this minimal, just enough to expose metrics at all like in the other examples.
9bd8902 to
42e3c76
Compare
There was a problem hiding this comment.
Flask Prometheus WSGI
There was a problem hiding this comment.
Not sure I understand this comment
There was a problem hiding this comment.
Proper nouns should be capitalised.
There was a problem hiding this comment.
We mention filenames before the relevant example.
28a7b36 to
b97f7ce
Compare
Signed-off-by: Evans Mungai <mbuevans@gmail.com>
|
Thanks! |
I'm working on a flask application that needs to expose metrics to prometheus. It was not very clear how that could be done without reading the code. This PR updates the README with a simple example of doing so. Hopefully it saves someone some time of trying to figure that out.
@brian-brazil