Skip to main content

A library for attaching Satella metrics to FastAPI

Project description

fastapi-satella-metrics

Build Status Test Coverage Code Climate Issue Count PyPI PyPI version PyPI License

fastapi-satella-metrics is an application to seamlessly measure your FastAPI application using Satella's metrics.

Example use:

import fastapi
from fastapi_satella_metrics import SatellaMetricsMiddleware
app = fastapi.FastAPI()
app.add_middleware(SatellaMetricsMiddleware)

If you want to exclude /metrics endpoint from being metricized:

app.add_middleware(SatellaMetricsMiddleware, exclude_metrics_endpoint=True)

Or to use your metrics:

summary_metric = getMetric(
    "requests_summary", "summary", quantiles=[0.2, 0.5, 0.9, 0.95, 0.99]
)
histogram_metric = getMetric("requests_histogram", "histogram")
response_codes_metric = getMetric("requests_response_codes", "counter")

app.add_middleware(
    SatellaMetricsMiddleware,
    summary_metric=summary_metric,
    histogram_metric=histogram_metric,
    response_codes_metric=response_codes_metric,
)

To launch a Prometheus exporter use the following snippet:

from satella.instrumentation.metrics.exporters import PrometheusHTTPExporterThread
phet = PrometheusHTTPExporterThread('0.0.0.0', 8080, {'service_name': 'my_service'})
phet.start()

Or, if you desire to export your metrics within FastAPI, just use:

import fastapi
from fastapi_satella_metrics.prometheus_exporter import PrometheusExporter
app = fastapi.FastAPI()
app.include_router(PrometheusExporter({'service_name': 'my_service'}))

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-satella-metrics-2.0.0.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

fastapi_satella_metrics-2.0.0-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

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