mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
metrics: add messages sent and received by streaming API
This commit is contained in:
parent
fc7228e183
commit
195cf9f44e
2 changed files with 18 additions and 1 deletions
|
|
@ -4,7 +4,11 @@ import { z } from 'zod';
|
||||||
|
|
||||||
import { type AppController } from '@/app.ts';
|
import { type AppController } from '@/app.ts';
|
||||||
import { Conf } from '@/config.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 { MuteListPolicy } from '@/policies/MuteListPolicy.ts';
|
||||||
import { getFeedPubkeys } from '@/queries.ts';
|
import { getFeedPubkeys } from '@/queries.ts';
|
||||||
import { hydrateEvents } from '@/storages/hydrate.ts';
|
import { hydrateEvents } from '@/storages/hydrate.ts';
|
||||||
|
|
@ -96,6 +100,7 @@ const streamingController: AppController = async (c) => {
|
||||||
function send(e: StreamingEvent) {
|
function send(e: StreamingEvent) {
|
||||||
if (socket.readyState === WebSocket.OPEN) {
|
if (socket.readyState === WebSocket.OPEN) {
|
||||||
debug('send', e.event, e.payload);
|
debug('send', e.event, e.payload);
|
||||||
|
streamingServerMessagesCounter.inc();
|
||||||
socket.send(JSON.stringify(e));
|
socket.send(JSON.stringify(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -172,6 +177,8 @@ const streamingController: AppController = async (c) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
socket.onmessage = (e) => {
|
socket.onmessage = (e) => {
|
||||||
|
streamingClientMessagesCounter.inc();
|
||||||
|
|
||||||
if (ip) {
|
if (ip) {
|
||||||
const count = limiter.get(ip) ?? 0;
|
const count = limiter.get(ip) ?? 0;
|
||||||
limiter.set(ip, count + 1, { ttl: LIMITER_WINDOW });
|
limiter.set(ip, count + 1, { ttl: LIMITER_WINDOW });
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,16 @@ export const streamingConnectionsGauge = new Gauge({
|
||||||
help: 'Number of active connections to the streaming API',
|
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({
|
export const fetchCounter = new Counter({
|
||||||
name: 'ditto_fetch_total',
|
name: 'ditto_fetch_total',
|
||||||
help: 'Total number of fetch requests',
|
help: 'Total number of fetch requests',
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue