diff options
author | Chocobozzz <me@florianbigard.com> | 2020-12-15 13:34:58 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-12-15 13:34:58 +0100 |
commit | 99afa081bc6ae7f34b2105075bd43e3625434fa8 (patch) | |
tree | 0caea8591b3d3688a133cf33edcad616bf276375 /server/controllers | |
parent | 48586fe070c2a59e9febb62a7f41ebb384e1d20e (diff) | |
download | PeerTube-99afa081bc6ae7f34b2105075bd43e3625434fa8.tar.gz PeerTube-99afa081bc6ae7f34b2105075bd43e3625434fa8.tar.zst PeerTube-99afa081bc6ae7f34b2105075bd43e3625434fa8.zip |
Add AP stats
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/activitypub/inbox.ts | 24 | ||||
-rw-r--r-- | server/controllers/api/server/stats.ts | 56 |
2 files changed, 11 insertions, 69 deletions
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts index 67b2c0d66..14f301ab7 100644 --- a/server/controllers/activitypub/inbox.ts +++ b/server/controllers/activitypub/inbox.ts | |||
@@ -1,13 +1,11 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { InboxManager } from '@server/lib/activitypub/inbox-manager' | ||
2 | import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, RootActivity } from '../../../shared' | 3 | import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, RootActivity } from '../../../shared' |
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' | 5 | import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' |
4 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
5 | import { processActivities } from '../../lib/activitypub/process/process' | ||
6 | import { asyncMiddleware, checkSignature, localAccountValidator, localVideoChannelValidator, signatureValidator } from '../../middlewares' | 7 | import { asyncMiddleware, checkSignature, localAccountValidator, localVideoChannelValidator, signatureValidator } from '../../middlewares' |
7 | import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' | 8 | import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' |
8 | import { queue } from 'async' | ||
9 | import { MActorDefault, MActorSignature } from '../../types/models' | ||
10 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
11 | 9 | ||
12 | const inboxRouter = express.Router() | 10 | const inboxRouter = express.Router() |
13 | 11 | ||
@@ -41,18 +39,6 @@ export { | |||
41 | 39 | ||
42 | // --------------------------------------------------------------------------- | 40 | // --------------------------------------------------------------------------- |
43 | 41 | ||
44 | type QueueParam = { activities: Activity[], signatureActor?: MActorSignature, inboxActor?: MActorDefault } | ||
45 | const inboxQueue = queue<QueueParam, Error>((task, cb) => { | ||
46 | const options = { signatureActor: task.signatureActor, inboxActor: task.inboxActor } | ||
47 | |||
48 | processActivities(task.activities, options) | ||
49 | .then(() => cb()) | ||
50 | .catch(err => { | ||
51 | logger.error('Error in process activities.', { err }) | ||
52 | cb() | ||
53 | }) | ||
54 | }) | ||
55 | |||
56 | function inboxController (req: express.Request, res: express.Response) { | 42 | function inboxController (req: express.Request, res: express.Response) { |
57 | const rootActivity: RootActivity = req.body | 43 | const rootActivity: RootActivity = req.body |
58 | let activities: Activity[] | 44 | let activities: Activity[] |
@@ -74,10 +60,12 @@ function inboxController (req: express.Request, res: express.Response) { | |||
74 | 60 | ||
75 | logger.info('Receiving inbox requests for %d activities by %s.', activities.length, res.locals.signature.actor.url) | 61 | logger.info('Receiving inbox requests for %d activities by %s.', activities.length, res.locals.signature.actor.url) |
76 | 62 | ||
77 | inboxQueue.push({ | 63 | InboxManager.Instance.addInboxMessage({ |
78 | activities, | 64 | activities, |
79 | signatureActor: res.locals.signature.actor, | 65 | signatureActor: res.locals.signature.actor, |
80 | inboxActor: accountOrChannel ? accountOrChannel.Actor : undefined | 66 | inboxActor: accountOrChannel |
67 | ? accountOrChannel.Actor | ||
68 | : undefined | ||
81 | }) | 69 | }) |
82 | 70 | ||
83 | return res.status(HttpStatusCode.NO_CONTENT_204).end() | 71 | return res.status(HttpStatusCode.NO_CONTENT_204).end() |
diff --git a/server/controllers/api/server/stats.ts b/server/controllers/api/server/stats.ts index f07301a04..3aea12450 100644 --- a/server/controllers/api/server/stats.ts +++ b/server/controllers/api/server/stats.ts | |||
@@ -1,16 +1,8 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { ServerStats } from '../../../../shared/models/server/server-stats.model' | 2 | import { StatsManager } from '@server/lib/stat-manager' |
3 | import { asyncMiddleware } from '../../../middlewares' | ||
4 | import { UserModel } from '../../../models/account/user' | ||
5 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | ||
6 | import { VideoModel } from '../../../models/video/video' | ||
7 | import { VideoCommentModel } from '../../../models/video/video-comment' | ||
8 | import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy' | ||
9 | import { ROUTE_CACHE_LIFETIME } from '../../../initializers/constants' | 3 | import { ROUTE_CACHE_LIFETIME } from '../../../initializers/constants' |
4 | import { asyncMiddleware } from '../../../middlewares' | ||
10 | import { cacheRoute } from '../../../middlewares/cache' | 5 | import { cacheRoute } from '../../../middlewares/cache' |
11 | import { VideoFileModel } from '../../../models/video/video-file' | ||
12 | import { CONFIG } from '../../../initializers/config' | ||
13 | import { VideoRedundancyStrategyWithManual } from '@shared/models' | ||
14 | 6 | ||
15 | const statsRouter = express.Router() | 7 | const statsRouter = express.Router() |
16 | 8 | ||
@@ -19,48 +11,10 @@ statsRouter.get('/stats', | |||
19 | asyncMiddleware(getStats) | 11 | asyncMiddleware(getStats) |
20 | ) | 12 | ) |
21 | 13 | ||
22 | async function getStats (req: express.Request, res: express.Response) { | 14 | async function getStats (_req: express.Request, res: express.Response) { |
23 | const { totalLocalVideos, totalLocalVideoViews, totalVideos } = await VideoModel.getStats() | 15 | const data = await StatsManager.Instance.getStats() |
24 | const { totalLocalVideoComments, totalVideoComments } = await VideoCommentModel.getStats() | ||
25 | const { totalUsers, totalDailyActiveUsers, totalWeeklyActiveUsers, totalMonthlyActiveUsers } = await UserModel.getStats() | ||
26 | const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats() | ||
27 | const { totalLocalVideoFilesSize } = await VideoFileModel.getStats() | ||
28 | |||
29 | const strategies = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES | ||
30 | .map(r => ({ | ||
31 | strategy: r.strategy as VideoRedundancyStrategyWithManual, | ||
32 | size: r.size | ||
33 | })) | ||
34 | |||
35 | strategies.push({ strategy: 'manual', size: null }) | ||
36 | |||
37 | const videosRedundancyStats = await Promise.all( | ||
38 | strategies.map(r => { | ||
39 | return VideoRedundancyModel.getStats(r.strategy) | ||
40 | .then(stats => Object.assign(stats, { strategy: r.strategy, totalSize: r.size })) | ||
41 | }) | ||
42 | ) | ||
43 | |||
44 | const data: ServerStats = { | ||
45 | totalLocalVideos, | ||
46 | totalLocalVideoViews, | ||
47 | totalLocalVideoFilesSize, | ||
48 | totalLocalVideoComments, | ||
49 | totalVideos, | ||
50 | totalVideoComments, | ||
51 | |||
52 | totalUsers, | ||
53 | totalDailyActiveUsers, | ||
54 | totalWeeklyActiveUsers, | ||
55 | totalMonthlyActiveUsers, | ||
56 | |||
57 | totalInstanceFollowers, | ||
58 | totalInstanceFollowing, | ||
59 | |||
60 | videosRedundancy: videosRedundancyStats | ||
61 | } | ||
62 | 16 | ||
63 | return res.json(data).end() | 17 | return res.json(data) |
64 | } | 18 | } |
65 | 19 | ||
66 | // --------------------------------------------------------------------------- | 20 | // --------------------------------------------------------------------------- |