X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fstat-manager.ts;h=03063793d8121695bb5864755086545d80021341;hb=63a3d336f6cc9a293a07fdc12d6bdfb86cfc2fd5;hp=f9d69b0dc733d26b258efa7c3ea768e5f5f79549;hpb=99afa081bc6ae7f34b2105075bd43e3625434fa8;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/stat-manager.ts b/server/lib/stat-manager.ts index f9d69b0dc..03063793d 100644 --- a/server/lib/stat-manager.ts +++ b/server/lib/stat-manager.ts @@ -1,11 +1,14 @@ +import { mapSeries } from 'bluebird' import { CONFIG } from '@server/initializers/config' -import { UserModel } from '@server/models/account/user' -import { ActorFollowModel } from '@server/models/activitypub/actor-follow' +import { ActorFollowModel } from '@server/models/actor/actor-follow' import { VideoRedundancyModel } from '@server/models/redundancy/video-redundancy' +import { UserModel } from '@server/models/user/user' import { VideoModel } from '@server/models/video/video' +import { VideoChannelModel } from '@server/models/video/video-channel' import { VideoCommentModel } from '@server/models/video/video-comment' import { VideoFileModel } from '@server/models/video/video-file' -import { ServerStats, VideoRedundancyStrategyWithManual } from '@shared/models' +import { VideoPlaylistModel } from '@server/models/video/video-playlist' +import { ActivityType, ServerStats, VideoRedundancyStrategyWithManual } from '@shared/models' class StatsManager { @@ -13,14 +16,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 () { @@ -29,30 +49,43 @@ class StatsManager { const { totalUsers, totalDailyActiveUsers, totalWeeklyActiveUsers, totalMonthlyActiveUsers } = await UserModel.getStats() const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats() const { totalLocalVideoFilesSize } = await VideoFileModel.getStats() + const { + totalLocalVideoChannels, + totalLocalDailyActiveVideoChannels, + totalLocalWeeklyActiveVideoChannels, + totalLocalMonthlyActiveVideoChannels + } = await VideoChannelModel.getStats() + const { totalLocalPlaylists } = await VideoPlaylistModel.getStats() const videosRedundancyStats = await this.buildRedundancyStats() const data: ServerStats = { + totalUsers, + totalDailyActiveUsers, + totalWeeklyActiveUsers, + totalMonthlyActiveUsers, + totalLocalVideos, totalLocalVideoViews, - totalLocalVideoFilesSize, totalLocalVideoComments, + totalLocalVideoFilesSize, + totalVideos, totalVideoComments, - totalUsers, - totalDailyActiveUsers, - totalWeeklyActiveUsers, - totalMonthlyActiveUsers, + totalLocalVideoChannels, + totalLocalDailyActiveVideoChannels, + totalLocalWeeklyActiveVideoChannels, + totalLocalMonthlyActiveVideoChannels, + + totalLocalPlaylists, totalInstanceFollowers, totalInstanceFollowing, videosRedundancy: videosRedundancyStats, - totalActivityPubMessagesProcessed: this.inboxMessagesProcessed, - activityPubMessagesProcessedPerSecond: this.buildActivityPubMessagesProcessedPerSecond(), - totalActivityPubMessagesWaiting: this.inboxMessagesWaiting + ...this.buildAPStats() } return data @@ -62,7 +95,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 () { @@ -74,12 +107,67 @@ class StatsManager { strategies.push({ strategy: 'manual', size: null }) - return Promise.all( - strategies.map(r => { - return VideoRedundancyModel.getStats(r.strategy) - .then(stats => Object.assign(stats, { strategy: r.strategy, totalSize: r.size })) - }) - ) + return mapSeries(strategies, r => { + return VideoRedundancyModel.getStats(r.strategy) + .then(stats => Object.assign(stats, { strategy: r.strategy, totalSize: r.size })) + }) + } + + 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 () {