job-queue-observers-builder.ts 649 B

123456789101112131415161718192021222324
  1. import { Meter } from '@opentelemetry/api'
  2. import { JobQueue } from '@server/lib/job-queue/index.js'
  3. export class JobQueueObserversBuilder {
  4. constructor (private readonly meter: Meter) {
  5. }
  6. buildObservers () {
  7. this.meter.createObservableGauge('peertube_job_queue_total', {
  8. description: 'Total jobs in the PeerTube job queue'
  9. }).addCallback(async observableResult => {
  10. const stats = await JobQueue.Instance.getStats()
  11. for (const { jobType, counts } of stats) {
  12. for (const state of Object.keys(counts)) {
  13. observableResult.observe(counts[state], { jobType, state })
  14. }
  15. }
  16. })
  17. }
  18. }