aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-07 11:07:12 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:17 +0200
commitbc8090411ddaa8d742ce4de3c83f9dba7bc18e2a (patch)
tree5020b384b6bc4870b06c53a0483abf551b33604e /shared/extra-utils/server
parentdab047092b51b453f175069573d8865fb17acdfc (diff)
downloadPeerTube-bc8090411ddaa8d742ce4de3c83f9dba7bc18e2a.tar.gz
PeerTube-bc8090411ddaa8d742ce4de3c83f9dba7bc18e2a.tar.zst
PeerTube-bc8090411ddaa8d742ce4de3c83f9dba7bc18e2a.zip
Introduce stats command
Diffstat (limited to 'shared/extra-utils/server')
-rw-r--r--shared/extra-utils/server/index.ts3
-rw-r--r--shared/extra-utils/server/servers.ts3
-rw-r--r--shared/extra-utils/server/stats-command.ts25
-rw-r--r--shared/extra-utils/server/stats.ts23
4 files changed, 31 insertions, 23 deletions
diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts
index 3ee70f0cf..d37f46321 100644
--- a/shared/extra-utils/server/index.ts
+++ b/shared/extra-utils/server/index.ts
@@ -1,3 +1,4 @@
1export * from './config'
1export * from './contact-form-command' 2export * from './contact-form-command'
2export * from './debug-command' 3export * from './debug-command'
3export * from './follows-command' 4export * from './follows-command'
@@ -7,3 +8,5 @@ export * from './jobs-command'
7export * from './plugins-command' 8export * from './plugins-command'
8export * from './plugins' 9export * from './plugins'
9export * from './redundancy-command' 10export * from './redundancy-command'
11export * from './servers'
12export * from './stats-command'
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
index eaf39ecea..4603cf62e 100644
--- a/shared/extra-utils/server/servers.ts
+++ b/shared/extra-utils/server/servers.ts
@@ -22,6 +22,7 @@ import { FollowsCommand } from './follows-command'
22import { JobsCommand } from './jobs-command' 22import { JobsCommand } from './jobs-command'
23import { PluginsCommand } from './plugins-command' 23import { PluginsCommand } from './plugins-command'
24import { RedundancyCommand } from './redundancy-command' 24import { RedundancyCommand } from './redundancy-command'
25import { StatsCommand } from './stats-command'
25 26
26interface ServerInfo { 27interface ServerInfo {
27 app: ChildProcess 28 app: ChildProcess
@@ -89,6 +90,7 @@ interface ServerInfo {
89 jobsCommand?: JobsCommand 90 jobsCommand?: JobsCommand
90 pluginsCommand?: PluginsCommand 91 pluginsCommand?: PluginsCommand
91 redundancyCommand?: RedundancyCommand 92 redundancyCommand?: RedundancyCommand
93 statsCommand?: StatsCommand
92} 94}
93 95
94function parallelTests () { 96function parallelTests () {
@@ -308,6 +310,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
308 server.jobsCommand = new JobsCommand(server) 310 server.jobsCommand = new JobsCommand(server)
309 server.pluginsCommand = new PluginsCommand(server) 311 server.pluginsCommand = new PluginsCommand(server)
310 server.redundancyCommand = new RedundancyCommand(server) 312 server.redundancyCommand = new RedundancyCommand(server)
313 server.statsCommand = new StatsCommand(server)
311 314
312 res(server) 315 res(server)
313 }) 316 })
diff --git a/shared/extra-utils/server/stats-command.ts b/shared/extra-utils/server/stats-command.ts
new file mode 100644
index 000000000..b51d9ceef
--- /dev/null
+++ b/shared/extra-utils/server/stats-command.ts
@@ -0,0 +1,25 @@
1import { ServerStats } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
3import { AbstractCommand, OverrideCommandOptions } from '../shared'
4
5export class StatsCommand extends AbstractCommand {
6
7 get (options: OverrideCommandOptions & {
8 useCache?: boolean // default false
9 } = {}) {
10 const { useCache = false } = options
11 const path = '/api/v1/server/stats'
12
13 const query = {
14 t: useCache ? undefined : new Date().getTime()
15 }
16
17 return this.getRequestBody<ServerStats>({
18 ...options,
19
20 path,
21 query,
22 defaultExpectedStatus: HttpStatusCode.OK_200
23 })
24 }
25}
diff --git a/shared/extra-utils/server/stats.ts b/shared/extra-utils/server/stats.ts
deleted file mode 100644
index b9dae24e2..000000000
--- a/shared/extra-utils/server/stats.ts
+++ /dev/null
@@ -1,23 +0,0 @@
1import { makeGetRequest } from '../requests/requests'
2import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
3
4function getStats (url: string, useCache = false) {
5 const path = '/api/v1/server/stats'
6
7 const query = {
8 t: useCache ? undefined : new Date().getTime()
9 }
10
11 return makeGetRequest({
12 url,
13 path,
14 query,
15 statusCodeExpected: HttpStatusCode.OK_200
16 })
17}
18
19// ---------------------------------------------------------------------------
20
21export {
22 getStats
23}