Skip to main content

RED Metrics tracker able to instrument flask views using prometheus metrics.

Project description

RED-Metrics-Tracker

Simple RED Metrics tracker able to instrument flask views using prometheus metrics.

Install

With pip, of course:

pip install red-metrics-tracker

Instrumenting

Tracking all methods and exceptions for all requests on a view:

app = flask.Flask(__name__)

@app.route("/endpoint")
@FlaskRedMetricsTracker.track()
def do_things():
     ...
     return "OK"

Limiting metrics tracking to specific methods:

@app.route("/endpoint", methods=["POST", "GET", "PUT", "DELETE"])
@FlaskRedMetricsTracker.track(methods=["POST", "DELETE"])
def do_things():
     ...
     return "OK"

Limiting to specific exceptions:

@app.route("/endpoint/<condition>")
@FlaskRedMetricsTracker.track(exceptions=MySpecialException)
def do_things():
     ...
     if condition == "throw":
        raise MySpecialException
     return "OK"

Filters may be combined, of course:

@app.route("/endpoint/<condition>", methods=["POST", "GET", "DELETE"])
@FlaskRedMetricsTracker.track(methods=["GET", "POST"]exceptions=MySpecialException)
def do_things():
     ...
     if condition == "throw":
        raise MySpecialException
     return "OK"

Exposition

Feel free to use prometheus_client to run an http_server serving a /metrics endpoint at its configured port.

For the people who’d like the /metrics endpoint to be part of their flask app, there’s a blueprint for that:

import flask
from red import metrics_blueprint

app = flask.Flask(__name__)
app.register_blueprint(metrics_blueprint)

Metrics are now available at you app’s url under the /metrics endpoint.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for RED-Metrics-Tracker, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size RED_Metrics_Tracker-0.1.1-py3-none-any.whl (13.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size RED-Metrics-Tracker-0.1.1.tar.gz (6.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page