feat: expand Prometheus metrics with request duration, storage, and auth counters

This commit is contained in:
SnapOtter
2026-06-14 12:06:06 +08:00
parent 6237684ec8
commit fb14f41512
5 changed files with 61 additions and 1 deletions
+23 -1
View File
@@ -5,7 +5,7 @@
* and a metricsText() function that appends live queue-depth gauges
* from BullMQ before returning the scrape payload.
*/
import { Counter, collectDefaultMetrics, Histogram, Registry } from "prom-client";
import { Counter, collectDefaultMetrics, Gauge, Histogram, Registry } from "prom-client";
import { perPoolCounts } from "../jobs/queues.js";
export const registry = new Registry();
@@ -26,6 +26,28 @@ export const jobDuration = new Histogram({
registers: [registry],
});
export const requestDuration = new Histogram({
name: "snapotter_http_request_duration_seconds",
help: "HTTP request duration in seconds",
labelNames: ["route_group", "status_class"] as const,
buckets: [0.01, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10],
registers: [registry],
});
export const storageUsage = new Gauge({
name: "snapotter_storage_bytes",
help: "Storage usage in bytes",
labelNames: ["category"] as const,
registers: [registry],
});
export const authAttempts = new Counter({
name: "snapotter_auth_attempts_total",
help: "Authentication attempts",
labelNames: ["method", "result"] as const,
registers: [registry],
});
export async function metricsText(): Promise<string> {
const counts = await perPoolCounts();
const lines: string[] = [