From 543442a3be9d7740749eb3918dc59f502ff042f9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 26 Feb 2021 10:28:11 +0100 Subject: Add more AP stats to stats endpoint It will help to understand if the federation correctly works or not --- server/lib/stat-manager.ts | 92 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 10 deletions(-) (limited to 'server/lib/stat-manager.ts') diff --git a/server/lib/stat-manager.ts b/server/lib/stat-manager.ts index f9d69b0dc..547d7a56b 100644 --- a/server/lib/stat-manager.ts +++ b/server/lib/stat-manager.ts @@ -5,7 +5,7 @@ import { VideoRedundancyModel } from '@server/models/redundancy/video-redundancy import { VideoModel } from '@server/models/video/video' import { VideoCommentModel } from '@server/models/video/video-comment' import { VideoFileModel } from '@server/models/video/video-file' -import { ServerStats, VideoRedundancyStrategyWithManual } from '@shared/models' +import { ActivityType, ServerStats, VideoRedundancyStrategyWithManual } from '@shared/models' class StatsManager { @@ -13,14 +13,31 @@ class StatsManager { private readonly instanceStartDate = new Date() - private inboxMessagesProcessed = 0 - private inboxMessagesWaiting = 0 + private inboxMessages = { + processed: 0, + errors: 0, + successes: 0, + waiting: 0, + errorsPerType: this.buildAPPerType(), + successesPerType: this.buildAPPerType() + } private constructor () {} - updateInboxStats (inboxMessagesProcessed: number, inboxMessagesWaiting: number) { - this.inboxMessagesProcessed = inboxMessagesProcessed - this.inboxMessagesWaiting = inboxMessagesWaiting + updateInboxWaiting (inboxMessagesWaiting: number) { + this.inboxMessages.waiting = inboxMessagesWaiting + } + + addInboxProcessedSuccess (type: ActivityType) { + this.inboxMessages.processed++ + this.inboxMessages.successes++ + this.inboxMessages.successesPerType[type]++ + } + + addInboxProcessedError (type: ActivityType) { + this.inboxMessages.processed++ + this.inboxMessages.errors++ + this.inboxMessages.errorsPerType[type]++ } async getStats () { @@ -50,9 +67,7 @@ class StatsManager { videosRedundancy: videosRedundancyStats, - totalActivityPubMessagesProcessed: this.inboxMessagesProcessed, - activityPubMessagesProcessedPerSecond: this.buildActivityPubMessagesProcessedPerSecond(), - totalActivityPubMessagesWaiting: this.inboxMessagesWaiting + ...this.buildAPStats() } return data @@ -62,7 +77,7 @@ class StatsManager { const now = new Date() const startedSeconds = (now.getTime() - this.instanceStartDate.getTime()) / 1000 - return this.inboxMessagesProcessed / startedSeconds + return this.inboxMessages.processed / startedSeconds } private buildRedundancyStats () { @@ -82,6 +97,63 @@ class StatsManager { ) } + private buildAPPerType () { + return { + Create: 0, + Update: 0, + Delete: 0, + Follow: 0, + Accept: 0, + Reject: 0, + Announce: 0, + Undo: 0, + Like: 0, + Dislike: 0, + Flag: 0, + View: 0 + } + } + + private buildAPStats () { + return { + totalActivityPubMessagesProcessed: this.inboxMessages.processed, + + totalActivityPubMessagesSuccesses: this.inboxMessages.successes, + + // Dirty, but simpler and with type checking + totalActivityPubCreateMessagesSuccesses: this.inboxMessages.successesPerType.Create, + totalActivityPubUpdateMessagesSuccesses: this.inboxMessages.successesPerType.Update, + totalActivityPubDeleteMessagesSuccesses: this.inboxMessages.successesPerType.Delete, + totalActivityPubFollowMessagesSuccesses: this.inboxMessages.successesPerType.Follow, + totalActivityPubAcceptMessagesSuccesses: this.inboxMessages.successesPerType.Accept, + totalActivityPubRejectMessagesSuccesses: this.inboxMessages.successesPerType.Reject, + totalActivityPubAnnounceMessagesSuccesses: this.inboxMessages.successesPerType.Announce, + totalActivityPubUndoMessagesSuccesses: this.inboxMessages.successesPerType.Undo, + totalActivityPubLikeMessagesSuccesses: this.inboxMessages.successesPerType.Like, + totalActivityPubDislikeMessagesSuccesses: this.inboxMessages.successesPerType.Dislike, + totalActivityPubFlagMessagesSuccesses: this.inboxMessages.successesPerType.Flag, + totalActivityPubViewMessagesSuccesses: this.inboxMessages.successesPerType.View, + + totalActivityPubCreateMessagesErrors: this.inboxMessages.errorsPerType.Create, + totalActivityPubUpdateMessagesErrors: this.inboxMessages.errorsPerType.Update, + totalActivityPubDeleteMessagesErrors: this.inboxMessages.errorsPerType.Delete, + totalActivityPubFollowMessagesErrors: this.inboxMessages.errorsPerType.Follow, + totalActivityPubAcceptMessagesErrors: this.inboxMessages.errorsPerType.Accept, + totalActivityPubRejectMessagesErrors: this.inboxMessages.errorsPerType.Reject, + totalActivityPubAnnounceMessagesErrors: this.inboxMessages.errorsPerType.Announce, + totalActivityPubUndoMessagesErrors: this.inboxMessages.errorsPerType.Undo, + totalActivityPubLikeMessagesErrors: this.inboxMessages.errorsPerType.Like, + totalActivityPubDislikeMessagesErrors: this.inboxMessages.errorsPerType.Dislike, + totalActivityPubFlagMessagesErrors: this.inboxMessages.errorsPerType.Flag, + totalActivityPubViewMessagesErrors: this.inboxMessages.errorsPerType.View, + + totalActivityPubMessagesErrors: this.inboxMessages.errors, + + activityPubMessagesProcessedPerSecond: this.buildActivityPubMessagesProcessedPerSecond(), + totalActivityPubMessagesWaiting: this.inboxMessages.waiting + } + } + static get Instance () { return this.instance || (this.instance = new this()) } -- cgit v1.2.3