diff options
author | Chocobozzz <me@florianbigard.com> | 2022-07-27 16:19:25 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-07-27 16:19:25 +0200 |
commit | adc94cf09c86112051f72055852efcc977e4a04a (patch) | |
tree | ae6f25824c1e66004fa69aa9f685642d8d7ad8b4 /server/lib/opentelemetry | |
parent | 50cc1ee48aacb6e7d6513c0f108492a589b515ea (diff) | |
download | PeerTube-adc94cf09c86112051f72055852efcc977e4a04a.tar.gz PeerTube-adc94cf09c86112051f72055852efcc977e4a04a.tar.zst PeerTube-adc94cf09c86112051f72055852efcc977e4a04a.zip |
Add live and viewers otel metrics
Diffstat (limited to 'server/lib/opentelemetry')
4 files changed, 60 insertions, 1 deletions
diff --git a/server/lib/opentelemetry/metric-helpers/index.ts b/server/lib/opentelemetry/metric-helpers/index.ts index ff0aff9fd..1b3813743 100644 --- a/server/lib/opentelemetry/metric-helpers/index.ts +++ b/server/lib/opentelemetry/metric-helpers/index.ts | |||
@@ -1,3 +1,5 @@ | |||
1 | export * from './lives-observers-builder' | ||
1 | export * from './job-queue-observers-builder' | 2 | export * from './job-queue-observers-builder' |
2 | export * from './nodejs-observers-builder' | 3 | export * from './nodejs-observers-builder' |
3 | export * from './stats-observers-builder' | 4 | export * from './stats-observers-builder' |
5 | export * from './viewers-observers-builder' | ||
diff --git a/server/lib/opentelemetry/metric-helpers/lives-observers-builder.ts b/server/lib/opentelemetry/metric-helpers/lives-observers-builder.ts new file mode 100644 index 000000000..e27bd8548 --- /dev/null +++ b/server/lib/opentelemetry/metric-helpers/lives-observers-builder.ts | |||
@@ -0,0 +1,21 @@ | |||
1 | import { Meter } from '@opentelemetry/api-metrics' | ||
2 | import { VideoModel } from '@server/models/video/video' | ||
3 | |||
4 | export class LivesObserversBuilder { | ||
5 | |||
6 | constructor (private readonly meter: Meter) { | ||
7 | |||
8 | } | ||
9 | |||
10 | buildObservers () { | ||
11 | this.meter.createObservableGauge('peertube_running_lives_total', { | ||
12 | description: 'Total running lives on the instance' | ||
13 | }).addCallback(async observableResult => { | ||
14 | const local = await VideoModel.countLives({ remote: false, mode: 'published' }) | ||
15 | const remote = await VideoModel.countLives({ remote: true, mode: 'published' }) | ||
16 | |||
17 | observableResult.observe(local, { liveOrigin: 'local' }) | ||
18 | observableResult.observe(remote, { liveOrigin: 'remote' }) | ||
19 | }) | ||
20 | } | ||
21 | } | ||
diff --git a/server/lib/opentelemetry/metric-helpers/viewers-observers-builder.ts b/server/lib/opentelemetry/metric-helpers/viewers-observers-builder.ts new file mode 100644 index 000000000..634e5bbc9 --- /dev/null +++ b/server/lib/opentelemetry/metric-helpers/viewers-observers-builder.ts | |||
@@ -0,0 +1,24 @@ | |||
1 | import { Meter } from '@opentelemetry/api-metrics' | ||
2 | import { VideoScope, ViewerScope } from '@server/lib/views/shared' | ||
3 | import { VideoViewsManager } from '@server/lib/views/video-views-manager' | ||
4 | |||
5 | export class ViewersObserversBuilder { | ||
6 | |||
7 | constructor (private readonly meter: Meter) { | ||
8 | |||
9 | } | ||
10 | |||
11 | buildObservers () { | ||
12 | this.meter.createObservableGauge('peertube_viewers_total', { | ||
13 | description: 'Total viewers on the instance' | ||
14 | }).addCallback(observableResult => { | ||
15 | for (const viewerScope of [ 'local', 'remote' ] as ViewerScope[]) { | ||
16 | for (const videoScope of [ 'local', 'remote' ] as VideoScope[]) { | ||
17 | const result = VideoViewsManager.Instance.getTotalViewers({ viewerScope, videoScope }) | ||
18 | |||
19 | observableResult.observe(result, { viewerOrigin: viewerScope, videoOrigin: videoScope }) | ||
20 | } | ||
21 | } | ||
22 | }) | ||
23 | } | ||
24 | } | ||
diff --git a/server/lib/opentelemetry/metrics.ts b/server/lib/opentelemetry/metrics.ts index 149f421be..ffe493670 100644 --- a/server/lib/opentelemetry/metrics.ts +++ b/server/lib/opentelemetry/metrics.ts | |||
@@ -4,7 +4,13 @@ import { PrometheusExporter } from '@opentelemetry/exporter-prometheus' | |||
4 | import { MeterProvider } from '@opentelemetry/sdk-metrics-base' | 4 | import { MeterProvider } from '@opentelemetry/sdk-metrics-base' |
5 | import { logger } from '@server/helpers/logger' | 5 | import { logger } from '@server/helpers/logger' |
6 | import { CONFIG } from '@server/initializers/config' | 6 | import { CONFIG } from '@server/initializers/config' |
7 | import { JobQueueObserversBuilder, NodeJSObserversBuilder, StatsObserversBuilder } from './metric-helpers' | 7 | import { |
8 | JobQueueObserversBuilder, | ||
9 | LivesObserversBuilder, | ||
10 | NodeJSObserversBuilder, | ||
11 | StatsObserversBuilder, | ||
12 | ViewersObserversBuilder | ||
13 | } from './metric-helpers' | ||
8 | 14 | ||
9 | class OpenTelemetryMetrics { | 15 | class OpenTelemetryMetrics { |
10 | 16 | ||
@@ -53,6 +59,12 @@ class OpenTelemetryMetrics { | |||
53 | 59 | ||
54 | const statsObserversBuilder = new StatsObserversBuilder(this.meter) | 60 | const statsObserversBuilder = new StatsObserversBuilder(this.meter) |
55 | statsObserversBuilder.buildObservers() | 61 | statsObserversBuilder.buildObservers() |
62 | |||
63 | const livesObserversBuilder = new LivesObserversBuilder(this.meter) | ||
64 | livesObserversBuilder.buildObservers() | ||
65 | |||
66 | const viewersObserversBuilder = new ViewersObserversBuilder(this.meter) | ||
67 | viewersObserversBuilder.buildObservers() | ||
56 | } | 68 | } |
57 | 69 | ||
58 | private buildRequestObserver () { | 70 | private buildRequestObserver () { |