diff --git a/src/controllers/api/streaming.ts b/src/controllers/api/streaming.ts index 31e8a398..4bbe6177 100644 --- a/src/controllers/api/streaming.ts +++ b/src/controllers/api/streaming.ts @@ -4,7 +4,11 @@ import { z } from 'zod'; import { type AppController } from '@/app.ts'; import { Conf } from '@/config.ts'; -import { streamingConnectionsGauge } from '@/metrics.ts'; +import { + streamingClientMessagesCounter, + streamingConnectionsGauge, + streamingServerMessagesCounter, +} from '@/metrics.ts'; import { MuteListPolicy } from '@/policies/MuteListPolicy.ts'; import { getFeedPubkeys } from '@/queries.ts'; import { hydrateEvents } from '@/storages/hydrate.ts'; @@ -96,6 +100,7 @@ const streamingController: AppController = async (c) => { function send(e: StreamingEvent) { if (socket.readyState === WebSocket.OPEN) { debug('send', e.event, e.payload); + streamingServerMessagesCounter.inc(); socket.send(JSON.stringify(e)); } } @@ -172,6 +177,8 @@ const streamingController: AppController = async (c) => { }; socket.onmessage = (e) => { + streamingClientMessagesCounter.inc(); + if (ip) { const count = limiter.get(ip) ?? 0; limiter.set(ip, count + 1, { ttl: LIMITER_WINDOW }); diff --git a/src/metrics.ts b/src/metrics.ts index 8d1a6531..1e20747b 100644 --- a/src/metrics.ts +++ b/src/metrics.ts @@ -17,6 +17,16 @@ export const streamingConnectionsGauge = new Gauge({ help: 'Number of active connections to the streaming API', }); +export const streamingServerMessagesCounter = new Counter({ + name: 'ditto_streaming_server_messages_total', + help: 'Total number of messages sent from the streaming API', +}); + +export const streamingClientMessagesCounter = new Counter({ + name: 'ditto_streaming_client_messages_total', + help: 'Total number of messages received by the streaming API', +}); + export const fetchCounter = new Counter({ name: 'ditto_fetch_total', help: 'Total number of fetch requests',