Coder Social home page Coder Social logo

asgi-prometheus's Introduction

ASGI-Prometheus

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

Tests Status PYPI Version Python Versions
  • python >= 3.9

asgi-prometheus should be installed using pip:

pip install asgi-prometheus

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)]
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=[],

)

If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/asgi-prometheus/issues

Development of the project happens at: https://github.com/klen/asgi-prometheus

Licensed under a MIT license.

asgi-prometheus's People

Contributors

klen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

asgi-prometheus's Issues

Requests with scope type "websocket" raise a KeyError because there are no method for this kind of asgi request

The asgi scope definition for "websocket" requests does not contain a "method" entry (cf https://asgi.readthedocs.io/en/latest/specs/www.html#websocket-connection-scope). The BaseMiddleware from asgi-tools calls __process__ if scope in ("http", "websocket") (default, overridable at class level).

Thus this causes an exception for all websocket requests:

path, method = scope["path"], scope["method"]

I'm not sure on how this should behave for websocket requests, I fix it for now be removing the "websocket" scope from the middleware scopes but this is a local workaround.

asgi_app = PrometheusMiddleware(asgi_app, metrics_url=_metrics_url, group_paths=["/"])
asgi_app.scopes = ("http",)

Uvloop support

Sorry to bother you again... ๐Ÿ˜…

I saw that uvloop is not on the README, but does it work with it? I guess it does?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.