Skip to content

Instantly share code, notes, and snippets.

@tshauck
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tshauck/ea115a7e8654977be3a0 to your computer and use it in GitHub Desktop.
Save tshauck/ea115a7e8654977be3a0 to your computer and use it in GitHub Desktop.
tracking metrics with prometheus and flask_restful
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
@brian-brazil
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment