Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesPull RequestsActionsSecurityInsightsSettings
✨ AI
More
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.

health-probe.tsBlame61 lines · 2 contributors
3ef4c9dClaude1/**
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
9import { Hono } from "hono";
10import { sql } from "drizzle-orm";
11import { db } from "../db";
12
13const health = new Hono();
14
15const started = Date.now();
16const counters = {
17 requests: 0,
18 errors: 0,
19};
20
21// Count every request that reaches any health route
22health.use("*", async (c, next) => {
23 counters.requests++;
24 await next();
25});
26
27health.get("/healthz", (c) => {
28 return c.json({
13e7ee3Dictation App29 status: "ok",
3ef4c9dClaude30 ok: true,
31 uptimeMs: Date.now() - started,
32 });
33});
34
35health.get("/readyz", async (c) => {
36 try {
37 await db.execute(sql`SELECT 1`);
38 return c.json({ ok: true, db: "up" });
39 } catch (err) {
40 counters.errors++;
41 return c.json(
42 { ok: false, db: "down", error: (err as Error).message },
43 503
44 );
45 }
46});
47
48health.get("/metrics", (c) => {
49 const mem = process.memoryUsage();
50 return c.json({
51 uptimeMs: Date.now() - started,
52 requests: counters.requests,
53 errors: counters.errors,
54 heapUsed: mem.heapUsed,
55 heapTotal: mem.heapTotal,
56 rss: mem.rss,
57 nodeVersion: process.version,
58 });
59});
60
61export default health;