/ opencodehub / src / lib / metrics.ts
swadhinbiswas Initial commit of OpenCodeHub source · 12/11/2025
1110042
31 lines · 844 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
import client from "prom-client";

// Create a Registry which registers the metrics
const register = new client.Registry();

// Add a default label which is added to all metrics
register.setDefaultLabels({
  app: "opencodehub",
});

// Enable the collection of default metrics
client.collectDefaultMetrics({ register });

// Define custom metrics
export const httpRequestDurationMicroseconds = new client.Histogram({
  name: "http_request_duration_seconds",
  help: "Duration of HTTP requests in seconds",
  labelNames: ["method", "route", "code"],
  buckets: [0.1, 0.3, 0.5, 0.7, 1, 3, 5, 7, 10],
});

export const activeRunners = new client.Gauge({
  name: "active_runners",
  help: "Number of active CI/CD runners",
});

register.registerMetric(httpRequestDurationMicroseconds);
register.registerMetric(activeRunners);

export { register };