Metadata-Version: 2.4
Name: aiohttp-openmetrics
Version: 0.0.13
Summary: OpenMetrics provider for aiohttp
Author-email: Jelmer Vernooĳ <jelmer@jelmer.uk>
License: Apache v2 or later
Project-URL: Homepage, https://github.com/jelmer/aiohttp-openmetrics/
Project-URL: Repository, https://github.com/jelmer/aiohttp-openmetrics
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Operating System :: POSIX
Requires-Python: >=3.10
Description-Content-Type: text/x-rst
License-File: COPYING
License-File: AUTHORS
Requires-Dist: aiohttp
Requires-Dist: prometheus_client
Dynamic: license-file

aiohttp-openmetrics
===================

This project contains a simple middleware and /metrics route endpoint for
aiohttp that allow easy implementation of the
`openmetrics <https://www.openmetrics.io/>`_ protocol.

At the moment, this package is a thin wrapper around the ``prometheus_client``
package.

Example usage
-------------

.. code-block:: python

  from aiohttp import web
  from aiohttp_openmetrics import metrics, metrics_middleware

  app = web.Application()
  app.middlewares.append(metrics_middlware)
  app.router.add_get('/metrics', metrics)

  web.run_app(app)

Configuring latency histogram buckets
-------------------------------------

The default latency histogram uses ``prometheus_client``'s default buckets,
which top out at 10 seconds. If your requests routinely take longer (or are
much faster) you can pass custom bucket boundaries to ``setup_metrics``:

.. code-block:: python

  from aiohttp import web
  from aiohttp_openmetrics import setup_metrics

  app = web.Application()
  setup_metrics(app, latency_buckets=[1, 5, 10, 30, 60, 120, 300, 600])

Overriding the route label
--------------------------

By default, the ``route`` label used in the exported metrics is taken from the
aiohttp route's ``name``. aiohttp enforces that route names are unique, which
can be inconvenient if you want to group multiple routes under a single
``route`` label. To override the label, set the ``_metric_name`` attribute on
the handler:

.. code-block:: python

  async def handler(request):
      ...

  handler._metric_name = "my_route"
  app.router.add_get("/somewhere", handler)

License
-------

This package is licensed under the Apache v2 or later license.
