})
})
-const server = createWebsocketTrackerServer(app)
+const { server, trackerServer } = createWebsocketTrackerServer(app)
// ----------- Run -----------
VideoChannelSyncLatestScheduler.Instance.enable()
VideoViewsBufferScheduler.Instance.enable()
GeoIPUpdateScheduler.Instance.enable()
- OpenTelemetryMetrics.Instance.registerMetrics()
+
+ OpenTelemetryMetrics.Instance.registerMetrics({ trackerServer })
PluginManager.Instance.init(server)
// Before PeerTubeSocket init
// Don't destroy socket, we have Socket.IO too
})
- return server
+ return { server, trackerServer }
}
// ---------------------------------------------------------------------------
--- /dev/null
+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 ])
+ }
+
+}
+export * from './bittorrent-tracker-observers-builder'
export * from './lives-observers-builder'
export * from './job-queue-observers-builder'
export * from './nodejs-observers-builder'
import { MVideoImmutable } from '@server/types/models'
import { PlaybackMetricCreate } from '@shared/models'
import {
+ BittorrentTrackerObserversBuilder,
JobQueueObserversBuilder,
LivesObserversBuilder,
NodeJSObserversBuilder,
})
}
- registerMetrics () {
+ registerMetrics (options: { trackerServer: any }) {
if (CONFIG.OPEN_TELEMETRY.METRICS.ENABLED !== true) return
logger.info('Registering Open Telemetry metrics')
const viewersObserversBuilder = new ViewersObserversBuilder(this.meter)
viewersObserversBuilder.buildObservers()
+
+ const bittorrentTrackerObserversBuilder = new BittorrentTrackerObserversBuilder(this.meter, options.trackerServer)
+ bittorrentTrackerObserversBuilder.buildObservers()
}
observePlaybackMetric (video: MVideoImmutable, metrics: PlaybackMetricCreate) {