aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/opentelemetry/metric-helpers/viewers-observers-builder.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-07-27 16:19:25 +0200
committerChocobozzz <me@florianbigard.com>2022-07-27 16:19:25 +0200
commitadc94cf09c86112051f72055852efcc977e4a04a (patch)
treeae6f25824c1e66004fa69aa9f685642d8d7ad8b4 /server/lib/opentelemetry/metric-helpers/viewers-observers-builder.ts
parent50cc1ee48aacb6e7d6513c0f108492a589b515ea (diff)
downloadPeerTube-adc94cf09c86112051f72055852efcc977e4a04a.tar.gz
PeerTube-adc94cf09c86112051f72055852efcc977e4a04a.tar.zst
PeerTube-adc94cf09c86112051f72055852efcc977e4a04a.zip
Add live and viewers otel metrics
Diffstat (limited to 'server/lib/opentelemetry/metric-helpers/viewers-observers-builder.ts')
-rw-r--r--server/lib/opentelemetry/metric-helpers/viewers-observers-builder.ts24
1 files changed, 24 insertions, 0 deletions
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 @@
1import { Meter } from '@opentelemetry/api-metrics'
2import { VideoScope, ViewerScope } from '@server/lib/views/shared'
3import { VideoViewsManager } from '@server/lib/views/video-views-manager'
4
5export 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}