diff --git a/servers/cu/src/domain/api/perf.js b/servers/cu/src/domain/api/perf.js index 3f3aa8058..8631aff5b 100644 --- a/servers/cu/src/domain/api/perf.js +++ b/servers/cu/src/domain/api/perf.js @@ -1,41 +1,37 @@ -import { path, zipObj } from 'ramda' +import { zipObj } from 'ramda' export function statsWith ({ loadWorkerStats, loadMemoryUsage, loadProcessCacheUsage, gauge }) { - const workerStatGaugesWith = ({ type }) => { - const totalWorkers = path([type, 'totalWorkers']) - const pendingTasks = path([type, 'pendingTasks']) - const activeTasks = path([type, 'activeTasks']) + gauge({ + name: 'worker_total', + description: 'The total amount of workers currently spun-up on the Compute Unit', + labelNames: ['worker_type'], + collect: (set) => Promise.resolve() + .then(loadWorkerStats) + .then(({ primary, dryRun }) => { + set(primary.totalWorkers + dryRun.totalWorkers) + set(primary.totalWorkers, { worker_type: 'primary' }) + set(dryRun.totalWorkers, { worker_type: 'dry-run' }) + }) + }) - // total workers - gauge({ - name: `${type.toLowerCase()}_worker_total`, - description: `The total amount of ${type} workers currently spun-up on the Compute Unit`, - collect: () => Promise.resolve() - .then(loadWorkerStats) - .then(totalWorkers) - }) + gauge({ + name: 'worker_tasks_total', + description: 'The total amount of worker tasks on the Compute Unit', + labelNames: ['worker_type', 'task_type'], + collect: (set) => Promise.resolve() + .then(loadWorkerStats) + .then(({ primary, dryRun }) => { + // pending + set(primary.pendingTasks + dryRun.pendingTasks) + set(primary.pendingTasks, { worker_type: 'primary', task_type: 'pending' }) + set(dryRun.pendingTasks, { worker_type: 'dry-run', task_type: 'pending' }) - // pending tasks - gauge({ - name: `${type.toLowerCase()}_worker_pending_tasks_total`, - description: `The total amount of ${type} pending tasks on the Compute Unit`, - collect: () => Promise.resolve() - .then(loadWorkerStats) - .then(pendingTasks) - }) - - // active tasks - gauge({ - name: `${type.toLowerCase()}_worker_active_tasks_total`, - description: `The total amount of ${type} active tasks on the Compute Unit`, - collect: () => Promise.resolve() - .then(loadWorkerStats) - .then(activeTasks) - }) - } - - workerStatGaugesWith({ type: 'dryRun' }) - workerStatGaugesWith({ type: 'primary' }) + // active + set(primary.activeTasks + dryRun.activeTasks) + set(primary.activeTasks, { worker_type: 'primary', task_type: 'active' }) + set(dryRun.activeTasks, { worker_type: 'dry-run', task_type: 'active' }) + }) + }) return async () => Promise.all([ loadWorkerStats(), diff --git a/servers/cu/src/domain/client/ao-process.js b/servers/cu/src/domain/client/ao-process.js index 51f4077b3..3bfbc655e 100644 --- a/servers/cu/src/domain/client/ao-process.js +++ b/servers/cu/src/domain/client/ao-process.js @@ -113,7 +113,12 @@ export async function createProcessMemoryCache ({ MAX_SIZE, TTL, logger, gauge, gauge({ name: 'ao_process_total', description: 'The total amount of ao Processes cached on the Compute Unit', - collect: () => lru.size + drainedToFile.size + labelNames: ['cache_type'], + collect: (set) => { + set(lru.size + drainedToFile.size) + set(lru.size, { cache_type: 'memory' }) + set(drainedToFile.size, { cache_type: 'file' }) + } }) /** diff --git a/servers/cu/src/domain/client/metrics.js b/servers/cu/src/domain/client/metrics.js index d501d9fd3..6f627882b 100644 --- a/servers/cu/src/domain/client/metrics.js +++ b/servers/cu/src/domain/client/metrics.js @@ -54,12 +54,19 @@ export const gaugeWith = ({ prefix = 'ao_cu' } = {}) => { * We abstract the use of 'this' * to the collect function here. * - * This way, the client may provide a function - * that simply returns the collected value to set, - * which will this call set here + * This way, the client may invoke set without + * the common "gotchas" w.r.t 'this'. + * + * Also makes the set api match the inc/dec/set api + * below, where value _then_ labels are passed */ ...(collect - ? { collect: async function () { this.set(await collect()) } } + ? { + collect: async function () { + const set = this.set.bind(this) + await collect((value, labels) => set(labels || {}, value)) + } + } : {} ), labelNames,