CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history
health-probe.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| 3ef4c9d | 1 | /** |
| 2 | * Health + metrics endpoints for load-balancer + observability. | |
| 3 | * | |
| 4 | * GET /healthz — liveness (always 200 if process alive) | |
| 5 | * GET /readyz — readiness (checks DB is reachable) | |
| 6 | * GET /metrics — basic in-process counters | |
| 7 | */ | |
| 8 | ||
| 9 | import { Hono } from "hono"; | |
| 10 | import { sql } from "drizzle-orm"; | |
| 11 | import { db } from "../db"; | |
| 12 | ||
| 13 | const health = new Hono(); | |
| 14 | ||
| 15 | const started = Date.now(); | |
| 16 | const counters = { | |
| 17 | requests: 0, | |
| 18 | errors: 0, | |
| 19 | }; | |
| 20 | ||
| 21 | // Count every request that reaches any health route | |
| 22 | health.use("*", async (c, next) => { | |
| 23 | counters.requests++; | |
| 24 | await next(); | |
| 25 | }); | |
| 26 | ||
| 27 | health.get("/healthz", (c) => { | |
| 28 | return c.json({ | |
| 29 | ok: true, | |
| 30 | uptimeMs: Date.now() - started, | |
| 31 | }); | |
| 32 | }); | |
| 33 | ||
| 34 | health.get("/readyz", async (c) => { | |
| 35 | try { | |
| 36 | await db.execute(sql`SELECT 1`); | |
| 37 | return c.json({ ok: true, db: "up" }); | |
| 38 | } catch (err) { | |
| 39 | counters.errors++; | |
| 40 | return c.json( | |
| 41 | { ok: false, db: "down", error: (err as Error).message }, | |
| 42 | 503 | |
| 43 | ); | |
| 44 | } | |
| 45 | }); | |
| 46 | ||
| 47 | health.get("/metrics", (c) => { | |
| 48 | const mem = process.memoryUsage(); | |
| 49 | return c.json({ | |
| 50 | uptimeMs: Date.now() - started, | |
| 51 | requests: counters.requests, | |
| 52 | errors: counters.errors, | |
| 53 | heapUsed: mem.heapUsed, | |
| 54 | heapTotal: mem.heapTotal, | |
| 55 | rss: mem.rss, | |
| 56 | nodeVersion: process.version, | |
| 57 | }); | |
| 58 | }); | |
| 59 | ||
| 60 | export default health; |