From cd1b8e9a40ad24a57bc6da589b51aa96fe850449 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 19 Jul 2022 11:58:19 +0200 Subject: Add node process metrics --- .../metric-helpers/job-queue-observers-builder.ts | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 server/lib/opentelemetry/metric-helpers/job-queue-observers-builder.ts (limited to 'server/lib/opentelemetry/metric-helpers/job-queue-observers-builder.ts') 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 @@ +import { Meter } from '@opentelemetry/api-metrics' +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 }) + } + } + }) + } + +} -- cgit v1.2.3