PeerTube/server/lib/opentelemetry/metric-helpers/lives-observers-builder.ts

22 lines
703 B
TypeScript
Raw Normal View History

2022-11-15 13:27:46 +01:00
import { Meter } from '@opentelemetry/api'
2022-07-27 16:19:25 +02:00
import { VideoModel } from '@server/models/video/video'
export class LivesObserversBuilder {
constructor (private readonly meter: Meter) {
}
buildObservers () {
this.meter.createObservableGauge('peertube_running_lives_total', {
description: 'Total running lives on the instance'
}).addCallback(async observableResult => {
const local = await VideoModel.countLives({ remote: false, mode: 'published' })
const remote = await VideoModel.countLives({ remote: true, mode: 'published' })
observableResult.observe(local, { liveOrigin: 'local' })
observableResult.observe(remote, { liveOrigin: 'remote' })
})
}
}