Skip to content

Commit

Permalink
Add worker thread completed OTEL metric
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed Oct 27, 2023
1 parent 049f50b commit 880f8b9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meter } from '@opentelemetry/api'
import { getWorkersQueueSize } from '@server/lib/worker/parent-process.js'
import { getWorkersStats } from '@server/lib/worker/parent-process.js'

export class WorkerThreadsObserversBuilder {

Expand All @@ -11,12 +11,22 @@ export class WorkerThreadsObserversBuilder {
this.meter.createObservableGauge('peertube_worker_thread_queue_total', {
description: 'Total tasks waiting for a PeerTube worker thread'
}).addCallback(observableResult => {
const stats = getWorkersQueueSize()
const stats = getWorkersStats()

for (const stat of stats) {
observableResult.observe(stat.queueSize, { state: 'waiting', workerThread: stat.label })
}
})

this.meter.createObservableGauge('peertube_worker_thread_completed_total', {
description: 'Total tasks completed in PeerTube worker threads'
}).addCallback(observableResult => {
const stats = getWorkersStats()

for (const stat of stats) {
observableResult.observe(stat.completed, { workerThread: stat.label })
}
})
}

}
26 changes: 17 additions & 9 deletions server/core/lib/worker/parent-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,39 +149,47 @@ export function buildDigestFromWorker (

// ---------------------------------------------------------------------------

export function getWorkersQueueSize () {
export function getWorkersStats () {
return [
{
label: 'downloadImage',
queueSize: downloadImageWorker?.queueSize || 0
queueSize: downloadImageWorker?.queueSize || 0,
completed: downloadImageWorker?.completed || 0
},
{
label: 'processImageWorker',
queueSize: processImageWorker?.queueSize || 0
queueSize: processImageWorker?.queueSize || 0,
completed: processImageWorker?.completed || 0
},
{
label: 'getImageSizeWorker',
queueSize: getImageSizeWorker?.queueSize || 0
queueSize: getImageSizeWorker?.queueSize || 0,
completed: getImageSizeWorker?.completed || 0
},
{
label: 'parallelHTTPBroadcastWorker',
queueSize: parallelHTTPBroadcastWorker?.queueSize || 0
queueSize: parallelHTTPBroadcastWorker?.queueSize || 0,
completed: parallelHTTPBroadcastWorker?.completed || 0
},
{
label: 'sequentialHTTPBroadcastWorker',
queueSize: sequentialHTTPBroadcastWorker?.queueSize || 0
queueSize: sequentialHTTPBroadcastWorker?.queueSize || 0,
completed: sequentialHTTPBroadcastWorker?.completed || 0
},
{
label: 'httpUnicastWorker',
queueSize: httpUnicastWorker?.queueSize || 0
queueSize: httpUnicastWorker?.queueSize || 0,
completed: httpUnicastWorker?.completed || 0
},
{
label: 'signJsonLDObjectWorker',
queueSize: signJsonLDObjectWorker?.queueSize || 0
queueSize: signJsonLDObjectWorker?.queueSize || 0,
completed: signJsonLDObjectWorker?.completed || 0
},
{
label: 'buildDigestWorker',
queueSize: buildDigestWorker?.queueSize || 0
queueSize: buildDigestWorker?.queueSize || 0,
completed: buildDigestWorker?.completed || 0
}
]
}

0 comments on commit 880f8b9

Please sign in to comment.