Skip to content

Commit

Permalink
Add worker count metric
Browse files Browse the repository at this point in the history
  • Loading branch information
darunrs committed Dec 2, 2023
1 parent 98022a1 commit d7f1775
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion runner/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { startServer as startMetricsServer } from './metrics';
import { METRICS, registerWorkerMetrics, startServer as startMetricsServer } from './metrics';
import RedisClient from './redis-client';
import StreamHandler from './stream-handler';
import promClient from 'prom-client';

const redisClient = new RedisClient();

Expand All @@ -18,6 +19,9 @@ void (async function main () {

while (true) {
const streamKeys = await redisClient.getStreams();
METRICS.WORKER_THREAD_COUNT.set(streamKeys.length);
const metrics = await promClient.register.getMetricsAsJSON();
registerWorkerMetrics(0, metrics as any);

streamKeys.forEach((streamKey) => {
if (streamHandlers[streamKey] !== undefined) {
Expand Down
6 changes: 6 additions & 0 deletions runner/src/metrics.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import express from 'express';
import { Gauge, Histogram, Counter, AggregatorRegistry } from 'prom-client';

const WORKER_THREAD_COUNT = new Gauge({
name: 'queryapi_runner_worker_thread_count',
help: 'Number of worker threads',
});

const BLOCK_WAIT_DURATION = new Histogram({
name: 'queryapi_runner_block_wait_duration_milliseconds',
help: 'Time an indexer function waited for a block before processing',
Expand Down Expand Up @@ -37,6 +42,7 @@ const EXECUTION_DURATION = new Histogram({
});

export const METRICS = {
WORKER_THREAD_COUNT,
BLOCK_WAIT_DURATION,
CACHE_HIT,
CACHE_MISS,
Expand Down

0 comments on commit d7f1775

Please sign in to comment.