A library for attaching Satella metrics to FastAPI
Project description
fastapi-satella-metrics
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
Built Distribution
Close
Hashes for fastapi-satella-metrics-2.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5539dea4108840986559155e5a00e499550a51cf1f563d11962f2d7665e640fc |
|
MD5 | 657045626cbeab327679137247cb8bb3 |
|
BLAKE2b-256 | 2475337c13c6ea3f9a18212bd5a04764fcb63acdf037fc0924072010e748f458 |
Close
Hashes for fastapi_satella_metrics-2.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28afbe915d878f3c8bf53b2a8f986fcae09bfe1e88a8a7c3c13094012063e56b |
|
MD5 | e29762a65f3ead17bc4b5c0b2e0cf586 |
|
BLAKE2b-256 | 8d9098b9a6dd9df3e3f74f090f06bb42bf4b77ac54ca646281539e32aea20173 |