Support Prometheus metrics for ASGI applications
Project description
asgi-prometheus – Support Prometheus metrics for ASGI applications (Asyncio / Trio, / Curio)
Requirements
python >= 3.7
Installation
asgi-prometheus should be installed using pip:
pip install asgi-prometheus
Usage
Common ASGI applications:
from asgi_prometheus import PrometheusMiddleware
async def my_app(scope, receive, send):
"""Read session and get the current user data from it or from request query."""
await send({"type": "http.response.start", "status": status, "headers": headers})
await send({"type": "http.response.body", "body": b"Hello World!"})
app = PrometheusMiddleware(my_app, metrics_url="/metrics", group_paths=['/'])
# http GET / -> OK
# http GET /metrics -> [Prometheus metrics]
As ASGI-Tools Internal middleware
from asgi_tools import App
from asgi_prometheus import PrometheusMiddleware
app = App()
app.middleware(PrometheusMiddleware.setup(group_paths=['/views', '/api']))
@app.route('/')
async def index(request):
return 'Hello World!'
# http GET / -> OK
# http GET /prometheus -> [Prometheus metrics (default URL)]
Options
from asgi_sessions import PrometheusMiddleware
app = PrometheusMiddleware(
# Your ASGI application
app,
# Metrics URL for Prometheus (set empty string to disable)
metrics_url='/prometheus',
# List of path's prefixes to group. A path which starts from the prefix will be grouped.
# For example: group_paths=['/api/users'], "/api/users/1", "/api/users/2" will be grouped into "/api/users*"
group_paths=[],
)
Bug tracker
If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/asgi-prometheus/issues
Contributing
Development of the project happens at: https://github.com/klen/asgi-prometheus
License
Licensed under a MIT license.
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
asgi-prometheus-1.0.1.tar.gz
(4.9 kB
view details)
Built Distribution
File details
Details for the file asgi-prometheus-1.0.1.tar.gz
.
File metadata
- Download URL: asgi-prometheus-1.0.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b5a14f73d55b141090950d0f87348b04d7397eeb6b128f25282741de35288d0 |
|
MD5 | d82bd744b13ace1948058160c1e9ce64 |
|
BLAKE2b-256 | 410c75b9d7ed1cfb8802f910bbb7fad42c47af95f95417e69434be81e1cd1693 |
File details
Details for the file asgi_prometheus-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: asgi_prometheus-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce9d76827108216222c2c09288a51b9931b599f5f480b98ffec08e895abd02b3 |
|
MD5 | 50f9aece7ea4f1960031f605cd2be58e |
|
BLAKE2b-256 | 69fed4d7561e47550abf82199c1666a2b03105af99a9293900daec54f98b6cd9 |