diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-07 11:07:12 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:17 +0200 |
commit | bc8090411ddaa8d742ce4de3c83f9dba7bc18e2a (patch) | |
tree | 5020b384b6bc4870b06c53a0483abf551b33604e /shared | |
parent | dab047092b51b453f175069573d8865fb17acdfc (diff) | |
download | PeerTube-bc8090411ddaa8d742ce4de3c83f9dba7bc18e2a.tar.gz PeerTube-bc8090411ddaa8d742ce4de3c83f9dba7bc18e2a.tar.zst PeerTube-bc8090411ddaa8d742ce4de3c83f9dba7bc18e2a.zip |
Introduce stats command
Diffstat (limited to 'shared')
-rw-r--r-- | shared/extra-utils/index.ts | 4 | ||||
-rw-r--r-- | shared/extra-utils/server/index.ts | 3 | ||||
-rw-r--r-- | shared/extra-utils/server/servers.ts | 3 | ||||
-rw-r--r-- | shared/extra-utils/server/stats-command.ts | 25 | ||||
-rw-r--r-- | shared/extra-utils/server/stats.ts | 23 |
5 files changed, 31 insertions, 27 deletions
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index cf6418249..f69d7241e 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts | |||
@@ -13,10 +13,6 @@ export * from './server' | |||
13 | export * from './requests/check-api-params' | 13 | export * from './requests/check-api-params' |
14 | export * from './requests/requests' | 14 | export * from './requests/requests' |
15 | 15 | ||
16 | export * from './server/clients' | ||
17 | export * from './server/config' | ||
18 | export * from './server/servers' | ||
19 | |||
20 | export * from './users/accounts' | 16 | export * from './users/accounts' |
21 | export * from './users/blocklist' | 17 | export * from './users/blocklist' |
22 | export * from './users/login' | 18 | export * from './users/login' |
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 @@ | |||
1 | export * from './config' | ||
1 | export * from './contact-form-command' | 2 | export * from './contact-form-command' |
2 | export * from './debug-command' | 3 | export * from './debug-command' |
3 | export * from './follows-command' | 4 | export * from './follows-command' |
@@ -7,3 +8,5 @@ export * from './jobs-command' | |||
7 | export * from './plugins-command' | 8 | export * from './plugins-command' |
8 | export * from './plugins' | 9 | export * from './plugins' |
9 | export * from './redundancy-command' | 10 | export * from './redundancy-command' |
11 | export * from './servers' | ||
12 | export * 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' | |||
22 | import { JobsCommand } from './jobs-command' | 22 | import { JobsCommand } from './jobs-command' |
23 | import { PluginsCommand } from './plugins-command' | 23 | import { PluginsCommand } from './plugins-command' |
24 | import { RedundancyCommand } from './redundancy-command' | 24 | import { RedundancyCommand } from './redundancy-command' |
25 | import { StatsCommand } from './stats-command' | ||
25 | 26 | ||
26 | interface ServerInfo { | 27 | interface 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 | ||
94 | function parallelTests () { | 96 | function 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 @@ | |||
1 | import { ServerStats } from '@shared/models' | ||
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export 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 @@ | |||
1 | import { makeGetRequest } from '../requests/requests' | ||
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | |||
4 | function 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 | |||
21 | export { | ||
22 | getStats | ||
23 | } | ||