Skip to main content

Support Prometheus metrics for ASGI applications

Project description

asgi-prometheus – Support Prometheus metrics for ASGI applications (Asyncio / Trio, / Curio)

Tests Status PYPI Version Python Versions

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


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.1.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

asgi_prometheus-1.1.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file asgi-prometheus-1.1.2.tar.gz.

File metadata

  • Download URL: asgi-prometheus-1.1.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for asgi-prometheus-1.1.2.tar.gz
Algorithm Hash digest
SHA256 bcfe83b8c1391378ab7826b9ea5171e779d83e09407c7d9f84028f909361fd73
MD5 2b89509e150691b9ad83ec9499642720
BLAKE2b-256 97d2381257c5219ec59bce22c8994e3b0ff87435ac3bb44984b4b8cb41fbc6fe

See more details on using hashes here.

File details

Details for the file asgi_prometheus-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for asgi_prometheus-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8199c6ed19b4f71065e3e5e9f12cb26d647f2c57e9f682f35eb48a212be74e7b
MD5 d43230f61bc05cd6d6dedbc2bedb1f24
BLAKE2b-256 e52ce7c4e0ed54a4742d2f8382d807cb5a877871418b1a55bf73a9ccbd2e098b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page