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

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page