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

Uploaded Source

Built Distribution

asgi_prometheus-1.1.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: asgi-prometheus-1.1.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for asgi-prometheus-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7437136fa16f3b2a8761ddd5196ae8101305c02878a54e0a86c3a53da0c49413
MD5 f7bddffdee19080a979b0b9068d3ac62
BLAKE2b-256 e363bbe857b6f9971c67ea957ab8041e020b090f59f8492d64b35fcdc4c65fec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asgi_prometheus-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for asgi_prometheus-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6cc1e7a967b89594cc0c3bb3849642c0f6a0aede09c5230cb7998e923248e136
MD5 088c486b5f4e62ab971668abcb383294
BLAKE2b-256 0d600314a71ff141dd48c4da29f33d0ef92e41a32c4db9b5b4ea4750f225227f

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