aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/server/stats.ts56
1 files changed, 5 insertions, 51 deletions
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { ServerStats } from '../../../../shared/models/server/server-stats.model' 2import { StatsManager } from '@server/lib/stat-manager'
3import { asyncMiddleware } from '../../../middlewares'
4import { UserModel } from '../../../models/account/user'
5import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
6import { VideoModel } from '../../../models/video/video'
7import { VideoCommentModel } from '../../../models/video/video-comment'
8import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy'
9import { ROUTE_CACHE_LIFETIME } from '../../../initializers/constants' 3import { ROUTE_CACHE_LIFETIME } from '../../../initializers/constants'
4import { asyncMiddleware } from '../../../middlewares'
10import { cacheRoute } from '../../../middlewares/cache' 5import { cacheRoute } from '../../../middlewares/cache'
11import { VideoFileModel } from '../../../models/video/video-file'
12import { CONFIG } from '../../../initializers/config'
13import { VideoRedundancyStrategyWithManual } from '@shared/models'
14 6
15const statsRouter = express.Router() 7const statsRouter = express.Router()
16 8
@@ -19,48 +11,10 @@ statsRouter.get('/stats',
19 asyncMiddleware(getStats) 11 asyncMiddleware(getStats)
20) 12)
21 13
22async function getStats (req: express.Request, res: express.Response) { 14async 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// ---------------------------------------------------------------------------