跳转到主要内容

为prometheus_client提供异步辅助工具。

项目描述

prometheus-async

Documentation License: Apache 2.0 PyPI version Downloads / Month

prometheus-asyncPython客户端(用于 Prometheus 度量和监控系统)添加了对异步框架的支持。

目前支持Python 3.7及更高版本上的 asyncioTwisted

它通过包装官方客户端的度量来工作

import asyncio

from aiohttp import web
from prometheus_client import Histogram
from prometheus_async.aio import time

REQ_TIME = Histogram("req_time_seconds", "time spent in requests")

@time(REQ_TIME)
async def req(request):
      await asyncio.sleep(1)
      return web.Response(body=b"hello")

即使是针对 同步 应用程序,度量暴露方法也可能很有用,因为它们比官方客户端提供的更强大。为此,已添加辅助函数,在单独的线程中运行它们(仅限 asyncio)。

源代码托管在 GitHub 上,文档在 Read The Docs 上。

支持者