Skip to content

Latest commit

 

History

History
60 lines (37 loc) · 1.93 KB

README.rst

File metadata and controls

60 lines (37 loc) · 1.93 KB

Prometheus middleware for aiohttp

aiohttp_prometheus adds support for exporting prometheus metrics to aiohttp applications. It is implemented as a aiohttp middleware.

Currently, it exports the following metrics via the /metrics endpoint:

  • request_latency_seconds: Latency of a request in seconds.
    • Labels exported: endpoint, app_name
  • requests_total: Request count.
    • Labels exported: app_name, method (HTTP method), endpoint, http_status (HTTP status)
  • requests_in_progress_total: In progress requests.
    • Labels exported: app_name, endpoint, method (HTTP method)

Install

I will be publishing to PyPI soon, but for now specifying the following in your requirements.txt file will install the master version of the package from github:

git+http://github.com/amitsaha/aiohttp-prometheus.git#egg=aiohttp_prometheus

Usage

The aiohttp_prometheus package exports a single function setup_metrics(app, 'app_name') which takes in the following arguments:

  • app: The application object returned via web.Application()
  • The second argument is the web application name which identifies the web application and used to set the app_name label above

Briefly, the following is all you need to do to measure and export prometheus metrics from your aiohttp web application:

from aiohttp_prometheus import setup_metrics
from aiohttp import web
app =  web.Application()
setup_metrics(app, "mywebapp")

For complete examples, please see examples.

Discussions

Please file a issue to file a comment, report an issue or make a suggestion.