package com.codahale.metrics.jetty8;

import com.codahale.metrics.Gauge;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.RatioGauge;
import org.eclipse.jetty.util.thread.QueuedThreadPool;

import static com.codahale.metrics.MetricRegistry.name;

public class InstrumentedQueuedThreadPool extends QueuedThreadPool {
    public InstrumentedQueuedThreadPool(MetricRegistry registry) {
        super();
        registry.register(name(QueuedThreadPool.class, "percent-idle"), new RatioGauge() {
            @Override
            protected Ratio getRatio() {
                return Ratio.of(getIdleThreads(),
                                getThreads());
            }
        });
        registry.register(name(QueuedThreadPool.class, "active-threads"), new Gauge<Integer>() {
            @Override
            public Integer getValue() {
                return getThreads();
            }
        });
        registry.register(name(QueuedThreadPool.class, "idle-threads"), new Gauge<Integer>() {
            @Override
            public Integer getValue() {
                return getIdleThreads();
            }
        });
    }
}

@@ -1135,20 +1135,420 @@
         %7D);%0A
+        registry.register(name(QueuedThreadPool.class, %22jobs%22), new Gauge%3CInteger%3E() %7B%0A            @Override%0A            public Integer getValue() %7B%0A                // This assumes the QueuedThreadPool is using a BlockingArrayQueue or%0A                // ArrayBlockingQueue for its queue, and is therefore a constant-time operation.%0A                return getQueue().size();%0A            %7D%0A        %7D);%0A
     %7D%0A%7D%0A

Add gauge for pending jobs in InstrumentedQueuedThreadPool.