metrics.ts25 lines · main
1import { createMetricsRegistry } from '@briven/shared/observability';
2
3/**
4 * api's metrics registry. Single instance per process; the route in
5 * `routes/health.ts` exposes `render()` at /metrics, the middleware in
6 * `middleware/metrics.ts` calls `incCounter` + `observeHistogram` per
7 * request.
8 */
9const registry = createMetricsRegistry({
10 help: {
11 http_requests_total: 'Total HTTP requests handled by the api, by method, status, and route',
12 http_request_duration_ms: 'HTTP request duration (ms), by method and route',
13 briven_api_audit_writes_total: 'Total audit-log rows written, by action namespace',
14 briven_auth_rate_limit_denied_total: 'Auth rate-limit denials (S6 reliability)',
15 briven_auth_rate_limit_memory_fallback_total: 'Auth rate limiter fell back to memory (no Redis)',
16 briven_auth_mailer_failures_total: 'Auth tenant mailer hard failures after fallback',
17 briven_auth_route_5xx_total: 'HTTP 5xx responses on auth-related routes',
18 },
19});
20
21export const incCounter = registry.incCounter;
22export const observeHistogram = registry.observeHistogram;
23export const registerGauge = registry.registerGauge;
24export const renderPrometheus = registry.render;
25export const resetMetrics = registry.reset;