Health checks & observability
/health endpoint tells the load balancer 'am I alive?'. Log every request with timing.
Code example
@app.get('/health')
async def health():
return {
'status': 'healthy',
'version': APP_VERSION,
'database': check_db(),
'system': {'cpu': psutil.cpu_percent(), 'mem': psutil.virtual_memory().percent}
}
How it works
A health endpoint is a lightweight GET that returns 200 if the app is alive. Render hits /health every few seconds; if it returns non-200 or times out, Render restarts the container. The endpoint should check critical dependencies (DB, Redis) so a broken DB doesn't look 'healthy'. OpenBenchML's /health returns version, DB status, system metrics, and WebSocket connection count — useful both for Render and for ad-hoc debugging.
🔍 Where this is used in OpenBenchML
app/main.py — /health endpoint with DB + Redis + system checks.