InstrumentedQueuedThreadPool extends QueuedThreadPool { @Override protected void doStart() throws Exception { super.doStart(); final String prefix = this.prefix == null ? name(QueuedThreadPool.class, getName()) : name(this.prefix, getName()); metricRegistry.register(name(prefix, "utilization"), new RatioGauge() { @Override protected Ratio getRatio() { return Ratio.of(getThreads() - getIdleThreads(), getThreads()); } }); metricRegistry.register(name(prefix, "utilization-max"), new RatioGauge() { @Override protected Ratio getRatio() { return Ratio.of(getThreads() - getIdleThreads(), getMaxThreads()); } }); metricRegistry.register(name(prefix, "size"), (Gauge<Integer>) this::getThreads); metricRegistry.register(name(prefix, "jobs"), (Gauge<Integer>) () -> { return getQueue().size(); }); metricRegistry.register(name(prefix, "jobs-queue-utilization"), new RatioGauge() { @Override protected Ratio getRatio() { BlockingQueue<Runnable> queue = getQueue(); return Ratio.of(queue.size(), queue.size() + queue.remainingCapacity()); } }); } InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry);  InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
                                        @Name("maxThreads") int maxThreads);  InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
                                        @Name("maxThreads") int maxThreads,
                                        @Name("minThreads") int minThreads);  InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
                                        @Name("maxThreads") int maxThreads,
                                        @Name("minThreads") int minThreads,
                                        @Name("idleTimeout") int idleTimeout);  InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
                                        @Name("maxThreads") int maxThreads,
                                        @Name("minThreads") int minThreads,
                                        @Name("idleTimeout") int idleTimeout,
                                        @Name("queue") BlockingQueue<Runnable> queue);  InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
                                        @Name("maxThreads") int maxThreads,
                                        @Name("minThreads") int minThreads,
                                        @Name("idleTimeout") int idleTimeout,
                                        @Name("queue") BlockingQueue<Runnable> queue,
                                        @Name("prefix") String prefix); String getPrefix(); void setPrefix(String prefix);  }
@Test public void metricsPrefixBackwardCompatible() throws Exception { iqtp.doStart(); verify(metricRegistry, atLeastOnce()).register(metricNameCaptor.capture(), any(Metric.class)); String metricName = metricNameCaptor.getValue(); assertThat(metricName) .overridingErrorMessage("The default metrics prefix was changed") .startsWith(QueuedThreadPool.class.getName()); }