mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
relay: fix connection metrics
This commit is contained in:
parent
9c9b87bc94
commit
5a0a2087e5
1 changed files with 7 additions and 6 deletions
|
|
@ -26,14 +26,16 @@ const LIMITER_LIMIT = 300;
|
||||||
|
|
||||||
const limiter = new TTLCache<string, number>();
|
const limiter = new TTLCache<string, number>();
|
||||||
|
|
||||||
|
/** Connections for metrics purposes. */
|
||||||
|
const connections = new Set<WebSocket>();
|
||||||
|
|
||||||
/** Set up the Websocket connection. */
|
/** Set up the Websocket connection. */
|
||||||
function connectStream(socket: WebSocket, ip: string | undefined) {
|
function connectStream(socket: WebSocket, ip: string | undefined) {
|
||||||
let opened = false;
|
|
||||||
const controllers = new Map<string, AbortController>();
|
const controllers = new Map<string, AbortController>();
|
||||||
|
|
||||||
socket.onopen = () => {
|
socket.onopen = () => {
|
||||||
opened = true;
|
connections.add(socket);
|
||||||
relayConnectionsGauge.inc();
|
relayConnectionsGauge.set(connections.size);
|
||||||
};
|
};
|
||||||
|
|
||||||
socket.onmessage = (e) => {
|
socket.onmessage = (e) => {
|
||||||
|
|
@ -63,9 +65,8 @@ function connectStream(socket: WebSocket, ip: string | undefined) {
|
||||||
};
|
};
|
||||||
|
|
||||||
socket.onclose = () => {
|
socket.onclose = () => {
|
||||||
if (opened) {
|
connections.delete(socket);
|
||||||
relayConnectionsGauge.dec();
|
relayConnectionsGauge.set(connections.size);
|
||||||
}
|
|
||||||
|
|
||||||
for (const controller of controllers.values()) {
|
for (const controller of controllers.values()) {
|
||||||
controller.abort();
|
controller.abort();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue