mirror of
https://github.com/aljazceru/ditto.git
synced 2025-12-18 22:14:23 +01:00
prometheus: add gauges for websocket connections
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
||||
|
||||
import { AppController } from '@/app.ts';
|
||||
import { relayInfoController } from '@/controllers/nostr/relay-info.ts';
|
||||
import { relayEventCounter, relayMessageCounter } from '@/metrics.ts';
|
||||
import { relayConnectionsGauge, relayEventCounter, relayMessageCounter } from '@/metrics.ts';
|
||||
import * as pipeline from '@/pipeline.ts';
|
||||
import { RelayError } from '@/RelayError.ts';
|
||||
import { Storages } from '@/storages.ts';
|
||||
@@ -22,6 +22,10 @@ const FILTER_LIMIT = 100;
|
||||
function connectStream(socket: WebSocket) {
|
||||
const controllers = new Map<string, AbortController>();
|
||||
|
||||
socket.onopen = () => {
|
||||
relayConnectionsGauge.inc();
|
||||
};
|
||||
|
||||
socket.onmessage = (e) => {
|
||||
const result = n.json().pipe(n.clientMsg()).safeParse(e.data);
|
||||
if (result.success) {
|
||||
@@ -34,6 +38,8 @@ function connectStream(socket: WebSocket) {
|
||||
};
|
||||
|
||||
socket.onclose = () => {
|
||||
relayConnectionsGauge.dec();
|
||||
|
||||
for (const controller of controllers.values()) {
|
||||
controller.abort();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user