diff options
Diffstat (limited to 'server/lib/opentelemetry/metric-helpers/lives-observers-builder.ts')
-rw-r--r-- | server/lib/opentelemetry/metric-helpers/lives-observers-builder.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/server/lib/opentelemetry/metric-helpers/lives-observers-builder.ts b/server/lib/opentelemetry/metric-helpers/lives-observers-builder.ts new file mode 100644 index 000000000..e27bd8548 --- /dev/null +++ b/server/lib/opentelemetry/metric-helpers/lives-observers-builder.ts | |||
@@ -0,0 +1,21 @@ | |||
1 | import { Meter } from '@opentelemetry/api-metrics' | ||
2 | import { VideoModel } from '@server/models/video/video' | ||
3 | |||
4 | export class LivesObserversBuilder { | ||
5 | |||
6 | constructor (private readonly meter: Meter) { | ||
7 | |||
8 | } | ||
9 | |||
10 | buildObservers () { | ||
11 | this.meter.createObservableGauge('peertube_running_lives_total', { | ||
12 | description: 'Total running lives on the instance' | ||
13 | }).addCallback(async observableResult => { | ||
14 | const local = await VideoModel.countLives({ remote: false, mode: 'published' }) | ||
15 | const remote = await VideoModel.countLives({ remote: true, mode: 'published' }) | ||
16 | |||
17 | observableResult.observe(local, { liveOrigin: 'local' }) | ||
18 | observableResult.observe(remote, { liveOrigin: 'remote' }) | ||
19 | }) | ||
20 | } | ||
21 | } | ||