Last active
August 29, 2015 14:27
-
-
Save tshauck/ea115a7e8654977be3a0 to your computer and use it in GitHub Desktop.
tracking metrics with prometheus and flask_restful
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from prometheus_client import Summary | |
from prometheus_client.exposition import generate_latest | |
from flask_restful import Resource | |
from flask import Response | |
REQUEST_TIME = Summary('request_processing_seconds', 'Time spent processing request') | |
class Metrics(Resource): | |
""" Resource for exposing metrics to prometheus. """ | |
def get(self): | |
""" get endpoint """ | |
latest = generate_latest() | |
resp = Response(latest, headers={'Content-Type': 'text/plain'}) | |
return resp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should use
prometheus_client.CONTENT_TYPE_LATEST
for the content type, as the Prometheus server uses that to decide how to parse the response.