Prometheus Metrics for Flask Web App
Project description
Flask Prometheus Metrics
Prometheus metrics exporter for Flask web applications.
flask_prometheus_metrics
uses official Prometheus Python Client
providing basic metrics about process resource usage, app's requests metrics and information.
Installation
pip install -U flask_prometheus_metrics
You will need Flask
to run examples below:
pip install -U 'flask_prometheus_metrics[flask]'
Usage
Run the following minimal example in Python shell:
from flask import Flask
from prometheus_client import make_wsgi_app
from werkzeug.middleware.dispatcher import DispatcherMiddleware
from werkzeug.serving import run_simple
from flask_prometheus_metrics import register_metrics
app = Flask(__name__)
@app.route("/")
def index():
return "Test"
# provide app's version and deploy environment/config name to set a gauge metric
register_metrics(app, app_version="v0.1.2", app_config="staging")
# Plug metrics WSGI app to your main app with dispatcher
dispatcher = DispatcherMiddleware(app.wsgi_app, {"/metrics": make_wsgi_app()})
run_simple(hostname="localhost", port=5000, application=dispatcher)
Then go over http://localhost:5000/
, refresh page a few times and check your
app's metrics at http://localhost:5000/metrics
.
See also example.py for more elaborate example of library usage in real Flask applications.
Metrics
flask_prometheus_metrics
exposes the following application metrics:
app_request_latency_seconds
(histogram) - Application request latencyapp_request_count_total
(counter) - application request countapp_version_info
(gauge) - application version
Library also provides some metrics about a Python interpreter used and process resource usage:
python_gc_objects_collected_total
(counter) - objects collected during gcpython_gc_objects_uncollectable_total
(counter) - uncollectable object found during GCpython_gc_collections_total
(counter) - number of times this generation was collectedpython_info
(gauge) - Python platform informationprocess_virtual_memory_bytes
(gauge) - virtual memory size in bytesprocess_resident_memory_bytes
(gauge) - resident memory size in bytesprocess_start_time_seconds
(gauge) - start time of the process since unix epoch in secondsprocess_cpu_seconds_total
(counter) - total user and system CPU time spent in secondsprocess_open_fds
(gauge) - number of open file descriptorsprocess_max_fds
(gauge) - maximum number of open file descriptors
Grafana dashboard
The metrics exported by flask_prometheus_metrics
can be scraped by
Prometheus monitoring system and then visualized in
Grafana.
You can download Grafana dashboard crafted specifically for the flask_prometheus_metrics
default metrics here.
Testing
When testing Flask application with DispatcherMiddleware
(see Usage example above)
you may want to use a little hack in order to make
Flask's test_client()
work properly.
History
v0.6.0 (2019-06-06)
- README and CHANGELOG as long description added
v0.5.0 (2019-06-06)
- CHANGELOG.md added
v0.4.0 (2019-06-06)
- Import simplified for metrics registration function
v0.3.1 (2019-06-05)
- Minor CI config fix
v0.3.0 (2019-06-05)
- Dependencies versions and safety checks added
v0.2.1 (2019-06-01)
- Update installation example in README
v0.2.0 (2019-06-01)
- README added, some code refactoring
v0.1.2 (2019-06-01)
- Version bumped
v0.1.1 (2019-06-01)
- Package versioning fix
v0.1.0 (2019-06-01)
- MVP
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 flask_prometheus_metrics-0.6.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f292c2d7d6fc721639252eb8a66cacfbae63420f5f6f668fe7f10837d6e474ef |
|
MD5 | 768484605a7def39b089b91440a636a6 |
|
BLAKE2b-256 | be962891f73536a43b2661770c845908d98fd1a80566518efa345dd5be068ed9 |
Hashes for flask_prometheus_metrics-0.6.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0c538bdccf7f04592479ff752e7d60e670651073975cefab94d840ee2591aea |
|
MD5 | 4453a40f712e9986bd1c60469bd7ae29 |
|
BLAKE2b-256 | d22ad4fabe044cd1556d1872d5fcabae8acba5bc8f4293ebff68f63555ca0365 |