aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/opentelemetry/metric-helpers/job-queue-observers-builder.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/opentelemetry/metric-helpers/job-queue-observers-builder.ts')
-rw-r--r--server/lib/opentelemetry/metric-helpers/job-queue-observers-builder.ts24
1 files changed, 24 insertions, 0 deletions
diff --git a/server/lib/opentelemetry/metric-helpers/job-queue-observers-builder.ts b/server/lib/opentelemetry/metric-helpers/job-queue-observers-builder.ts
new file mode 100644
index 000000000..c81959616
--- /dev/null
+++ b/server/lib/opentelemetry/metric-helpers/job-queue-observers-builder.ts
@@ -0,0 +1,24 @@
1import { Meter } from '@opentelemetry/api-metrics'
2import { JobQueue } from '@server/lib/job-queue'
3
4export class JobQueueObserversBuilder {
5
6 constructor (private readonly meter: Meter) {
7
8 }
9
10 buildObservers () {
11 this.meter.createObservableGauge('peertube_job_queue_total', {
12 description: 'Total jobs in the PeerTube job queue'
13 }).addCallback(async observableResult => {
14 const stats = await JobQueue.Instance.getStats()
15
16 for (const { jobType, counts } of stats) {
17 for (const state of Object.keys(counts)) {
18 observableResult.observe(counts[state], { jobType, state })
19 }
20 }
21 })
22 }
23
24}