From f0c0b75285175cc8f0dd4ba2fd20da7256621530 Mon Sep 17 00:00:00 2001 From: eternal-flame-AD Date: Mon, 18 Nov 2024 13:47:18 -0600 Subject: [PATCH] notifications metrics Signed-off-by: eternal-flame-AD --- .../backend/src/core/NotificationService.ts | 9 +++++++++ .../backend/src/core/PushNotificationService.ts | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/packages/backend/src/core/NotificationService.ts b/packages/backend/src/core/NotificationService.ts index 68ad92f396..5827c99b3c 100644 --- a/packages/backend/src/core/NotificationService.ts +++ b/packages/backend/src/core/NotificationService.ts @@ -21,6 +21,13 @@ import type { Config } from '@/config.js'; import { UserListService } from '@/core/UserListService.js'; import type { FilterUnionByProperty } from '@/types.js'; import { trackPromise } from '@/misc/promise-tracker.js'; +import { metricCounter } from '@/server/api/MetricsService.js'; + +const mNotificationsCreated = metricCounter({ + name: 'misskey_notifications_created', + help: 'Notifications created', + labelNames: ['event_type'], +}); @Injectable() export class NotificationService implements OnApplicationShutdown { @@ -165,6 +172,8 @@ export class NotificationService implements OnApplicationShutdown { if (packed == null) return null; + mNotificationsCreated?.inc({ event_type: notification.type }); + // Publish notification event this.globalEventService.publishMainStream(notifieeId, 'notification', packed); diff --git a/packages/backend/src/core/PushNotificationService.ts b/packages/backend/src/core/PushNotificationService.ts index 1479bb00d9..c71c668fbe 100644 --- a/packages/backend/src/core/PushNotificationService.ts +++ b/packages/backend/src/core/PushNotificationService.ts @@ -13,6 +13,19 @@ import { getNoteSummary } from '@/misc/get-note-summary.js'; import type { MiMeta, MiSwSubscription, SwSubscriptionsRepository } from '@/models/_.js'; import { bindThis } from '@/decorators.js'; import { RedisKVCache } from '@/misc/cache.js'; +import { metricCounter } from '@/server/api/MetricsService.js'; + +const mWebPushCreated = metricCounter({ + name: 'misskey_webpush_created', + help: 'WebPush event', + labelNames: ['event_type'], +}); + +const mWebPushError = metricCounter({ + name: 'misskey_webpush_error', + help: 'WebPush error', + labelNames: ['event_type', 'status'], +}); // Defined also packages/sw/types.ts#L13 type PushNotificationsTypes = { @@ -95,6 +108,8 @@ export class PushNotificationService implements OnApplicationShutdown { }, }; + mWebPushCreated?.inc({ event_type: type }); + push.sendNotification(pushSubscription, JSON.stringify({ type, body: (type === 'notification' || type === 'unreadAntennaNote') ? truncateBody(type, body) : body, @@ -116,6 +131,8 @@ export class PushNotificationService implements OnApplicationShutdown { }).then(() => { this.refreshCache(userId); }); + } else { + mWebPushError?.inc({ event_type: type, status: err.statusCode || 'unknown' }); } }); } -- 2.45.2