diff options
author | Chocobozzz <me@florianbigard.com> | 2021-02-26 10:28:11 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-02-26 10:28:11 +0100 |
commit | 543442a3be9d7740749eb3918dc59f502ff042f9 (patch) | |
tree | 3d2959757b7907ea9be8a6f6a69d4bab8521dbc3 /server/lib/stat-manager.ts | |
parent | cb2e36618ca5986949d4326ea939b5b08f3a9a82 (diff) | |
download | PeerTube-543442a3be9d7740749eb3918dc59f502ff042f9.tar.gz PeerTube-543442a3be9d7740749eb3918dc59f502ff042f9.tar.zst PeerTube-543442a3be9d7740749eb3918dc59f502ff042f9.zip |
Add more AP stats to stats endpoint
It will help to understand if the federation correctly works or not
Diffstat (limited to 'server/lib/stat-manager.ts')
-rw-r--r-- | server/lib/stat-manager.ts | 92 |
1 files changed, 82 insertions, 10 deletions
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 | |||
5 | import { VideoModel } from '@server/models/video/video' | 5 | import { VideoModel } from '@server/models/video/video' |
6 | import { VideoCommentModel } from '@server/models/video/video-comment' | 6 | import { VideoCommentModel } from '@server/models/video/video-comment' |
7 | import { VideoFileModel } from '@server/models/video/video-file' | 7 | import { VideoFileModel } from '@server/models/video/video-file' |
8 | import { ServerStats, VideoRedundancyStrategyWithManual } from '@shared/models' | 8 | import { ActivityType, ServerStats, VideoRedundancyStrategyWithManual } from '@shared/models' |
9 | 9 | ||
10 | class StatsManager { | 10 | class StatsManager { |
11 | 11 | ||
@@ -13,14 +13,31 @@ class StatsManager { | |||
13 | 13 | ||
14 | private readonly instanceStartDate = new Date() | 14 | private readonly instanceStartDate = new Date() |
15 | 15 | ||
16 | private inboxMessagesProcessed = 0 | 16 | private inboxMessages = { |
17 | private inboxMessagesWaiting = 0 | 17 | processed: 0, |
18 | errors: 0, | ||
19 | successes: 0, | ||
20 | waiting: 0, | ||
21 | errorsPerType: this.buildAPPerType(), | ||
22 | successesPerType: this.buildAPPerType() | ||
23 | } | ||
18 | 24 | ||
19 | private constructor () {} | 25 | private constructor () {} |
20 | 26 | ||
21 | updateInboxStats (inboxMessagesProcessed: number, inboxMessagesWaiting: number) { | 27 | updateInboxWaiting (inboxMessagesWaiting: number) { |
22 | this.inboxMessagesProcessed = inboxMessagesProcessed | 28 | this.inboxMessages.waiting = inboxMessagesWaiting |
23 | this.inboxMessagesWaiting = inboxMessagesWaiting | 29 | } |
30 | |||
31 | addInboxProcessedSuccess (type: ActivityType) { | ||
32 | this.inboxMessages.processed++ | ||
33 | this.inboxMessages.successes++ | ||
34 | this.inboxMessages.successesPerType[type]++ | ||
35 | } | ||
36 | |||
37 | addInboxProcessedError (type: ActivityType) { | ||
38 | this.inboxMessages.processed++ | ||
39 | this.inboxMessages.errors++ | ||
40 | this.inboxMessages.errorsPerType[type]++ | ||
24 | } | 41 | } |
25 | 42 | ||
26 | async getStats () { | 43 | async getStats () { |
@@ -50,9 +67,7 @@ class StatsManager { | |||
50 | 67 | ||
51 | videosRedundancy: videosRedundancyStats, | 68 | videosRedundancy: videosRedundancyStats, |
52 | 69 | ||
53 | totalActivityPubMessagesProcessed: this.inboxMessagesProcessed, | 70 | ...this.buildAPStats() |
54 | activityPubMessagesProcessedPerSecond: this.buildActivityPubMessagesProcessedPerSecond(), | ||
55 | totalActivityPubMessagesWaiting: this.inboxMessagesWaiting | ||
56 | } | 71 | } |
57 | 72 | ||
58 | return data | 73 | return data |
@@ -62,7 +77,7 @@ class StatsManager { | |||
62 | const now = new Date() | 77 | const now = new Date() |
63 | const startedSeconds = (now.getTime() - this.instanceStartDate.getTime()) / 1000 | 78 | const startedSeconds = (now.getTime() - this.instanceStartDate.getTime()) / 1000 |
64 | 79 | ||
65 | return this.inboxMessagesProcessed / startedSeconds | 80 | return this.inboxMessages.processed / startedSeconds |
66 | } | 81 | } |
67 | 82 | ||
68 | private buildRedundancyStats () { | 83 | private buildRedundancyStats () { |
@@ -82,6 +97,63 @@ class StatsManager { | |||
82 | ) | 97 | ) |
83 | } | 98 | } |
84 | 99 | ||
100 | private buildAPPerType () { | ||
101 | return { | ||
102 | Create: 0, | ||
103 | Update: 0, | ||
104 | Delete: 0, | ||
105 | Follow: 0, | ||
106 | Accept: 0, | ||
107 | Reject: 0, | ||
108 | Announce: 0, | ||
109 | Undo: 0, | ||
110 | Like: 0, | ||
111 | Dislike: 0, | ||
112 | Flag: 0, | ||
113 | View: 0 | ||
114 | } | ||
115 | } | ||
116 | |||
117 | private buildAPStats () { | ||
118 | return { | ||
119 | totalActivityPubMessagesProcessed: this.inboxMessages.processed, | ||
120 | |||
121 | totalActivityPubMessagesSuccesses: this.inboxMessages.successes, | ||
122 | |||
123 | // Dirty, but simpler and with type checking | ||
124 | totalActivityPubCreateMessagesSuccesses: this.inboxMessages.successesPerType.Create, | ||
125 | totalActivityPubUpdateMessagesSuccesses: this.inboxMessages.successesPerType.Update, | ||
126 | totalActivityPubDeleteMessagesSuccesses: this.inboxMessages.successesPerType.Delete, | ||
127 | totalActivityPubFollowMessagesSuccesses: this.inboxMessages.successesPerType.Follow, | ||
128 | totalActivityPubAcceptMessagesSuccesses: this.inboxMessages.successesPerType.Accept, | ||
129 | totalActivityPubRejectMessagesSuccesses: this.inboxMessages.successesPerType.Reject, | ||
130 | totalActivityPubAnnounceMessagesSuccesses: this.inboxMessages.successesPerType.Announce, | ||
131 | totalActivityPubUndoMessagesSuccesses: this.inboxMessages.successesPerType.Undo, | ||
132 | totalActivityPubLikeMessagesSuccesses: this.inboxMessages.successesPerType.Like, | ||
133 | totalActivityPubDislikeMessagesSuccesses: this.inboxMessages.successesPerType.Dislike, | ||
134 | totalActivityPubFlagMessagesSuccesses: this.inboxMessages.successesPerType.Flag, | ||
135 | totalActivityPubViewMessagesSuccesses: this.inboxMessages.successesPerType.View, | ||
136 | |||
137 | totalActivityPubCreateMessagesErrors: this.inboxMessages.errorsPerType.Create, | ||
138 | totalActivityPubUpdateMessagesErrors: this.inboxMessages.errorsPerType.Update, | ||
139 | totalActivityPubDeleteMessagesErrors: this.inboxMessages.errorsPerType.Delete, | ||
140 | totalActivityPubFollowMessagesErrors: this.inboxMessages.errorsPerType.Follow, | ||
141 | totalActivityPubAcceptMessagesErrors: this.inboxMessages.errorsPerType.Accept, | ||
142 | totalActivityPubRejectMessagesErrors: this.inboxMessages.errorsPerType.Reject, | ||
143 | totalActivityPubAnnounceMessagesErrors: this.inboxMessages.errorsPerType.Announce, | ||
144 | totalActivityPubUndoMessagesErrors: this.inboxMessages.errorsPerType.Undo, | ||
145 | totalActivityPubLikeMessagesErrors: this.inboxMessages.errorsPerType.Like, | ||
146 | totalActivityPubDislikeMessagesErrors: this.inboxMessages.errorsPerType.Dislike, | ||
147 | totalActivityPubFlagMessagesErrors: this.inboxMessages.errorsPerType.Flag, | ||
148 | totalActivityPubViewMessagesErrors: this.inboxMessages.errorsPerType.View, | ||
149 | |||
150 | totalActivityPubMessagesErrors: this.inboxMessages.errors, | ||
151 | |||
152 | activityPubMessagesProcessedPerSecond: this.buildActivityPubMessagesProcessedPerSecond(), | ||
153 | totalActivityPubMessagesWaiting: this.inboxMessages.waiting | ||
154 | } | ||
155 | } | ||
156 | |||
85 | static get Instance () { | 157 | static get Instance () { |
86 | return this.instance || (this.instance = new this()) | 158 | return this.instance || (this.instance = new this()) |
87 | } | 159 | } |