Health Checks & Metrics
Designed so production never leaks data: the public endpoint says only ok or error, everything else needs a token, a direct local connection or a one-time code.
| Endpoint | Enabled | Who can read it | Content |
|---|---|---|---|
/health | App(health=True) (default) | everyone | {"status": "ok"} 200 or {"status": "error"} 503 (database ping, cached 5 s) |
/health/details | with /health | token / local / OTP | uptime, process RSS/CPU/threads/FDs, cache stats, task queue counts |
/metrics | App(metrics=True) | token / local / OTP | Prometheus text format |
If your project already defines /health or /metrics, Lila does not replace them.
Access rules
- METRICS_TOKEN set →
Authorization: Bearer <token>is required (constant-time comparison). Use this for Prometheus. - No token → only direct loopback requests (
curl http://127.0.0.1:PORT/metricson the server). Requests relayed by Nginx carry forwarding headers and are refused, even if the app runs without--proxy-headers. Remote callers get 404. - METRICS_OTP=true → additionally, every access needs a one-time code: the first request returns 401 and the server prints a 6-digit code in its terminal/journal (valid 5 minutes, single use, stored hashed). Repeat the request with
X-Lila-OTP: 123456or?otp=123456.
Terminal
# on the server, with METRICS_OTP=true
curl -s http://127.0.0.1:8000/health/details # 401 {"otp_required": true}
sudo journalctl -u my-shop -n 5 | grep "One-time code" # [Lila] One-time code for /health/details: 482913
curl -s -H "X-Lila-OTP: 482913" http://127.0.0.1:8000/health/details
prometheus.yml
# prometheus.yml
scrape_configs:
- job_name: lila
metrics_path: /metrics
authorization:
credentials: "<METRICS_TOKEN>"
static_configs:
- targets: ["127.0.0.1:8000"]
Metrics exported
lila_requests_total{method, status="2xx|3xx|4xx|5xx"},lila_request_duration_seconds(histogram),lila_requests_in_flightprocess_resident_memory_bytes,process_cpu_seconds_total,process_open_fds,process_threads,lila_uptime_secondslila_cache_items,lila_cache_memory_bytes,lila_tasks{status},lila_database_up- No path, query, user or IP labels: no personal data and no cardinality explosion.