跳转到主要内容

支持ASGI应用程序的Prometheus指标

项目描述

asgi-prometheus – 支持ASGI应用程序的Prometheus指标(《Asyncio》/Trio,/Curio

Tests Status PYPI Version Python Versions

需求

  • python >= 3.9

安装

应使用pip安装asgi-prometheus

pip install asgi-prometheus

使用

常见ASGI应用程序

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]

作为ASGI-Tools内部中间件

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

)

错误跟踪器

如果您有任何建议、错误报告或不满,请向https://github.com/klen/asgi-prometheus/issues的issue tracker报告

贡献

项目开发地点: https://github.com/klen/asgi-prometheus

许可证

MIT许可证下发布。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪一个,请了解更多关于安装包的信息。

源代码分发

asgi_prometheus-1.2.3.tar.gz (5.1 kB 查看散列值)

上传时间 源代码

构建分发

asgi_prometheus-1.2.3-py3-none-any.whl (5.0 kB 查看散列值)

上传时间 Python 3

支持