Add peers number and p2p enabled label to metrics
This commit is contained in:
parent
4e5da193d0
commit
305facdfab
|
@ -18,6 +18,9 @@ class MetricsPlugin extends Plugin {
|
||||||
private resolutionChanges = 0
|
private resolutionChanges = 0
|
||||||
private errors = 0
|
private errors = 0
|
||||||
|
|
||||||
|
private p2pEnabled: boolean
|
||||||
|
private totalPeers = 0
|
||||||
|
|
||||||
private lastPlayerNetworkInfo: PlayerNetworkInfo
|
private lastPlayerNetworkInfo: PlayerNetworkInfo
|
||||||
|
|
||||||
private metricsInterval: any
|
private metricsInterval: any
|
||||||
|
@ -113,6 +116,9 @@ class MetricsPlugin extends Plugin {
|
||||||
|
|
||||||
uploadedBytesP2P: this.uploadedBytesP2P,
|
uploadedBytesP2P: this.uploadedBytesP2P,
|
||||||
|
|
||||||
|
totalPeers: this.totalPeers,
|
||||||
|
p2pEnabled: this.p2pEnabled,
|
||||||
|
|
||||||
videoId: this.options_.videoUUID()
|
videoId: this.options_.videoUUID()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,12 +145,18 @@ class MetricsPlugin extends Plugin {
|
||||||
|
|
||||||
this.uploadedBytesP2P += Math.round(data.p2p.uploaded - (this.lastPlayerNetworkInfo?.p2p.uploaded || 0))
|
this.uploadedBytesP2P += Math.round(data.p2p.uploaded - (this.lastPlayerNetworkInfo?.p2p.uploaded || 0))
|
||||||
|
|
||||||
|
this.totalPeers = data.p2p.numPeers
|
||||||
|
this.p2pEnabled = true
|
||||||
|
|
||||||
this.lastPlayerNetworkInfo = data
|
this.lastPlayerNetworkInfo = data
|
||||||
})
|
})
|
||||||
|
|
||||||
this.player.on('http-info', (_event, data: PlayerNetworkInfo) => {
|
this.player.on('http-info', (_event, data: PlayerNetworkInfo) => {
|
||||||
this.downloadedBytesHTTP += Math.round(data.http.downloaded - (this.lastPlayerNetworkInfo?.http.downloaded || 0))
|
this.downloadedBytesHTTP += Math.round(data.http.downloaded - (this.lastPlayerNetworkInfo?.http.downloaded || 0))
|
||||||
|
|
||||||
|
this.totalPeers = 0
|
||||||
|
this.p2pEnabled = false
|
||||||
|
|
||||||
this.lastPlayerNetworkInfo = data
|
this.lastPlayerNetworkInfo = data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Counter, Meter } from '@opentelemetry/api'
|
import { Counter, Histogram, Meter } from '@opentelemetry/api'
|
||||||
import { MVideoImmutable } from '@server/types/models'
|
import { MVideoImmutable } from '@server/types/models'
|
||||||
import { PlaybackMetricCreate } from '@shared/models'
|
import { PlaybackMetricCreate } from '@shared/models'
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ export class PlaybackMetrics {
|
||||||
|
|
||||||
private downloadedBytesHTTPCounter: Counter
|
private downloadedBytesHTTPCounter: Counter
|
||||||
|
|
||||||
|
private peersP2PPeers: Histogram
|
||||||
|
|
||||||
constructor (private readonly meter: Meter) {
|
constructor (private readonly meter: Meter) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,6 +36,10 @@ export class PlaybackMetrics {
|
||||||
this.uploadedBytesP2PCounter = this.meter.createCounter('peertube_playback_p2p_uploaded_bytes', {
|
this.uploadedBytesP2PCounter = this.meter.createCounter('peertube_playback_p2p_uploaded_bytes', {
|
||||||
description: 'Uploaded bytes with P2P by PeerTube player.'
|
description: 'Uploaded bytes with P2P by PeerTube player.'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.peersP2PPeers = this.meter.createHistogram('peertube_playback_p2p_peers', {
|
||||||
|
description: 'Total P2P peers connected to the PeerTube player.'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
observe (video: MVideoImmutable, metrics: PlaybackMetricCreate) {
|
observe (video: MVideoImmutable, metrics: PlaybackMetricCreate) {
|
||||||
|
@ -47,6 +53,8 @@ export class PlaybackMetrics {
|
||||||
resolution: metrics.resolution + '',
|
resolution: metrics.resolution + '',
|
||||||
fps: metrics.fps + '',
|
fps: metrics.fps + '',
|
||||||
|
|
||||||
|
p2pEnabled: metrics.p2pEnabled,
|
||||||
|
|
||||||
videoUUID: video.uuid
|
videoUUID: video.uuid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,5 +65,7 @@ export class PlaybackMetrics {
|
||||||
this.downloadedBytesP2PCounter.add(metrics.downloadedBytesP2P, attributes)
|
this.downloadedBytesP2PCounter.add(metrics.downloadedBytesP2P, attributes)
|
||||||
|
|
||||||
this.uploadedBytesP2PCounter.add(metrics.uploadedBytesP2P, attributes)
|
this.uploadedBytesP2PCounter.add(metrics.uploadedBytesP2P, attributes)
|
||||||
|
|
||||||
|
if (metrics.totalPeers) this.peersP2PPeers.record(metrics.totalPeers, attributes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,15 @@ const addPlaybackMetricValidator = [
|
||||||
body('fps')
|
body('fps')
|
||||||
.optional()
|
.optional()
|
||||||
.isInt({ min: 0 }),
|
.isInt({ min: 0 }),
|
||||||
|
|
||||||
|
body('totalPeers')
|
||||||
|
.optional()
|
||||||
|
.isInt({ min: 0 }),
|
||||||
|
|
||||||
|
body('p2pEnabled')
|
||||||
|
.optional()
|
||||||
|
.isBoolean(),
|
||||||
|
|
||||||
body('playerMode')
|
body('playerMode')
|
||||||
.custom(isValidPlayerMode),
|
.custom(isValidPlayerMode),
|
||||||
|
|
||||||
|
|
|
@ -89,10 +89,6 @@ describe('Test metrics API validators', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with a missing errors', async function () {
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Should fail with an missing/invalid errors', async function () {
|
it('Should fail with an missing/invalid errors', async function () {
|
||||||
await makePostBodyRequest({
|
await makePostBodyRequest({
|
||||||
url: server.url,
|
url: server.url,
|
||||||
|
@ -149,6 +145,22 @@ describe('Test metrics API validators', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should fail with an invalid p2pEnabled', async function () {
|
||||||
|
await makePostBodyRequest({
|
||||||
|
url: server.url,
|
||||||
|
path,
|
||||||
|
fields: { ...baseParams, p2pEnabled: 'toto' }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should fail with an invalid totalPeers', async function () {
|
||||||
|
await makePostBodyRequest({
|
||||||
|
url: server.url,
|
||||||
|
path,
|
||||||
|
fields: { ...baseParams, totalPeers: 'toto' }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it('Should fail with a bad video id', async function () {
|
it('Should fail with a bad video id', async function () {
|
||||||
await makePostBodyRequest({
|
await makePostBodyRequest({
|
||||||
url: server.url,
|
url: server.url,
|
||||||
|
@ -173,6 +185,13 @@ describe('Test metrics API validators', function () {
|
||||||
fields: baseParams,
|
fields: baseParams,
|
||||||
expectedStatus: HttpStatusCode.NO_CONTENT_204
|
expectedStatus: HttpStatusCode.NO_CONTENT_204
|
||||||
})
|
})
|
||||||
|
|
||||||
|
await makePostBodyRequest({
|
||||||
|
url: server.url,
|
||||||
|
path,
|
||||||
|
fields: { ...baseParams, p2pEnabled: false, totalPeers: 32 },
|
||||||
|
expectedStatus: HttpStatusCode.NO_CONTENT_204
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,8 @@ describe('Open Telemetry', function () {
|
||||||
downloadedBytesP2P: 0,
|
downloadedBytesP2P: 0,
|
||||||
downloadedBytesHTTP: 0,
|
downloadedBytesHTTP: 0,
|
||||||
uploadedBytesP2P: 5,
|
uploadedBytesP2P: 5,
|
||||||
|
totalPeers: 1,
|
||||||
|
p2pEnabled: false,
|
||||||
videoId: video.uuid
|
videoId: video.uuid
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,6 +6,9 @@ export interface PlaybackMetricCreate {
|
||||||
resolution?: VideoResolution
|
resolution?: VideoResolution
|
||||||
fps?: number
|
fps?: number
|
||||||
|
|
||||||
|
p2pEnabled?: boolean
|
||||||
|
totalPeers?: number
|
||||||
|
|
||||||
resolutionChanges: number
|
resolutionChanges: number
|
||||||
|
|
||||||
errors: number
|
errors: number
|
||||||
|
|
Loading…
Reference in New Issue