template-test3/app/modules/sys/registers.py
2025-11-12 08:01:19 +00:00

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")