aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/opentelemetry/metric-helpers/lives-observers-builder.ts
blob: 5effc18e165a9b12ea2451fce63e9065b426ee84 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { Meter } from '@opentelemetry/api'
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' })
    })
  }
}