PeerTube/server/core/lib/opentelemetry/metric-helpers/job-queue-observers-builder.ts

25 lines
649 B
TypeScript
Raw Normal View History

2022-11-15 06:27:46 -06:00
import { Meter } from '@opentelemetry/api'
import { JobQueue } from '@server/lib/job-queue/index.js'
2022-07-19 04:58:19 -05:00
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 })
}
}
})
}
}