MCPcopy
hub / github.com/soketi/soketi / PrometheusMetricsDriver

Class PrometheusMetricsDriver

src/metrics/prometheus-metrics-driver.ts:35–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33}
34
35export class PrometheusMetricsDriver implements MetricsInterface {
36 /**
37 * The list of metrics that will register.
38 *
39 * @type {PrometheusMetrics}
40 */
41 protected metrics: PrometheusMetrics = {
42 // TODO: Metrics for subscribes/unsubscribes/client events?
43 };
44
45 /**
46 * Prometheus register repo.
47 *
48 * @type {prom.Registry}
49 */
50 register: prom.Registry;
51
52 /**
53 * The infra-related metadata.
54 *
55 * @type {InfraMetadata}
56 */
57 protected infraMetadata: InfraMetadata = {
58 //
59 };
60
61 /**
62 * Initialize the Prometheus exporter.
63 */
64 constructor(protected server: Server) {
65 this.register = new prom.Registry();
66
67 this.registerMetrics();
68
69 this.infraMetadata = {
70 port: server.options.port
71 };
72
73 prom.collectDefaultMetrics({
74 prefix: server.options.metrics.prometheus.prefix,
75 register: this.register,
76 labels: this.infraMetadata,
77 });
78 }
79
80 /**
81 * Handle a new connection.
82 */
83 markNewConnection(ws: WebSocket): void {
84 this.metrics.connectedSockets.inc(this.getTags(ws.app.id));
85 this.metrics.newConnectionsTotal.inc(this.getTags(ws.app.id));
86 }
87
88 /**
89 * Handle a disconnection.
90 */
91 markDisconnection(ws: WebSocket): void {
92 this.metrics.connectedSockets.dec(this.getTags(ws.app.id));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected