From 9e0bedbb5f520d51759d50aa08d8afa8a4a3a89a Mon Sep 17 00:00:00 2001 From: Dmitry Kaukov Date: Mon, 10 Jun 2024 07:51:35 +1000 Subject: [PATCH] Fix Jetty 12.x QueuedThreadPool metrics (#4181) --- .../metrics/jetty12/InstrumentedQueuedThreadPool.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/metrics-jetty12/src/main/java/io/dropwizard/metrics/jetty12/InstrumentedQueuedThreadPool.java b/metrics-jetty12/src/main/java/io/dropwizard/metrics/jetty12/InstrumentedQueuedThreadPool.java index 99117378fa..31cdbf6884 100644 --- a/metrics-jetty12/src/main/java/io/dropwizard/metrics/jetty12/InstrumentedQueuedThreadPool.java +++ b/metrics-jetty12/src/main/java/io/dropwizard/metrics/jetty12/InstrumentedQueuedThreadPool.java @@ -127,15 +127,10 @@ protected void doStart() throws Exception { metricRegistry.register(name(prefix, NAME_UTILIZATION), new RatioGauge() { @Override protected Ratio getRatio() { - return Ratio.of(getThreads() - getIdleThreads(), getThreads()); - } - }); - metricRegistry.register(name(prefix, NAME_UTILIZATION_MAX), new RatioGauge() { - @Override - protected Ratio getRatio() { - return Ratio.of(getThreads() - getIdleThreads(), getMaxThreads()); + return Ratio.of(getUtilizedThreads(), getThreads() - getLeasedThreads()); } }); + metricRegistry.registerGauge(name(prefix, NAME_UTILIZATION_MAX), this::getUtilizationRate); metricRegistry.registerGauge(name(prefix, NAME_SIZE), this::getThreads); // This assumes the QueuedThreadPool is using a BlockingArrayQueue or // ArrayBlockingQueue for its queue, and is therefore a constant-time operation.