Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Release Notes.
* Polish test framework to support `arm64/v8` platforms
* Fix wrong config name `plugin.toolkit.use_qualified_name_as_operation_name`, and system variable name `SW_PLUGIN_TOOLKIT_USE_QUALIFIED_NAME_AS_OPERATION_NAME:false`. They were **toolit**.
* Rename `JDBI` to `JDBC`
* Support collecting dubbo thread pool metrics

#### Documentation

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 org.apache.skywalking.apm.plugin.asf.dubbo;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.remoting.transport.AbstractServer;
import org.apache.skywalking.apm.agent.core.meter.MeterFactory;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;

import java.lang.reflect.Field;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;

public class AbstractServerConstructorInterceptor implements InstanceConstructorInterceptor {
private static final String METER_NAME = "thread_pool";
private static final String METRIC_POOL_NAME_TAG_NAME = "pool_name";
private static final String METRIC_TYPE_TAG_NAME = "metric_type";

@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable {
Field executorField = AbstractServer.class.getDeclaredField("executor");
executorField.setAccessible(true);
ExecutorService executor = (ExecutorService) executorField.get(objInst);

URL url = (URL) allArguments[0];
int port = url.getPort();

if (!(executor instanceof ThreadPoolExecutor)) {
return;
}
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor;
// TODO String.format("DubboServerHandler-%s:%s", host, port) will be better
String threadPoolName = String.format("DubboServerHandler-%s", port);

MeterFactory.gauge(METER_NAME, () -> (double) (threadPoolExecutor.getCorePoolSize()))
.tag(METRIC_POOL_NAME_TAG_NAME, threadPoolName)
.tag(METRIC_TYPE_TAG_NAME, "core_pool_size")
.build();
MeterFactory.gauge(METER_NAME, () -> (double) (threadPoolExecutor.getMaximumPoolSize()))
.tag(METRIC_POOL_NAME_TAG_NAME, threadPoolName)
.tag(METRIC_TYPE_TAG_NAME, "max_pool_size")
.build();
MeterFactory.gauge(METER_NAME, () -> (double) (threadPoolExecutor.getLargestPoolSize()))
.tag(METRIC_POOL_NAME_TAG_NAME, threadPoolName)
.tag(METRIC_TYPE_TAG_NAME, "largest_pool_size")
.build();
MeterFactory.gauge(METER_NAME, () -> (double) (threadPoolExecutor.getPoolSize()))
.tag(METRIC_POOL_NAME_TAG_NAME, threadPoolName)
.tag(METRIC_TYPE_TAG_NAME, "pool_size")
.build();
MeterFactory.gauge(METER_NAME, () -> (double) (threadPoolExecutor.getQueue().size()))
.tag(METRIC_POOL_NAME_TAG_NAME, threadPoolName)
.tag(METRIC_TYPE_TAG_NAME, "queue_size")
.build();
MeterFactory.gauge(METER_NAME, () -> (double) (threadPoolExecutor.getActiveCount()))
.tag(METRIC_POOL_NAME_TAG_NAME, threadPoolName)
.tag(METRIC_TYPE_TAG_NAME, "active_size")
.build();
MeterFactory.gauge(METER_NAME, () -> (double) (threadPoolExecutor.getTaskCount()))
.tag(METRIC_POOL_NAME_TAG_NAME, threadPoolName)
.tag(METRIC_TYPE_TAG_NAME, "task_count")
.build();
MeterFactory.gauge(METER_NAME, () -> (double) (threadPoolExecutor.getCompletedTaskCount()))
.tag(METRIC_POOL_NAME_TAG_NAME, threadPoolName)
.tag(METRIC_TYPE_TAG_NAME, "completed_task_count")
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 org.apache.skywalking.apm.plugin.asf.dubbo;

import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;

import static net.bytebuddy.matcher.ElementMatchers.any;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;

public class AbstractServerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "org.apache.dubbo.remoting.transport.AbstractServer";
private static final String CONSTRUCTOR_INTERCEPTOR = "org.apache.skywalking.apm.plugin.asf.dubbo.AbstractServerConstructorInterceptor";

@Override
protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS);
}

@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[]{
new ConstructorInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getConstructorMatcher() {
return any();
}

@Override
public String getConstructorInterceptor() {
return CONSTRUCTOR_INTERCEPTOR;
}
}
};
}

@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
# limitations under the License.

dubbo-2.7.x=org.apache.skywalking.apm.plugin.asf.dubbo.DubboInstrumentation
dubbo-threadpool-2.7.x=org.apache.skywalking.apm.plugin.asf.dubbo.AbstractServerInstrumentation
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 org.apache.skywalking.apm.plugin.dubbo;

import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.remoting.transport.AbstractServer;
import org.apache.skywalking.apm.agent.core.meter.MeterFactory;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;

import java.lang.reflect.Field;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;

public class AbstractServerConstructorInterceptor implements InstanceConstructorInterceptor {
private static final String METER_NAME = "thread_pool";
private static final String METRIC_POOL_NAME_TAG_NAME = "pool_name";
private static final String METRIC_TYPE_TAG_NAME = "metric_type";

@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable {
Field executorField = AbstractServer.class.getDeclaredField("executor");
executorField.setAccessible(true);
ExecutorService executor = (ExecutorService) executorField.get(objInst);

URL url = (URL) allArguments[0];
int port = url.getPort();

if (!(executor instanceof ThreadPoolExecutor)) {
return;
}
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor;
// TODO String.format("DubboServerHandler-%s:%s", host, port) will be better
String threadPoolName = String.format("DubboServerHandler-%s", port);

MeterFactory.gauge(METER_NAME, () -> (double) (threadPoolExecutor.getCorePoolSize()))
.tag(METRIC_POOL_NAME_TAG_NAME, threadPoolName)
.tag(METRIC_TYPE_TAG_NAME, "core_pool_size")
.build();
MeterFactory.gauge(METER_NAME, () -> (double) (threadPoolExecutor.getMaximumPoolSize()))
.tag(METRIC_POOL_NAME_TAG_NAME, threadPoolName)
.tag(METRIC_TYPE_TAG_NAME, "max_pool_size")
.build();
MeterFactory.gauge(METER_NAME, () -> (double) (threadPoolExecutor.getLargestPoolSize()))
.tag(METRIC_POOL_NAME_TAG_NAME, threadPoolName)
.tag(METRIC_TYPE_TAG_NAME, "largest_pool_size")
.build();
MeterFactory.gauge(METER_NAME, () -> (double) (threadPoolExecutor.getPoolSize()))
.tag(METRIC_POOL_NAME_TAG_NAME, threadPoolName)
.tag(METRIC_TYPE_TAG_NAME, "pool_size")
.build();
MeterFactory.gauge(METER_NAME, () -> (double) (threadPoolExecutor.getQueue().size()))
.tag(METRIC_POOL_NAME_TAG_NAME, threadPoolName)
.tag(METRIC_TYPE_TAG_NAME, "queue_size")
.build();
MeterFactory.gauge(METER_NAME, () -> (double) (threadPoolExecutor.getActiveCount()))
.tag(METRIC_POOL_NAME_TAG_NAME, threadPoolName)
.tag(METRIC_TYPE_TAG_NAME, "active_size")
.build();
MeterFactory.gauge(METER_NAME, () -> (double) (threadPoolExecutor.getTaskCount()))
.tag(METRIC_POOL_NAME_TAG_NAME, threadPoolName)
.tag(METRIC_TYPE_TAG_NAME, "task_count")
.build();
MeterFactory.gauge(METER_NAME, () -> (double) (threadPoolExecutor.getCompletedTaskCount()))
.tag(METRIC_POOL_NAME_TAG_NAME, threadPoolName)
.tag(METRIC_TYPE_TAG_NAME, "completed_task_count")
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 org.apache.skywalking.apm.plugin.dubbo;

import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;

import static net.bytebuddy.matcher.ElementMatchers.any;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;

public class AbstractServerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "com.alibaba.dubbo.remoting.transport.AbstractServer";
private static final String CONSTRUCTOR_INTERCEPTOR = "org.apache.skywalking.apm.plugin.dubbo.AbstractServerConstructorInterceptor";

@Override
protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS);
}

@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[]{
new ConstructorInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getConstructorMatcher() {
return any();
}

@Override
public String getConstructorInterceptor() {
return CONSTRUCTOR_INTERCEPTOR;
}
}
};
}

@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
# limitations under the License.

dubbo=org.apache.skywalking.apm.plugin.dubbo.DubboInstrumentation
dubbo-threadpool=org.apache.skywalking.apm.plugin.dubbo.AbstractServerInstrumentation
2 changes: 2 additions & 0 deletions docs/en/setup/service-agent/java-agent/Plugin-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
- dubbo
- dubbo-2.7.x
- dubbo-3.x
- dubbo-threadpool
- dubbo-threadpool-2.7.x
Comment thread
nisiyong marked this conversation as resolved.
- ehcache-2.x
- elastic-job-2.x
- elasticjob-3.x
Expand Down
1 change: 1 addition & 0 deletions docs/en/setup/service-agent/java-agent/Supported-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ The meter plugin provides the advanced metrics collections, which are not a part
* Thread Pool
* [Undertow](https://github.com/undertow-io/undertow) 2.1.x -> 2.6.x
* [Tomcat](https://github.com/apache/tomcat) 7.0.x -> 10.0.x
* [Dubbo](https://github.com/apache/dubbo) 2.5.x -> 2.7.x
___
¹Due to license incompatibilities/restrictions these plugins are hosted and released in 3rd part repository,
go to [SkyAPM java plugin extension repository](https://github.com/SkyAPM/java-plugin-extensions) to get these.
Expand Down
Loading