Metadata-Version: 2.1 Name: RED-Metrics-Tracker Version: 0.1.0 Summary: RED Metrics tracker able to instrument flask views using prometheus metrics. Home-page: https://github.com/nlsdfnbch/RED-Metrics-Tracker License: UNKNOWN Keywords: red-metrics, prometheus, instrumentation, metrics Author: Nils Diefenbach Author-email: nlsdfnbch.foos@kolabnow.com Requires-Python: >3.6 Description-Content-Type: text/x-rst Classifier: Intended Audience :: Developers Classifier: Intended Audience :: Information Technology Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python :: 3 :: Only Classifier: Programming Language :: Python :: Implementation :: CPython Requires-Dist: prometheus_client Requires-Dist: flask Requires-Dist: black==19.3b0; extra == "dev" Requires-Dist: flake8-bugbear==18.8.0; extra == "dev" Requires-Dist: flake8-tuple==0.2.13; extra == "dev" Requires-Dist: flake8==3.7.5; extra == "dev" Requires-Dist: isort==4.3.16; extra == "dev" Requires-Dist: pytest==4.5.0; extra == "dev" Requires-Dist: pytest; extra == "test" Project-URL: Bug Tracker, https://github.com/nlsdfnbch/RED-Metrics-Tracker/issues Project-URL: GitHub, https://github.com/nlsdfnbch/RED-Metrics-Tracker Provides-Extra: dev Provides-Extra: test 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/") @FlaskRedMetricsTracker.track(exceptions=MySpecialException) def do_things(): ... if condition == "throw": raise MySpecialException return "OK" Filters may be combined, of course:: @app.route("/endpoint/", 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.