1+ /*
2+ * Licensed to the Apache Software Foundation (ASF) under one or more
3+ * contributor license agreements. See the NOTICE file distributed with
4+ * this work for additional information regarding copyright ownership.
5+ * The ASF licenses this file to You under the Apache License, Version 2.0
6+ * (the "License"); you may not use this file except in compliance with
7+ * the License. You may obtain a copy of the License at
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ *
17+ */
18+
19+ package org .apache .skywalking .apm .plugin .jetty .thread .pool ;
20+
21+ import org .apache .skywalking .apm .agent .core .meter .MeterFactory ;
22+ import org .apache .skywalking .apm .agent .core .plugin .interceptor .enhance .EnhancedInstance ;
23+ import org .apache .skywalking .apm .agent .core .plugin .interceptor .enhance .InstanceConstructorInterceptor ;
24+ import org .eclipse .jetty .server .Server ;
25+ import org .eclipse .jetty .util .thread .QueuedThreadPool ;
26+
27+ public class JettyServerInterceptor implements InstanceConstructorInterceptor {
28+
29+ private static final String METER_NAME = "thread_pool" ;
30+ private static final String METRIC_POOL_NAME_TAG_NAME = "pool_name" ;
31+ private static final String THREAD_POOL_NAME = "jetty_execute_pool" ;
32+ private static final String METRIC_TYPE_TAG_NAME = "metric_type" ;
33+
34+ @ Override
35+ public void onConstruct (EnhancedInstance objInst , Object [] allArguments ) throws Throwable {
36+ Server server = (Server ) objInst ;
37+ QueuedThreadPool queuedThreadPool = (QueuedThreadPool ) server .getThreadPool ();
38+ MeterFactory .gauge (METER_NAME , () -> (double ) queuedThreadPool .getMinThreads ())
39+ .tag (METRIC_POOL_NAME_TAG_NAME , THREAD_POOL_NAME )
40+ .tag (METRIC_TYPE_TAG_NAME , "core_pool_size" )
41+ .build ();
42+ MeterFactory .gauge (METER_NAME , () -> (double ) queuedThreadPool .getMaxThreads ())
43+ .tag (METRIC_POOL_NAME_TAG_NAME , THREAD_POOL_NAME )
44+ .tag (METRIC_TYPE_TAG_NAME , "max_pool_size" )
45+ .build ();
46+ MeterFactory .gauge (METER_NAME , () -> (double ) queuedThreadPool .getThreads ())
47+ .tag (METRIC_POOL_NAME_TAG_NAME , THREAD_POOL_NAME )
48+ .tag (METRIC_TYPE_TAG_NAME , "pool_size" )
49+ .build ();
50+ MeterFactory .gauge (METER_NAME , () -> (double ) queuedThreadPool .getQueueSize ())
51+ .tag (METRIC_POOL_NAME_TAG_NAME , THREAD_POOL_NAME )
52+ .tag (METRIC_TYPE_TAG_NAME , "queue_size" )
53+ .build ();
54+ MeterFactory .gauge (METER_NAME , () -> (double ) queuedThreadPool .getThreads () - queuedThreadPool .getIdleThreads ())
55+ .tag (METRIC_POOL_NAME_TAG_NAME , THREAD_POOL_NAME )
56+ .tag (METRIC_TYPE_TAG_NAME , "active_size" )
57+ .build ();
58+
59+ }
60+ }
0 commit comments