{"id":17350487,"url":"https://github.com/pilosus/flask_prometheus_metrics","last_synced_at":"2025-04-14T20:31:14.877Z","repository":{"id":34914897,"uuid":"189735548","full_name":"pilosus/flask_prometheus_metrics","owner":"pilosus","description":"Prometheus Metrics for Flask Web App","archived":false,"fork":false,"pushed_at":"2023-05-01T21:13:43.000Z","size":47,"stargazers_count":28,"open_issues_count":5,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T09:01:50.857Z","etag":null,"topics":["flask","grafana","metrics","prometheus"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pilosus.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-01T13:24:12.000Z","updated_at":"2025-01-07T03:18:18.000Z","dependencies_parsed_at":"2024-06-19T00:19:26.144Z","dependency_job_id":"e223dafc-b1ad-4833-881a-9e6bf8a82cfc","html_url":"https://github.com/pilosus/flask_prometheus_metrics","commit_stats":{"total_commits":20,"total_committers":2,"mean_commits":10.0,"dds":"0.19999999999999996","last_synced_commit":"715530bd2cb3a7bfee71283d22a5b0a865fbec3c"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilosus%2Fflask_prometheus_metrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilosus%2Fflask_prometheus_metrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilosus%2Fflask_prometheus_metrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilosus%2Fflask_prometheus_metrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pilosus","download_url":"https://codeload.github.com/pilosus/flask_prometheus_metrics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248609723,"owners_count":21132917,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flask","grafana","metrics","prometheus"],"created_at":"2024-10-15T17:07:07.460Z","updated_at":"2025-04-14T20:31:14.516Z","avatar_url":"https://github.com/pilosus.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Flask Prometheus Metrics ##\n\n[![Build Status](https://travis-ci.org/pilosus/flask_prometheus_metrics.svg?branch=master)](https://travis-ci.org/pilosus/flask_prometheus_metrics)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/6b414e49d4f9302fe460/test_coverage)](https://codeclimate.com/github/pilosus/flask_prometheus_metrics/test_coverage)\n[![Maintainability](https://api.codeclimate.com/v1/badges/6b414e49d4f9302fe460/maintainability)](https://codeclimate.com/github/pilosus/flask_prometheus_metrics/maintainability)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black)\n\nPrometheus metrics exporter for Flask web applications.\n\n``flask_prometheus_metrics`` uses official [Prometheus Python Client](https://github.com/prometheus/client_python)\nproviding basic metrics about process resource usage, app's requests metrics and information.\n\n\n## Installation ##\n\n```bash\npip install -U flask_prometheus_metrics\n```\n\nYou will need ``Flask`` to run examples below:\n\n```bash\npip install -U 'flask_prometheus_metrics[flask]'\n```\n\n## Usage ##\n\nRun the following minimal example in Python shell:\n\n```python\nfrom flask import Flask\nfrom prometheus_client import make_wsgi_app\nfrom werkzeug.middleware.dispatcher import DispatcherMiddleware\nfrom werkzeug.serving import run_simple\nfrom flask_prometheus_metrics import register_metrics\n\napp = Flask(__name__)\n\n@app.route(\"/\")\ndef index():\n    return \"Test\"\n\n# provide app's version and deploy environment/config name to set a gauge metric\nregister_metrics(app, app_version=\"v0.1.2\", app_config=\"staging\")\n\n# Plug metrics WSGI app to your main app with dispatcher\ndispatcher = DispatcherMiddleware(app.wsgi_app, {\"/metrics\": make_wsgi_app()})\n\nrun_simple(hostname=\"localhost\", port=5000, application=dispatcher)\n```\n\nThen go over ``http://localhost:5000/``, refresh page a few times and check your\napp's metrics at ``http://localhost:5000/metrics``.\n\nSee also [example.py](https://github.com/pilosus/flask_prometheus_metrics/blob/master/flask_prometheus_metrics/example.py)\nfor more elaborate example of library usage in real Flask applications.\n\n## Metrics ##\n\n``flask_prometheus_metrics`` exposes the following application metrics:\n\n- ``app_request_latency_seconds`` (histogram) - Application request latency\n- ``app_request_count_total`` (counter) - application request count\n- ``app_version_info`` (gauge) - application version\n\nLibrary also provides some metrics about a Python interpreter used and process\nresource usage:\n\n- ``python_gc_objects_collected_total`` (counter) - objects collected during gc\n- ``python_gc_objects_uncollectable_total`` (counter) -  uncollectable object found during GC\n- ``python_gc_collections_total`` (counter) - number of times this generation was collected\n- ``python_info`` (gauge) - Python platform information\n- ``process_virtual_memory_bytes`` (gauge) - virtual memory size in bytes\n- ``process_resident_memory_bytes`` (gauge) - resident memory size in bytes\n- ``process_start_time_seconds`` (gauge) - start time of the process since unix epoch in seconds\n- ``process_cpu_seconds_total`` (counter) - total user and system CPU time spent in seconds\n- ``process_open_fds`` (gauge) - number of open file descriptors\n- ``process_max_fds`` (gauge) - maximum number of open file descriptors\n\n## Grafana dashboard ##\n\nThe metrics exported by ``flask_prometheus_metrics`` can be scraped by\n[Prometheus](https://prometheus.io/) monitoring system and then visualized in\n[Grafana](https://grafana.com/).\n\nYou can download Grafana dashboard crafted specifically for the ``flask_prometheus_metrics``\ndefault metrics [here](https://github.com/pilosus/prometheus-client-python-app-grafana-dashboard/).\n\n[![Grafana visualisation](https://raw.githubusercontent.com/pilosus/prometheus-client-python-app-grafana-dashboard/master/docs/flask-app-2.png)](https://github.com/pilosus/prometheus-client-python-app-grafana-dashboard/)\n\n\n## Testing ##\n\nWhen testing Flask application with ``DispatcherMiddleware`` (see Usage example above)\nyou may want to use a [little hack](https://github.com/pilosus/flask_prometheus_metrics/blob/master/tests/conftest.py#L22)\nin order to make Flask's ``test_client()`` work properly.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpilosus%2Fflask_prometheus_metrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpilosus%2Fflask_prometheus_metrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpilosus%2Fflask_prometheus_metrics/lists"}