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

health-probe.tsBlame60 lines · 1 contributor
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({
29 ok: true,
30 uptimeMs: Date.now() - started,
31 });
32});
33
34health.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
47health.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
60export default health;