omergertel / pyformance

Performance metrics, based on Coda Hale's Yammer metrics
Other
195 stars 72 forks source link

Reporting via http #1

Closed djv closed 8 years ago

djv commented 12 years ago

Would be very useful if there's a built-in way to fetch the metrics through http. That's a feature in Yammer's library (http://metrics.codahale.com/manual/servlet/#manual-servlet)

omergertel commented 11 years ago

Probably, though for which framework? There isn't a one-servlet-to-rule-them-all in python, so it's probably best to build extensions to each framework as a separate package. Also, flask and djano make it really easy.

Here's what I'd use as a basis for a flask based pyformance API:

from flask import current_app, Flask
import pyformance, json
app = Flask(__name__)

@app.route('/metrics')
def metrics():
    res = pyformance.dump_metrics()
    return current_app.response_class(json.dumps(res), mimetype = 'application/json')