aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/opentelemetry/metric-helpers/playback-metrics.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-12 16:41:29 +0200
committerChocobozzz <me@florianbigard.com>2022-08-16 10:33:27 +0200
commitfd3c2e87051f5029cdec39d877b576a62f48e219 (patch)
treea3c657f178702a3363af680ed8ffb7cd038243b8 /server/lib/opentelemetry/metric-helpers/playback-metrics.ts
parent0e6cd1c00f71554fe7375a96db693a6983951ba6 (diff)
downloadPeerTube-fd3c2e87051f5029cdec39d877b576a62f48e219.tar.gz
PeerTube-fd3c2e87051f5029cdec39d877b576a62f48e219.tar.zst
PeerTube-fd3c2e87051f5029cdec39d877b576a62f48e219.zip
Add playback metric endpoint sent to OTEL
Diffstat (limited to 'server/lib/opentelemetry/metric-helpers/playback-metrics.ts')
-rw-r--r--server/lib/opentelemetry/metric-helpers/playback-metrics.ts59
1 files changed, 59 insertions, 0 deletions
diff --git a/server/lib/opentelemetry/metric-helpers/playback-metrics.ts b/server/lib/opentelemetry/metric-helpers/playback-metrics.ts
new file mode 100644
index 000000000..d2abdee62
--- /dev/null
+++ b/server/lib/opentelemetry/metric-helpers/playback-metrics.ts
@@ -0,0 +1,59 @@
1import { Counter, Meter } from '@opentelemetry/api-metrics'
2import { MVideoImmutable } from '@server/types/models'
3import { PlaybackMetricCreate } from '@shared/models'
4
5export class PlaybackMetrics {
6 private errorsCounter: Counter
7 private resolutionChangesCounter: Counter
8
9 private downloadedBytesP2PCounter: Counter
10 private uploadedBytesP2PCounter: Counter
11
12 private downloadedBytesHTTPCounter: Counter
13
14 constructor (private readonly meter: Meter) {
15
16 }
17
18 buildCounters () {
19 this.errorsCounter = this.meter.createCounter('peertube_playback_errors_count', {
20 description: 'Errors collected from PeerTube player.'
21 })
22
23 this.resolutionChangesCounter = this.meter.createCounter('peertube_playback_resolution_changes_count', {
24 description: 'Resolution changes collected from PeerTube player.'
25 })
26
27 this.downloadedBytesHTTPCounter = this.meter.createCounter('peertube_playback_http_downloaded_bytes', {
28 description: 'Downloaded bytes with HTTP by PeerTube player.'
29 })
30 this.downloadedBytesP2PCounter = this.meter.createCounter('peertube_playback_p2p_downloaded_bytes', {
31 description: 'Downloaded bytes with P2P by PeerTube player.'
32 })
33
34 this.uploadedBytesP2PCounter = this.meter.createCounter('peertube_playback_p2p_uploaded_bytes', {
35 description: 'Uploaded bytes with P2P by PeerTube player.'
36 })
37 }
38
39 observe (video: MVideoImmutable, metrics: PlaybackMetricCreate) {
40 const attributes = {
41 videoOrigin: video.remote
42 ? 'remote'
43 : 'local',
44
45 playerMode: metrics.playerMode,
46
47 resolution: metrics.resolution + '',
48 fps: metrics.fps + ''
49 }
50
51 this.errorsCounter.add(metrics.errors, attributes)
52 this.resolutionChangesCounter.add(metrics.resolutionChanges, attributes)
53
54 this.downloadedBytesHTTPCounter.add(metrics.downloadedBytesHTTP, attributes)
55 this.downloadedBytesP2PCounter.add(metrics.downloadedBytesP2P, attributes)
56
57 this.uploadedBytesP2PCounter.add(metrics.uploadedBytesP2P, attributes)
58 }
59}