Skip to content

Commit

Permalink
[To dev/1.3] Fix ThreadPool Metric NPE #14460
Browse files Browse the repository at this point in the history
Signed-off-by: OneSizeFitQuorum <[email protected]>
  • Loading branch information
OneSizeFitsQuorum authored Dec 17, 2024
1 parent f78bbdb commit c01baa0
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@SuppressWarnings("java:S6548")
public class ThreadPoolMetrics implements IMetricSet {
Expand Down Expand Up @@ -57,35 +58,50 @@ private void registerThreadPoolMetrics(String name) {
SystemMetric.THREAD_POOL_ACTIVE_THREAD_COUNT.toString(),
MetricLevel.IMPORTANT,
registeredPoolMap,
map -> registeredPoolMap.get(name).getActiveCount(),
map ->
Optional.ofNullable(registeredPoolMap.get(name))
.map(IThreadPoolMBean::getActiveCount)
.orElse(0),
SystemTag.POOL_NAME.toString(),
name);
metricService.createAutoGauge(
SystemMetric.THREAD_POOL_CORE_SIZE.toString(),
MetricLevel.IMPORTANT,
registeredPoolMap,
map -> registeredPoolMap.get(name).getCorePoolSize(),
map ->
Optional.ofNullable(registeredPoolMap.get(name))
.map(IThreadPoolMBean::getCorePoolSize)
.orElse(0),
SystemTag.POOL_NAME.toString(),
name);
metricService.createAutoGauge(
SystemMetric.THREAD_POOL_WAITING_TASK_COUNT.toString(),
MetricLevel.IMPORTANT,
registeredPoolMap,
map -> registeredPoolMap.get(name).getQueueLength(),
map ->
Optional.ofNullable(registeredPoolMap.get(name))
.map(IThreadPoolMBean::getQueueLength)
.orElse(0),
SystemTag.POOL_NAME.toString(),
name);
metricService.createAutoGauge(
SystemMetric.THREAD_POOL_DONE_TASK_COUNT.toString(),
MetricLevel.IMPORTANT,
registeredPoolMap,
map -> registeredPoolMap.get(name).getCompletedTaskCount(),
map ->
Optional.ofNullable(registeredPoolMap.get(name))
.map(IThreadPoolMBean::getCompletedTaskCount)
.orElse(0L),
SystemTag.POOL_NAME.toString(),
name);
metricService.createAutoGauge(
SystemMetric.THREAD_POOL_LARGEST_POOL_SIZE.toString(),
MetricLevel.IMPORTANT,
registeredPoolMap,
map -> registeredPoolMap.get(name).getLargestPoolSize(),
map ->
Optional.ofNullable(registeredPoolMap.get(name))
.map(IThreadPoolMBean::getLargestPoolSize)
.orElse(0),
SystemTag.POOL_NAME.toString(),
name);
}
Expand Down

0 comments on commit c01baa0

Please sign in to comment.