Skip to content

adriankrupa/aiohttp_prometheus_exporter

Repository files navigation

aiohttp prometheus exporter

Black Documentation Status Updates

Export aiohttp metrics for Prometheus.io

Usage

Requirements

  • aiohttp >= 3

Installation

Install with:

pip install aiohttp-prometheus-exporter

Server quickstart

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)

Client quickstart

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.

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

About

Prometheus exporter for aiohttp client and server.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •