mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Add subscriptions bytes metrics
This commit is contained in:
parent
808c3f70f5
commit
fd87bad238
2 changed files with 10 additions and 1 deletions
|
|
@ -4,7 +4,7 @@ import { type DittoConf } from '@ditto/conf';
|
|||
import { type DittoDB, type DittoTables } from '@ditto/db';
|
||||
import { detectLanguage } from '@ditto/lang';
|
||||
import { NPostgres, NPostgresSchema } from '@nostrify/db';
|
||||
import { dbEventsCounter, internalSubscriptionsSizeGauge } from '@ditto/metrics';
|
||||
import { dbEventsCounter, internalSubscriptionsBytesGauge, internalSubscriptionsSizeGauge } from '@ditto/metrics';
|
||||
import {
|
||||
NIP50,
|
||||
NKinds,
|
||||
|
|
@ -354,8 +354,11 @@ export class DittoPgStore extends NPostgres {
|
|||
yield ['EOSE', subId];
|
||||
}
|
||||
|
||||
const sizeBytes = new TextEncoder().encode(JSON.stringify(filters)).length;
|
||||
|
||||
this.subs.set(subId, { filters, machina });
|
||||
internalSubscriptionsSizeGauge.set(this.subs.size);
|
||||
internalSubscriptionsBytesGauge.inc(sizeBytes);
|
||||
|
||||
try {
|
||||
for await (const msg of machina) {
|
||||
|
|
@ -370,6 +373,7 @@ export class DittoPgStore extends NPostgres {
|
|||
} finally {
|
||||
this.subs.delete(subId);
|
||||
internalSubscriptionsSizeGauge.set(this.subs.size);
|
||||
internalSubscriptionsBytesGauge.dec(sizeBytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -133,6 +133,11 @@ export const internalSubscriptionsSizeGauge: Gauge = new Gauge({
|
|||
help: "Number of active subscriptions to Ditto's internal relay",
|
||||
});
|
||||
|
||||
export const internalSubscriptionsBytesGauge: Gauge = new Gauge({
|
||||
name: `${prefix}_internal_subscriptions_bytes`,
|
||||
help: "Total size in bytes of active subscriptions to Ditto's internal relay",
|
||||
});
|
||||
|
||||
export const relayPoolRelaysSizeGauge: Gauge<'ready_state'> = new Gauge({
|
||||
name: `${prefix}_relay_pool_relays_size`,
|
||||
help: 'Number of relays in the relay pool',
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue