feat(O7): availability metrics and dependency health checks
- Health endpoint now checks DB connectivity - Track health check total/failures - DEP_DB_UP gauge (1=up, 0=down) + latency histogram - APP_UPTIME_SECONDS updated on each health check - Metrics: A1-A10 (10 metrics instrumented)
This commit is contained in:
@@ -453,7 +453,24 @@ pub async fn start_server(port: u16, api_key: String, database_url: &str) -> Res
|
||||
|
||||
/// Health check (no auth)
|
||||
pub async fn health_check(state: web::Data<AppState>) -> HttpResponse {
|
||||
use crate::metrics::*;
|
||||
HEALTH_CHECKS_TOTAL.inc();
|
||||
let uptime = state.start_time.elapsed().as_secs();
|
||||
APP_UPTIME_SECONDS.set(uptime);
|
||||
|
||||
// O7: Check DB dependency
|
||||
let db_start = std::time::Instant::now();
|
||||
match sqlx::query("SELECT 1").execute(&state.pool).await {
|
||||
Ok(_) => {
|
||||
DEP_DB_UP.set(1);
|
||||
DEP_DB_LATENCY.observe(db_start.elapsed().as_secs_f64());
|
||||
}
|
||||
Err(_) => {
|
||||
DEP_DB_UP.set(0);
|
||||
HEALTH_CHECK_FAILURES.inc();
|
||||
}
|
||||
}
|
||||
|
||||
HttpResponse::Ok().json(json!({"status": "ok", "uptime_seconds": uptime}))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user