-
Notifications
You must be signed in to change notification settings - Fork 284
Expand file tree
/
Copy pathmetrics.ts
More file actions
33 lines (25 loc) · 968 Bytes
/
metrics.ts
File metadata and controls
33 lines (25 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import express, { Request, Response } from "express";
import client from "prom-client";
import log from "./logger";
const app = express();
export const restResponseTimeHistogram = new client.Histogram({
name: "rest_response_time_duration_seconds",
help: "REST API response time in seconds",
labelNames: ["method", "route", "status_code"],
});
export const databaseResponseTimeHistogram = new client.Histogram({
name: "db_response_time_duration_seconds",
help: "Database response time in seconds",
labelNames: ["operation", "success"],
});
export function startMetricsServer() {
const collectDefaultMetrics = client.collectDefaultMetrics;
collectDefaultMetrics();
app.get("/metrics", async (req: Request, res: Response) => {
res.set("Content-Type", client.register.contentType);
return res.send(await client.register.metrics());
});
app.listen(9100, () => {
log.info("Metrics server started at http://localhost:9100");
});
}