Skip to content

Commit 3ad9f24

Browse files
xu1009litexuwu-sheng
authored
support jetty server work thread pool metric monitor (#517)
* support jetty server work thread pool metric monitor Co-authored-by: litexu <litexu@tencent.com> Co-authored-by: 吴晟 Wu Sheng <wu.sheng@foxmail.com>
1 parent 9144a06 commit 3ad9f24

27 files changed

Lines changed: 967 additions & 0 deletions

File tree

.github/workflows/plugins-jdk17-test.0.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ jobs:
5757
case:
5858
- jdk17-with-gson-scenario
5959
- resttemplate-6.x-scenario
60+
- jetty-thread-pool-scenario
61+
- jetty-11.x-thread-pool-scenario
6062
steps:
6163
- uses: actions/checkout@v2
6264
with:

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Release Notes.
88
* Exclude `synthetic` methods for the WitnessMethod mechanism
99
* Support ForkJoinPool trace
1010
* Support clickhouse-jdbc-plugin trace sql parameters
11+
* Support monitor jetty server work thread pool metric
1112

1213
#### Documentation
1314

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to You under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
~
18+
-->
19+
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<parent>
22+
<artifactId>apm-sdk-plugin</artifactId>
23+
<groupId>org.apache.skywalking</groupId>
24+
<version>8.16.0-SNAPSHOT</version>
25+
</parent>
26+
<modelVersion>4.0.0</modelVersion>
27+
28+
<artifactId>apm-jetty-thread-pool-plugin</artifactId>
29+
<name>jetty-thread-pool-plugin</name>
30+
<url>http://maven.apache.org</url>
31+
32+
<properties>
33+
<jetty-server.version>9.1.0.v20131115</jetty-server.version>
34+
</properties>
35+
36+
37+
<dependencies>
38+
<dependency>
39+
<groupId>org.eclipse.jetty</groupId>
40+
<artifactId>jetty-server</artifactId>
41+
<version>${jetty-server.version}</version>
42+
<scope>provided</scope>
43+
</dependency>
44+
</dependencies>
45+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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.define;
20+
21+
import static net.bytebuddy.matcher.ElementMatchers.any;
22+
import static net.bytebuddy.matcher.ElementMatchers.named;
23+
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
24+
25+
import java.util.Collections;
26+
import java.util.List;
27+
import net.bytebuddy.description.method.MethodDescription;
28+
import net.bytebuddy.matcher.ElementMatcher;
29+
import org.apache.skywalking.apm.agent.core.plugin.WitnessMethod;
30+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
31+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
32+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
33+
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
34+
35+
public class JettyServerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
36+
37+
private static final String JETTY_SERVER_CLASS = "org.eclipse.jetty.server.Server";
38+
39+
private static final String JETTY_SERVER_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jetty.thread.pool.JettyServerInterceptor";
40+
41+
private static final String QUEUED_THREAD_POOL_CLASS_NAME = "org.eclipse.jetty.util.thread.QueuedThreadPool";
42+
43+
private static final String QUEUED_THREAD_POOL_GET_QUEUE_SIZE = "getQueueSize";
44+
45+
@Override
46+
protected ClassMatch enhanceClass() {
47+
return byName(JETTY_SERVER_CLASS);
48+
}
49+
50+
@Override
51+
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
52+
return new ConstructorInterceptPoint[]{new ConstructorInterceptPoint() {
53+
@Override
54+
public ElementMatcher<MethodDescription> getConstructorMatcher() {
55+
return any();
56+
}
57+
58+
@Override
59+
public String getConstructorInterceptor() {
60+
return JETTY_SERVER_INTERCEPTOR;
61+
}
62+
}
63+
};
64+
}
65+
66+
@Override
67+
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
68+
return new InstanceMethodsInterceptPoint[0];
69+
}
70+
71+
@Override
72+
protected List<WitnessMethod> witnessMethods() {
73+
return Collections.singletonList(new WitnessMethod(
74+
QUEUED_THREAD_POOL_CLASS_NAME,
75+
named(QUEUED_THREAD_POOL_GET_QUEUE_SIZE)
76+
));
77+
}
78+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with 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+
jetty-thread-pool=org.apache.skywalking.apm.plugin.jetty.thread.pool.define.JettyServerInstrumentation

apm-sniffer/apm-sdk-plugin/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
<module>jedis-plugins</module>
127127
<module>impala-jdbc-2.6.x-plugin</module>
128128
<module>apm-armeria-plugins</module>
129+
<module>jetty-thread-pool-plugin</module>
129130
</modules>
130131
<packaging>pom</packaging>
131132

docs/en/setup/service-agent/java-agent/Plugin-list.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,4 @@
158158
- nats-client-2.14.x-2.15.x
159159
- impala-jdbc-2.6.x
160160
- jdk-forkjoinpool-plugin
161+
- jetty-thread-pool

docs/en/setup/service-agent/java-agent/Supported-list.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ The meter plugin provides the advanced metrics collections, which are not a part
155155
* [Undertow](https://github.com/undertow-io/undertow) 2.1.x -> 2.6.x
156156
* [Tomcat](https://github.com/apache/tomcat) 7.0.x -> 10.0.x
157157
* [Dubbo](https://github.com/apache/dubbo) 2.5.x -> 2.7.x
158+
* [Jetty](https://github.com/eclipse/jetty.project) 9.1.x -> 11.x
158159
___
159160
¹Due to license incompatibilities/restrictions these plugins are hosted and released in 3rd part repository,
160161
go to [SkyAPM java plugin extension repository](https://github.com/SkyAPM/java-plugin-extensions) to get these.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
home="$(cd "$(dirname $0)"; pwd)"
20+
21+
java -jar ${agent_opts} ${home}/../libs/jetty-11.x-thread-pool-scenario.jar &

0 commit comments

Comments
 (0)