Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class ExecutorServiceMetrics implements MeterBinder {

private static final String DEFAULT_EXECUTOR_METRIC_PREFIX = "";

private static final String DESCRIPTION_POOL_SIZE = "The current number of threads in the pool";

@Nullable
private final ExecutorService executorService;

Expand Down Expand Up @@ -362,7 +364,7 @@ private void monitor(MeterRegistry registry, @Nullable ThreadPoolExecutor tp) {

Gauge.builder(metricPrefix + "executor.pool.size", tp, ThreadPoolExecutor::getPoolSize)
.tags(tags)
.description("The current number of threads in the pool")
.description(DESCRIPTION_POOL_SIZE)
.baseUnit(BaseUnits.THREADS)
.register(registry);

Expand Down Expand Up @@ -402,6 +404,18 @@ private void monitor(MeterRegistry registry, ForkJoinPool fj) {
.description(
"An estimate of the number of worker threads that are not blocked waiting to join tasks or for other managed synchronization threads")
.register(registry);

Gauge.builder(metricPrefix + "executor.parallelism", fj, ForkJoinPool::getParallelism)
.tags(tags)
.description("The targeted parallelism level of this pool")
.baseUnit(BaseUnits.THREADS)
.register(registry);

Gauge.builder(metricPrefix + "executor.pool.size", fj, ForkJoinPool::getPoolSize)
.tags(tags)
.description(DESCRIPTION_POOL_SIZE)
.baseUnit(BaseUnits.THREADS)
.register(registry);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ void monitorExecutorsExecutorServicePrivateClass() {
.doesNotThrowAnyException();
}

@DisplayName("ForkJoinPool is assigned with its own set of metrics")
@ParameterizedTest
@CsvSource({ "custom,custom.", "custom.,custom.", ",''", "' ',''" })
void forkJoinPool(String metricPrefix, String expectedMetricPrefix) {
var fjp = new ForkJoinPool(1);
monitorExecutorService("fjp", metricPrefix, fjp);
registry.get(expectedMetricPrefix + "executor.steals").tags(userTags).tag("name", "fjp").functionCounter();
registry.get(expectedMetricPrefix + "executor.queued").tags(userTags).tag("name", "fjp").gauge();
registry.get(expectedMetricPrefix + "executor.running").tags(userTags).tag("name", "fjp").gauge();
registry.get(expectedMetricPrefix + "executor.parallelism").tags(userTags).tag("name", "fjp").gauge();
registry.get(expectedMetricPrefix + "executor.pool.size").tags(userTags).tag("name", "fjp").gauge();
}

@DisplayName("ScheduledExecutorService can be monitored with a default set of metrics")
@ParameterizedTest
@CsvSource({ "custom,custom.", "custom.,custom.", ",''", "' ',''" })
Expand Down