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/metrics.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/metrics.ts')
-rw-r--r-- | server/lib/opentelemetry/metrics.ts | 39 |
1 files changed, 7 insertions, 32 deletions
diff --git a/server/lib/opentelemetry/metrics.ts b/server/lib/opentelemetry/metrics.ts index ca0aae8e7..149f421be 100644 --- a/server/lib/opentelemetry/metrics.ts +++ b/server/lib/opentelemetry/metrics.ts | |||
@@ -4,8 +4,7 @@ import { PrometheusExporter } from '@opentelemetry/exporter-prometheus' | |||
4 | import { MeterProvider } from '@opentelemetry/sdk-metrics-base' | 4 | import { MeterProvider } from '@opentelemetry/sdk-metrics-base' |
5 | import { logger } from '@server/helpers/logger' | 5 | import { logger } from '@server/helpers/logger' |
6 | import { CONFIG } from '@server/initializers/config' | 6 | import { CONFIG } from '@server/initializers/config' |
7 | import { JobQueue } from '../job-queue' | 7 | import { JobQueueObserversBuilder, NodeJSObserversBuilder, StatsObserversBuilder } from './metric-helpers' |
8 | import { StatsObserverBuilder } from './metric-helpers' | ||
9 | 8 | ||
10 | class OpenTelemetryMetrics { | 9 | class OpenTelemetryMetrics { |
11 | 10 | ||
@@ -44,40 +43,16 @@ class OpenTelemetryMetrics { | |||
44 | 43 | ||
45 | this.meter = metrics.getMeter('default') | 44 | this.meter = metrics.getMeter('default') |
46 | 45 | ||
47 | this.buildMemoryObserver() | ||
48 | this.buildRequestObserver() | 46 | this.buildRequestObserver() |
49 | this.buildJobQueueObserver() | ||
50 | 47 | ||
51 | const statsObserverBuilder = new StatsObserverBuilder(this.meter) | 48 | const nodeJSObserversBuilder = new NodeJSObserversBuilder(this.meter, provider) |
52 | statsObserverBuilder.buildObservers() | 49 | nodeJSObserversBuilder.buildObservers() |
53 | } | ||
54 | 50 | ||
55 | private buildMemoryObserver () { | 51 | const jobQueueObserversBuilder = new JobQueueObserversBuilder(this.meter) |
56 | this.meter.createObservableGauge('nodejs_memory_usage_bytes', { | 52 | jobQueueObserversBuilder.buildObservers() |
57 | description: 'Memory' | ||
58 | }).addCallback(observableResult => { | ||
59 | const current = process.memoryUsage() | ||
60 | |||
61 | observableResult.observe(current.heapTotal, { memoryType: 'heapTotal' }) | ||
62 | observableResult.observe(current.heapUsed, { memoryType: 'heapUsed' }) | ||
63 | observableResult.observe(current.arrayBuffers, { memoryType: 'arrayBuffers' }) | ||
64 | observableResult.observe(current.external, { memoryType: 'external' }) | ||
65 | observableResult.observe(current.rss, { memoryType: 'rss' }) | ||
66 | }) | ||
67 | } | ||
68 | 53 | ||
69 | private buildJobQueueObserver () { | 54 | const statsObserversBuilder = new StatsObserversBuilder(this.meter) |
70 | this.meter.createObservableGauge('peertube_job_queue_total', { | 55 | statsObserversBuilder.buildObservers() |
71 | description: 'Total jobs in the PeerTube job queue' | ||
72 | }).addCallback(async observableResult => { | ||
73 | const stats = await JobQueue.Instance.getStats() | ||
74 | |||
75 | for (const { jobType, counts } of stats) { | ||
76 | for (const state of Object.keys(counts)) { | ||
77 | observableResult.observe(counts[state], { jobType, state }) | ||
78 | } | ||
79 | } | ||
80 | }) | ||
81 | } | 56 | } |
82 | 57 | ||
83 | private buildRequestObserver () { | 58 | private buildRequestObserver () { |