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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for RED-Metrics-Tracker-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04e5563d32ed8c04e2d361b659959f4938d5bdace950364b3361c3faec75c57e |
|
MD5 | 260a488927e5295076a73c6c6dc2b891 |
|
BLAKE2b-256 | 8579552b36f1c3c8a4b21225e0454949c4e569f7f0b03b0f3132507bf251ce57 |
Hashes for RED_Metrics_Tracker-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5871fec127dd71d8a0f463b60e8d4e1ee64bbf8f9d2791cf2430ef9de2f9826e |
|
MD5 | 6cbee7a9af04e4c3e8b3ee55b621fa2d |
|
BLAKE2b-256 | 25ef5e72abcbd776ae8415f23300d0bdde4a8c1f0767e63dcfe58ff9685efdbe |