Export aiohttp metrics for Prometheus.io
- aiohttp >= 3
Install with:
pip install aiohttp-prometheus-exporter
from aiohttp import web
from aiohttp_prometheus_exporter.handler import metrics
from aiohttp_prometheus_exporter.middleware import prometheus_middleware_factory
async def hello(request):
return web.Response(text="Hello, world")
app = web.Application()
app.add_routes([web.get('/', hello)])
app.middlewares.append(prometheus_middleware_factory())
app.router.add_get("/metrics", metrics())
web.run_app(app)
import aiohttp
from aiohttp_prometheus_exporter.trace import PrometheusTraceConfig
async with aiohttp.ClientSession(trace_configs=[PrometheusTraceConfig()) as session:
async with session.get('http://httpbin.org/get') as resp:
print(resp.status)
print(await resp.text())
Now, client metrics are attached to metrics exposed by your web server.
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.