diff options
author | Chocobozzz <me@florianbigard.com> | 2022-07-19 11:58:19 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-07-19 11:58:19 +0200 |
commit | cd1b8e9a40ad24a57bc6da589b51aa96fe850449 (patch) | |
tree | c60b134e1f17909f9c27b96270cd389edc5f27aa /server/lib/opentelemetry/metric-helpers/job-queue-observers-builder.ts | |
parent | 0755cb89e752edbfac10e72610f6b44ea93debf5 (diff) | |
download | PeerTube-cd1b8e9a40ad24a57bc6da589b51aa96fe850449.tar.gz PeerTube-cd1b8e9a40ad24a57bc6da589b51aa96fe850449.tar.zst PeerTube-cd1b8e9a40ad24a57bc6da589b51aa96fe850449.zip |
Add node process metrics
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.ts | 24 |
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 @@ | |||
1 | import { Meter } from '@opentelemetry/api-metrics' | ||
2 | import { JobQueue } from '@server/lib/job-queue' | ||
3 | |||
4 | export 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 | } | ||