aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-21 11:42:52 +0200
committerChocobozzz <me@florianbigard.com>2023-07-21 11:42:52 +0200
commitc6867725fb8e3dfbc2018a37ed5a963103587cb6 (patch)
tree92e00e551c95553c6090e26a7502593e72bdcfd7 /server/lib
parentb63c607b92fd3ec62e370b73e398062bcf317738 (diff)
downloadPeerTube-c6867725fb8e3dfbc2018a37ed5a963103587cb6.tar.gz
PeerTube-c6867725fb8e3dfbc2018a37ed5a963103587cb6.tar.zst
PeerTube-c6867725fb8e3dfbc2018a37ed5a963103587cb6.zip
Add p2p info to metrics
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/opentelemetry/metric-helpers/playback-metrics.ts22
1 files changed, 18 insertions, 4 deletions
diff --git a/server/lib/opentelemetry/metric-helpers/playback-metrics.ts b/server/lib/opentelemetry/metric-helpers/playback-metrics.ts
index 41a5dd640..1eb08b5a6 100644
--- a/server/lib/opentelemetry/metric-helpers/playback-metrics.ts
+++ b/server/lib/opentelemetry/metric-helpers/playback-metrics.ts
@@ -1,4 +1,4 @@
1import { Counter, Histogram, Meter } from '@opentelemetry/api' 1import { Counter, Meter } from '@opentelemetry/api'
2import { MVideoImmutable } from '@server/types/models' 2import { MVideoImmutable } from '@server/types/models'
3import { PlaybackMetricCreate } from '@shared/models' 3import { PlaybackMetricCreate } from '@shared/models'
4 4
@@ -11,7 +11,10 @@ export class PlaybackMetrics {
11 11
12 private downloadedBytesHTTPCounter: Counter 12 private downloadedBytesHTTPCounter: Counter
13 13
14 private peersP2PPeers: Histogram 14 private peersP2PPeersGaugeBuffer: {
15 value: number
16 attributes: any
17 }[] = []
15 18
16 constructor (private readonly meter: Meter) { 19 constructor (private readonly meter: Meter) {
17 20
@@ -37,8 +40,14 @@ export class PlaybackMetrics {
37 description: 'Uploaded bytes with P2P by PeerTube player.' 40 description: 'Uploaded bytes with P2P by PeerTube player.'
38 }) 41 })
39 42
40 this.peersP2PPeers = this.meter.createHistogram('peertube_playback_p2p_peers', { 43 this.meter.createObservableGauge('peertube_playback_p2p_peers', {
41 description: 'Total P2P peers connected to the PeerTube player.' 44 description: 'Total P2P peers connected to the PeerTube player.'
45 }).addCallback(observableResult => {
46 for (const gauge of this.peersP2PPeersGaugeBuffer) {
47 observableResult.observe(gauge.value, gauge.attributes)
48 }
49
50 this.peersP2PPeersGaugeBuffer = []
42 }) 51 })
43 } 52 }
44 53
@@ -66,6 +75,11 @@ export class PlaybackMetrics {
66 75
67 this.uploadedBytesP2PCounter.add(metrics.uploadedBytesP2P, attributes) 76 this.uploadedBytesP2PCounter.add(metrics.uploadedBytesP2P, attributes)
68 77
69 if (metrics.totalPeers) this.peersP2PPeers.record(metrics.totalPeers, attributes) 78 if (metrics.p2pPeers) {
79 this.peersP2PPeersGaugeBuffer.push({
80 value: metrics.p2pPeers,
81 attributes
82 })
83 }
70 } 84 }
71} 85}