/**
 * Copyright 2017 Pivotal Software, Inc.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.micrometer.core.instrument.binder.jetty;

import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.binder.MeterBinder;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.ThreadPool;
import org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool;

/**
 * {@link MeterBinder} for Jetty {@link ThreadPool}.
 *
 * @author Manabu Matsuzaki
 * @author Andy Wilkinson
 */
public class JettyServerThreadPoolMetrics implements MeterBinder {

    private final ThreadPool threadPool;

    private final Iterable<Tag> tags;

    public JettyServerThreadPoolMetrics(ThreadPool threadPool, Iterable<Tag> tags) {
        this.threadPool = threadPool;
        this.tags = tags;
    }

    @Override
    public void bindTo(MeterRegistry registry) {
        if (this.threadPool instanceof SizedThreadPool) {
            SizedThreadPool sizedThreadPool = (SizedThreadPool) this.threadPool;
            Gauge.builder("jetty.threads.config.min", sizedThreadPool,
                SizedThreadPool::getMinThreads)
                .description("The minimum number of threads in the pool")
                .tags(this.tags).register(registry);
            Gauge.builder("jetty.threads.config.max", sizedThreadPool,
                SizedThreadPool::getMaxThreads)
                .description("The maximum number of threads in the pool")
                .tags(this.tags).register(registry);
            if (this.threadPool instanceof QueuedThreadPool) {
                QueuedThreadPool queuedThreadPool = (QueuedThreadPool) this.threadPool;
                Gauge.builder("jetty.threads.busy", queuedThreadPool,
                    QueuedThreadPool::getBusyThreads)
                    .description("The number of busy threads in the pool")
                    .tags(this.tags).register(registry);
            }
        }
        Gauge.builder("jetty.threads.current", this.threadPool,
            ThreadPool::getThreads)
            .description("The total number of threads in the pool")
            .tags(this.tags).register(registry);
        Gauge.builder("jetty.threads.idle", this.threadPool,
            ThreadPool::getIdleThreads)
            .description("The number of idle threads in the pool").tags(this.tags)
            .register(registry);
    }

}

@@ -1140,16 +1140,38 @@
 lkinson%0A
+ * @author Johnny Lim%0A
  */%0Apubl
@@ -1538,37 +1538,32 @@
 ) %7B%0A        if (
-this.
 threadPool insta
@@ -1643,37 +1643,32 @@
 izedThreadPool) 
-this.
 threadPool;%0A    
@@ -1733,32 +1733,16 @@
 eadPool,
-%0A               
  SizedTh
@@ -1774,32 +1774,36 @@
                 
+    
 .description(%22Th
@@ -1856,35 +1856,34 @@
             
+    
 .tags(
-this.
 tags).regist
@@ -1966,32 +1966,16 @@
 eadPool,
-%0A               
  SizedTh
@@ -1991,32 +1991,36 @@
 :getMaxThreads)%0A
+    
                 
@@ -2089,35 +2089,34 @@
             
+    
 .tags(
-this.
 tags).regist
@@ -2145,21 +2145,16 @@
     if (
-this.
 threadPo
@@ -2258,21 +2258,16 @@
 adPool) 
-this.
 threadPo
@@ -2339,36 +2339,16 @@
 eadPool,
-%0A                   
  QueuedT
@@ -2386,32 +2386,36 @@
                 
+   
+ 
 .description(%22Th
@@ -2469,35 +2469,275 @@
             
+    
 .tags(t
-his.
+ags).register(registry);%0A                Gauge.builder(%22jetty.threads.jobs%22, queuedThreadPool, QueuedThreadPool::getQueueSize)%0A                        .description(%22Number of jobs queued waiting for a thread%22)%0A                        .tags(
 tags).regist
@@ -2821,21 +2821,16 @@
 rrent%22, 
-this.
 threadPo
@@ -2828,36 +2828,24 @@
  threadPool,
-%0A           
  ThreadPool:
@@ -2849,32 +2849,36 @@
 ol::getThreads)%0A
+    
             .des
@@ -2941,27 +2941,26 @@
         
+  
+  
 .tags(
-this.
 tags).re
@@ -3021,21 +3021,16 @@
 .idle%22, 
-this.
 threadPo
@@ -3032,28 +3032,16 @@
 eadPool,
-%0A           
  ThreadP
@@ -3053,32 +3053,36 @@
 getIdleThreads)%0A
+    
             .des
@@ -3141,19 +3141,18 @@
 ags(
-this.
 tags)%0A
+    
     

Add queue size metric for QueuedThreadPool