34 lines
938 B
Python
34 lines
938 B
Python
"""Operational monitoring routes."""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from flask import Blueprint, jsonify
|
|
|
|
from ..database import db_cursor
|
|
from ..metrics import export_metrics
|
|
|
|
bp = Blueprint("monitoring", __name__)
|
|
|
|
|
|
@bp.route("/health", methods=["GET"])
|
|
def health():
|
|
"""Simple health endpoint used by orchestrators and Docker HEALTHCHECK."""
|
|
try:
|
|
with db_cursor(read_only=True) as (_, cur):
|
|
cur.execute("SELECT 1")
|
|
cur.fetchone()
|
|
except Exception as exc: # pragma: no cover - logged for operators
|
|
logging.exception("Health check DB failure: %s", exc)
|
|
return jsonify({"status": "unhealthy"}), 500
|
|
|
|
return jsonify({"status": "ok"}), 200
|
|
|
|
|
|
@bp.route("/metrics", methods=["GET"])
|
|
def metrics():
|
|
payload, status, headers = export_metrics()
|
|
if isinstance(payload, dict):
|
|
return jsonify(payload), status
|
|
return payload, status, headers
|