27 lines
799 B
Python
27 lines
799 B
Python
import logging
|
|
|
|
from fastapi import FastAPI
|
|
|
|
from app.utils.config import settings
|
|
|
|
|
|
def register_metrics(app: FastAPI):
|
|
"""
|
|
Register Prometheus metrics endpoint.
|
|
"""
|
|
try:
|
|
from prometheus_fastapi_instrumentator import Instrumentator
|
|
|
|
instrumentator = (
|
|
Instrumentator().instrument(
|
|
app,
|
|
metric_namespace="freeleaps_{}".format(settings.FREELEAPS_PRODUCT_ID),
|
|
metric_subsystem=settings.ENVIRONMENT
|
|
)
|
|
)
|
|
instrumentator.expose(app, endpoint="/api/_/metrics", should_gzip=True)
|
|
logging.info("Metrics endpoint exposed at /api/_/metrics")
|
|
|
|
except ImportError:
|
|
logging.warning("prometheus-fastapi-instrumentator not installed, metrics endpoint will not be available")
|