Skip to main content

FastAPI Prometheus Exporter

Project description

fastapi-prometheus-exporter

codecov
FastAPI Prometheus Exporter is a simple Prometheus exporter for FastAPI applications. It provides a set of metrics by default and allows you to add your own metrics as well.

Installation

pip install fastapi-prometheus-exporter

or

poetry add fastapi-prometheus-exporter

Usage

from fastapi import FastAPI
from fastapi_prometheus_exporter import PrometheusExporterMiddleware
app = FastAPI()

PrometheusExporterMiddleware.setup(
    app=app,
    metrics_path="/metrics",
    # ignore_paths=["/healthz", "/metrics"],
)

Parameters

  • app: FastAPI application instance
  • ignore_paths: List of paths to ignore. Default: []
  • metrics_path: Path to expose metrics. Default: /metrics
  • metrics_registry: Prometheus registry to use. Default: prometheus_client.CollectorRegistry
  • request_latency_name: Name of the request latency metric. Default: http_request_duration_seconds
  • request_latency_doc: Description of the request latency metric. Default: HTTP Request Latency
  • request_latency_buckets: Buckets for the request latency metric. Default: prometheus_client.Histogram.DEFAULT_BUCKETS
  • request_latency_labels: Labels for the request latency metric. Default: ["method", "endpoint", "http_status"]
  • request_count_name: Name of the request count metric. Default: http_requests_total
  • request_count_doc: Description of the request count metric. Default: Total HTTP Requests
  • request_count_labels: Labels for the request count metric. Default: ["method", "endpoint", "http_status"]

Metrics

Default Metrics

  • http_request_duration_seconds: HTTP request latency in seconds
  • http_requests_total: Total HTTP requests

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

fastapi_prometheus_exporter-0.2.2.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file fastapi_prometheus_exporter-0.2.2.tar.gz.

File metadata

  • Download URL: fastapi_prometheus_exporter-0.2.2.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1016-azure

File hashes

Hashes for fastapi_prometheus_exporter-0.2.2.tar.gz
Algorithm Hash digest
SHA256 1eb6d88b638e1e234e071879d413b64f466a31fd6f0afc5dfdc869956c1d2b1e
MD5 4b4abd6d92142d1f6e57730004558e48
BLAKE2b-256 734f3e08d09b8ba29daa10e750022f7038b2d11770ff4d7b9be02615ed4de17e

See more details on using hashes here.

File details

Details for the file fastapi_prometheus_exporter-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_prometheus_exporter-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e14ee4350131768d3ec0588d62b12b8b6d2cf870467b4d0761d5925cf2a65960
MD5 31f3a33bf5869ec1078907897295082c
BLAKE2b-256 7943b3a6b35b3d832280119b96b7c2775ca4cf776a09cb96c32a2f6aeeb46336

See more details on using hashes here.

Supported by

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