mirror of https://github.com/Chocobozzz/PeerTube
Add tracker opentelemtry metrics
parent
60bab7b540
commit
5847724474
|
@ -279,7 +279,7 @@ app.use((err, _req, res: express.Response, _next) => {
|
|||
})
|
||||
})
|
||||
|
||||
const server = createWebsocketTrackerServer(app)
|
||||
const { server, trackerServer } = createWebsocketTrackerServer(app)
|
||||
|
||||
// ----------- Run -----------
|
||||
|
||||
|
@ -328,7 +328,8 @@ async function startApplication () {
|
|||
VideoChannelSyncLatestScheduler.Instance.enable()
|
||||
VideoViewsBufferScheduler.Instance.enable()
|
||||
GeoIPUpdateScheduler.Instance.enable()
|
||||
OpenTelemetryMetrics.Instance.registerMetrics()
|
||||
|
||||
OpenTelemetryMetrics.Instance.registerMetrics({ trackerServer })
|
||||
|
||||
PluginManager.Instance.init(server)
|
||||
// Before PeerTubeSocket init
|
||||
|
|
|
@ -121,7 +121,7 @@ function createWebsocketTrackerServer (app: express.Application) {
|
|||
// Don't destroy socket, we have Socket.IO too
|
||||
})
|
||||
|
||||
return server
|
||||
return { server, trackerServer }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
import { Meter } from '@opentelemetry/api'
|
||||
|
||||
export class BittorrentTrackerObserversBuilder {
|
||||
|
||||
constructor (private readonly meter: Meter, private readonly trackerServer: any) {
|
||||
|
||||
}
|
||||
|
||||
buildObservers () {
|
||||
const activeInfohashes = this.meter.createObservableGauge('peertube_bittorrent_tracker_active_infohashes_total', {
|
||||
description: 'Total active infohashes in the PeerTube BitTorrent Tracker'
|
||||
})
|
||||
const inactiveInfohashes = this.meter.createObservableGauge('peertube_bittorrent_tracker_inactive_infohashes_total', {
|
||||
description: 'Total inactive infohashes in the PeerTube BitTorrent Tracker'
|
||||
})
|
||||
const peers = this.meter.createObservableGauge('peertube_bittorrent_tracker_peers_total', {
|
||||
description: 'Total peers in the PeerTube BitTorrent Tracker'
|
||||
})
|
||||
|
||||
this.meter.addBatchObservableCallback(observableResult => {
|
||||
const infohashes = Object.keys(this.trackerServer.torrents)
|
||||
|
||||
const counters = {
|
||||
activeInfohashes: 0,
|
||||
inactiveInfohashes: 0,
|
||||
peers: 0,
|
||||
uncompletedPeers: 0
|
||||
}
|
||||
|
||||
for (const infohash of infohashes) {
|
||||
const content = this.trackerServer.torrents[infohash]
|
||||
|
||||
const peers = content.peers
|
||||
if (peers.keys.length !== 0) counters.activeInfohashes++
|
||||
else counters.inactiveInfohashes++
|
||||
|
||||
for (const peerId of peers.keys) {
|
||||
const peer = peers.peek(peerId)
|
||||
if (peer == null) return
|
||||
|
||||
counters.peers++
|
||||
}
|
||||
}
|
||||
|
||||
observableResult.observe(activeInfohashes, counters.activeInfohashes)
|
||||
observableResult.observe(inactiveInfohashes, counters.inactiveInfohashes)
|
||||
observableResult.observe(peers, counters.peers)
|
||||
}, [ activeInfohashes, inactiveInfohashes, peers ])
|
||||
}
|
||||
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
export * from './bittorrent-tracker-observers-builder'
|
||||
export * from './lives-observers-builder'
|
||||
export * from './job-queue-observers-builder'
|
||||
export * from './nodejs-observers-builder'
|
||||
|
|
|
@ -7,6 +7,7 @@ import { CONFIG } from '@server/initializers/config'
|
|||
import { MVideoImmutable } from '@server/types/models'
|
||||
import { PlaybackMetricCreate } from '@shared/models'
|
||||
import {
|
||||
BittorrentTrackerObserversBuilder,
|
||||
JobQueueObserversBuilder,
|
||||
LivesObserversBuilder,
|
||||
NodeJSObserversBuilder,
|
||||
|
@ -41,7 +42,7 @@ class OpenTelemetryMetrics {
|
|||
})
|
||||
}
|
||||
|
||||
registerMetrics () {
|
||||
registerMetrics (options: { trackerServer: any }) {
|
||||
if (CONFIG.OPEN_TELEMETRY.METRICS.ENABLED !== true) return
|
||||
|
||||
logger.info('Registering Open Telemetry metrics')
|
||||
|
@ -80,6 +81,9 @@ class OpenTelemetryMetrics {
|
|||
|
||||
const viewersObserversBuilder = new ViewersObserversBuilder(this.meter)
|
||||
viewersObserversBuilder.buildObservers()
|
||||
|
||||
const bittorrentTrackerObserversBuilder = new BittorrentTrackerObserversBuilder(this.meter, options.trackerServer)
|
||||
bittorrentTrackerObserversBuilder.buildObservers()
|
||||
}
|
||||
|
||||
observePlaybackMetric (video: MVideoImmutable, metrics: PlaybackMetricCreate) {
|
||||
|
|
Loading…
Reference in New Issue