INNER CODE UNIT · Python
health_pool
flukelaster/ai-trading-agent · backend/app/main.py:515
async def health_pool():
"""Live DB pool stats + recent slow queries + long-hold requests.
Auth-gated: leaks DB topology, partial SQL, and request-path latencies that
are useful for an attacker fingerprinting the deployment.
"""
stats = get_pool_stats(db_engine)
monitor = getattr(app.state, "pool_monitor", None)
return {
"pool": stats,
"samples": monitor.recent(60) if monitor else [],
"slow_queries": slow_query_tracker.top(10),
"long_holds": long_hold_tracker.top(10),
"thresholds": {
"alert_utilization": settings.db_pool_alert_threshold,
"alert_sustained_seconds": settings.db_pool_alert_sustained_seconds,
"slow_query_ms": settings.db_slow_query_threshold_ms,
"request_warn_ms": settings.db_request_warn_ms,