From c6867725fb8e3dfbc2018a37ed5a963103587cb6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 21 Jul 2023 11:42:52 +0200 Subject: Add p2p info to metrics --- .../metric-helpers/playback-metrics.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'server/lib') 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 @@ -import { Counter, Histogram, Meter } from '@opentelemetry/api' +import { Counter, Meter } from '@opentelemetry/api' import { MVideoImmutable } from '@server/types/models' import { PlaybackMetricCreate } from '@shared/models' @@ -11,7 +11,10 @@ export class PlaybackMetrics { private downloadedBytesHTTPCounter: Counter - private peersP2PPeers: Histogram + private peersP2PPeersGaugeBuffer: { + value: number + attributes: any + }[] = [] constructor (private readonly meter: Meter) { @@ -37,8 +40,14 @@ export class PlaybackMetrics { description: 'Uploaded bytes with P2P by PeerTube player.' }) - this.peersP2PPeers = this.meter.createHistogram('peertube_playback_p2p_peers', { + this.meter.createObservableGauge('peertube_playback_p2p_peers', { description: 'Total P2P peers connected to the PeerTube player.' + }).addCallback(observableResult => { + for (const gauge of this.peersP2PPeersGaugeBuffer) { + observableResult.observe(gauge.value, gauge.attributes) + } + + this.peersP2PPeersGaugeBuffer = [] }) } @@ -66,6 +75,11 @@ export class PlaybackMetrics { this.uploadedBytesP2PCounter.add(metrics.uploadedBytesP2P, attributes) - if (metrics.totalPeers) this.peersP2PPeers.record(metrics.totalPeers, attributes) + if (metrics.p2pPeers) { + this.peersP2PPeersGaugeBuffer.push({ + value: metrics.p2pPeers, + attributes + }) + } } } -- cgit v1.2.3