From fd3c2e87051f5029cdec39d877b576a62f48e219 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 12 Aug 2022 16:41:29 +0200 Subject: Add playback metric endpoint sent to OTEL --- shared/models/index.ts | 1 + shared/models/metrics/index.ts | 1 + shared/models/metrics/playback-metric-create.model.ts | 19 +++++++++++++++++++ shared/server-commands/server/index.ts | 1 + shared/server-commands/server/metrics-command.ts | 18 ++++++++++++++++++ shared/server-commands/server/server.ts | 3 +++ 6 files changed, 43 insertions(+) create mode 100644 shared/models/metrics/index.ts create mode 100644 shared/models/metrics/playback-metric-create.model.ts create mode 100644 shared/server-commands/server/metrics-command.ts (limited to 'shared') diff --git a/shared/models/index.ts b/shared/models/index.ts index 78723d830..439e9c8e1 100644 --- a/shared/models/index.ts +++ b/shared/models/index.ts @@ -6,6 +6,7 @@ export * from './custom-markup' export * from './feeds' export * from './http' export * from './joinpeertube' +export * from './metrics' export * from './moderation' export * from './overviews' export * from './plugins' diff --git a/shared/models/metrics/index.ts b/shared/models/metrics/index.ts new file mode 100644 index 000000000..24194cce3 --- /dev/null +++ b/shared/models/metrics/index.ts @@ -0,0 +1 @@ +export * from './playback-metric-create.model' diff --git a/shared/models/metrics/playback-metric-create.model.ts b/shared/models/metrics/playback-metric-create.model.ts new file mode 100644 index 000000000..d669ab690 --- /dev/null +++ b/shared/models/metrics/playback-metric-create.model.ts @@ -0,0 +1,19 @@ +import { VideoResolution } from '../videos' + +export interface PlaybackMetricCreate { + playerMode: 'p2p-media-loader' | 'webtorrent' + + resolution?: VideoResolution + fps?: number + + resolutionChanges: number + + errors: number + + downloadedBytesP2P: number + downloadedBytesHTTP: number + + uploadedBytesP2P: number + + videoId: number | string +} diff --git a/shared/server-commands/server/index.ts b/shared/server-commands/server/index.ts index 0a4b21fc4..9a2fbf8d3 100644 --- a/shared/server-commands/server/index.ts +++ b/shared/server-commands/server/index.ts @@ -5,6 +5,7 @@ export * from './follows-command' export * from './follows' export * from './jobs' export * from './jobs-command' +export * from './metrics-command' export * from './object-storage-command' export * from './plugins-command' export * from './redundancy-command' diff --git a/shared/server-commands/server/metrics-command.ts b/shared/server-commands/server/metrics-command.ts new file mode 100644 index 000000000..d22b4833d --- /dev/null +++ b/shared/server-commands/server/metrics-command.ts @@ -0,0 +1,18 @@ +import { HttpStatusCode, PlaybackMetricCreate } from '@shared/models' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class MetricsCommand extends AbstractCommand { + + addPlaybackMetric (options: OverrideCommandOptions & { metrics: PlaybackMetricCreate }) { + const path = '/api/v1/metrics/playback' + + return this.postBodyRequest({ + ...options, + + path, + fields: options.metrics, + implicitToken: false, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } +} diff --git a/shared/server-commands/server/server.ts b/shared/server-commands/server/server.ts index c05d16ad2..2b4c9c9f8 100644 --- a/shared/server-commands/server/server.ts +++ b/shared/server-commands/server/server.ts @@ -37,6 +37,7 @@ import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' import { FollowsCommand } from './follows-command' import { JobsCommand } from './jobs-command' +import { MetricsCommand } from './metrics-command' import { ObjectStorageCommand } from './object-storage-command' import { PluginsCommand } from './plugins-command' import { RedundancyCommand } from './redundancy-command' @@ -104,6 +105,7 @@ export class PeerTubeServer { debug?: DebugCommand follows?: FollowsCommand jobs?: JobsCommand + metrics?: MetricsCommand plugins?: PluginsCommand redundancy?: RedundancyCommand stats?: StatsCommand @@ -377,6 +379,7 @@ export class PeerTubeServer { this.debug = new DebugCommand(this) this.follows = new FollowsCommand(this) this.jobs = new JobsCommand(this) + this.metrics = new MetricsCommand(this) this.plugins = new PluginsCommand(this) this.redundancy = new RedundancyCommand(this) this.stats = new StatsCommand(this) -- cgit v1.2.3