aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/opentelemetry/metric-helpers/job-queue-observers-builder.ts
blob: 56713ede8170431a9c9e102682cdf2d5e1825681 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { Meter } from '@opentelemetry/api'
import { JobQueue } from '@server/lib/job-queue'

export class JobQueueObserversBuilder {

  constructor (private readonly meter: Meter) {

  }

  buildObservers () {
    this.meter.createObservableGauge('peertube_job_queue_total', {
      description: 'Total jobs in the PeerTube job queue'
    }).addCallback(async observableResult => {
      const stats = await JobQueue.Instance.getStats()

      for (const { jobType, counts } of stats) {
        for (const state of Object.keys(counts)) {
          observableResult.observe(counts[state], { jobType, state })
        }
      }
    })
  }

}