mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
prometheus: add gauges for websocket connections
This commit is contained in:
parent
4ed289e5c3
commit
e6cd3d9e47
3 changed files with 22 additions and 2 deletions
|
|
@ -5,6 +5,7 @@ import { z } from 'zod';
|
|||
import { type AppController } from '@/app.ts';
|
||||
import { Conf } from '@/config.ts';
|
||||
import { DittoDB } from '@/db/DittoDB.ts';
|
||||
import { streamingConnectionsGauge } from '@/metrics.ts';
|
||||
import { MuteListPolicy } from '@/policies/MuteListPolicy.ts';
|
||||
import { getFeedPubkeys } from '@/queries.ts';
|
||||
import { hydrateEvents } from '@/storages/hydrate.ts';
|
||||
|
|
@ -97,6 +98,8 @@ const streamingController: AppController = async (c) => {
|
|||
}
|
||||
|
||||
socket.onopen = async () => {
|
||||
streamingConnectionsGauge.inc();
|
||||
|
||||
if (!stream) return;
|
||||
const topicFilter = await topicToFilter(stream, c.req.query(), pubkey);
|
||||
|
||||
|
|
@ -120,6 +123,7 @@ const streamingController: AppController = async (c) => {
|
|||
};
|
||||
|
||||
socket.onclose = () => {
|
||||
streamingConnectionsGauge.dec();
|
||||
controller.abort();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Counter } from 'prom-client';
|
||||
import { Counter, Gauge } from 'prom-client';
|
||||
|
||||
export const httpRequestCounter = new Counter({
|
||||
name: 'http_requests_total',
|
||||
|
|
@ -6,6 +6,11 @@ export const httpRequestCounter = new Counter({
|
|||
labelNames: ['method'],
|
||||
});
|
||||
|
||||
export const streamingConnectionsGauge = new Gauge({
|
||||
name: 'streaming_connections',
|
||||
help: 'Number of active connections to the streaming API',
|
||||
});
|
||||
|
||||
export const fetchCounter = new Counter({
|
||||
name: 'fetch_total',
|
||||
help: 'Total number of fetch requests',
|
||||
|
|
@ -36,6 +41,11 @@ export const relayMessageCounter = new Counter({
|
|||
labelNames: ['verb'],
|
||||
});
|
||||
|
||||
export const relayConnectionsGauge = new Gauge({
|
||||
name: 'relay_connections',
|
||||
help: 'Number of active connections to the relay',
|
||||
});
|
||||
|
||||
export const dbQueryCounter = new Counter({
|
||||
name: 'db_query_total',
|
||||
help: 'Total number of database queries',
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue