perdy / starlette-prometheus

Prometheus integration for Starlette.
GNU General Public License v3.0
277 stars 31 forks source link
asgi metrics middleware prometheus starlette

Starlette Prometheus

Build Status Package Version PyPI Version

Introduction

Prometheus integration for Starlette.

Requirements

Installation

$ pip install starlette-prometheus

Usage

A complete example that exposes prometheus metrics endpoint under /metrics/ path.

from starlette.applications import Starlette
from starlette_prometheus import metrics, PrometheusMiddleware

app = Starlette()

app.add_middleware(PrometheusMiddleware)
app.add_route("/metrics/", metrics)

Metrics for paths that do not match any Starlette route can be filtered by passing filter_unhandled_paths=True argument to add_middleware method. Note that not turning on this filtering can lead to unbounded memory use when lots of different routes are called.

Contributing

This project is absolutely open to contributions so if you have a nice idea, create an issue to let the community discuss it.