notifications metrics #28
2 changed files with 26 additions and 0 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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' });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue