Skip to main content

Prometheus metrics exporter for Starlette applications.

Project description

starlette_exporter

Prometheus exporter for Starlette and FastAPI.

The middleware collects basic metrics:

  • Counter: starlette_requests_total
  • Histogram: starlette_request_duration_seconds

Metrics include labels for the HTTP method, the path, and the response status code.

starlette_requests_total{method="GET",path="/",status_code="200"} 1.0
starlette_request_duration_seconds_bucket{le="0.01",method="GET",path="/",status_code="200"} 1.0

Use the HTTP handler handle_metrics at path /metrics to expose a metrics endpoint to Prometheus.

Usage

Starlette

        from starlette.applications import Starlette
        from starlette_exporter import PrometheusMiddleware, handle_metrics

        app = Starlette()
        app.add_middleware(PrometheusMiddleware)
        app.add_route("/metrics", handle_metrics)

        ...

FastAPI

        from fastapi import FastAPI
        from starlette_exporter import PrometheusMiddleware, handle_metrics

        app = FastAPI()
        app.add_middleware(PrometheusMiddleware)
        app.add_route("/metrics", handle_metrics)

        ...

Developing

git clone https://github.com/stephenhillier/starlette_exporter
cd starlette_exporter
pytest tests

License

Code released under the Apache License, Version 2.0.

Dependencies

https://github.com/prometheus/client_python

https://github.com/encode/starlette

Credits

Starlette - https://github.com/encode/starlette

FastAPI - https://github.com/tiangolo/fastapi

Flask exporter - https://github.com/rycus86/prometheus_flask_exporter

Alternate Starlette exporter - https://github.com/perdy/starlette-prometheus

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

starlette_exporter-0.1.0.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

starlette_exporter-0.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file starlette_exporter-0.1.0.tar.gz.

File metadata

  • Download URL: starlette_exporter-0.1.0.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.5.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for starlette_exporter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 71b15b59f61249e4e8825a3427be98ba3b8525d3c7317913ff2c15d2b99bdf70
MD5 5a87fa49c5bd2b10bd12eb588ee06bd1
BLAKE2b-256 c1609313bd728c28ed7b1ab812b79e116431d2e64850f29e2c9a227addb456dc

See more details on using hashes here.

File details

Details for the file starlette_exporter-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: starlette_exporter-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.5.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for starlette_exporter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 07c1f82f68071e8cc22b0ef761efb296f6c9f61a43dd727667422a7096d9b58b
MD5 fc78f85630755e47d159612befd64dda
BLAKE2b-256 d214796ed199a385456fd512bb51f6db62daf8c5bd681103bb9e78f362651536

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page