提交 7047c97e 编写于 作者: L Lemon 提交者: 彭勇升 pengys

Add CLR_Receiver plugin (#2385)

上级 6aefdc42
......@@ -40,8 +40,8 @@ public class ServiceInstanceCLRGC extends Source {
@Getter @Setter private String name;
@Getter @Setter private String serviceName;
@Getter @Setter private int serviceId;
@Getter @Setter private int gen0CollectCount;
@Getter @Setter private int gen1CollectCount;
@Getter @Setter private int gen2CollectCount;
@Getter @Setter private long gen0CollectCount;
@Getter @Setter private long gen1CollectCount;
@Getter @Setter private long gen2CollectCount;
@Getter @Setter private long heapMemory;
}
\ No newline at end of file
......@@ -36,6 +36,7 @@
<module>skywalking-jvm-receiver-plugin</module>
<module>envoy-metrics-receiver-plugin</module>
<module>skywalking-sharing-server-plugin</module>
<module>skywalking-clr-receiver-plugin</module>
</modules>
<dependencies>
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<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">
<parent>
<artifactId>server-receiver-plugin</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>6.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>skywalking-clr-receiver-plugin</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>skywalking-sharing-server-plugin</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
/*
* 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.oap.server.receiver.clr.module;
import org.apache.skywalking.oap.server.library.module.ModuleDefine;
/**
* @author liuhaoyang
**/
public class CLRModule extends ModuleDefine {
public CLRModule() {
super("receiver-clr");
}
@Override public Class[] services() {
return new Class[0];
}
}
/*
* 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.oap.server.receiver.clr.provider;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.server.GRPCHandlerRegister;
import org.apache.skywalking.oap.server.library.module.ModuleConfig;
import org.apache.skywalking.oap.server.library.module.ModuleDefine;
import org.apache.skywalking.oap.server.library.module.ModuleProvider;
import org.apache.skywalking.oap.server.library.module.ModuleStartException;
import org.apache.skywalking.oap.server.library.module.ServiceNotProvidedException;
import org.apache.skywalking.oap.server.receiver.clr.module.CLRModule;
import org.apache.skywalking.oap.server.receiver.clr.provider.handler.CLRMetricReportServiceHandler;
import org.apache.skywalking.oap.server.receiver.sharing.server.SharingServerModule;
/**
* @author liuhaoyang
**/
public class CLRModuleProvider extends ModuleProvider {
@Override public String name() {
return "default";
}
@Override public Class<? extends ModuleDefine> module() {
return CLRModule.class;
}
@Override public ModuleConfig createConfigBeanIfAbsent() {
return null;
}
@Override public void prepare() throws ServiceNotProvidedException, ModuleStartException {
}
@Override public void start() throws ServiceNotProvidedException, ModuleStartException {
GRPCHandlerRegister grpcHandlerRegister = getManager().find(SharingServerModule.NAME).provider().getService(GRPCHandlerRegister.class);
grpcHandlerRegister.addHandler(new CLRMetricReportServiceHandler(getManager()));
}
@Override public void notifyAfterCompleted() throws ServiceNotProvidedException, ModuleStartException {
}
@Override public String[] requiredModules() {
return new String[] {CoreModule.NAME, SharingServerModule.NAME};
}
}
/*
* 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.oap.server.receiver.clr.provider.handler;
import io.grpc.stub.StreamObserver;
import org.apache.skywalking.apm.network.common.Commands;
import org.apache.skywalking.apm.network.language.agent.v2.CLRMetricCollection;
import org.apache.skywalking.apm.network.language.agent.v2.CLRMetricReportServiceGrpc;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.server.grpc.GRPCHandler;
import org.apache.skywalking.oap.server.library.util.TimeBucketUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author liuhaoyang
**/
public class CLRMetricReportServiceHandler extends CLRMetricReportServiceGrpc.CLRMetricReportServiceImplBase implements GRPCHandler {
private static final Logger logger = LoggerFactory.getLogger(CLRMetricReportServiceHandler.class);
private final CLRSourceDispatcher clrSourceDispatcher;
public CLRMetricReportServiceHandler(ModuleManager moduleManager) {
clrSourceDispatcher = new CLRSourceDispatcher(moduleManager);
}
@Override public void collect(CLRMetricCollection request, StreamObserver<Commands> responseObserver) {
int serviceInstanceId = request.getServiceInstanceId();
if (logger.isDebugEnabled()) {
logger.debug("receive the clr metric from service instance, id: {}", serviceInstanceId);
}
request.getMetricsList().forEach(metric -> {
long minuteTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(metric.getTime());
clrSourceDispatcher.sendMetric(serviceInstanceId, minuteTimeBucket, metric);
});
responseObserver.onNext(Commands.newBuilder().build());
responseObserver.onCompleted();
}
}
/*
* 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.oap.server.receiver.clr.provider.handler;
import org.apache.skywalking.apm.network.common.CPU;
import org.apache.skywalking.apm.network.language.agent.CLRMetric;
import org.apache.skywalking.apm.network.language.agent.ClrGC;
import org.apache.skywalking.apm.network.language.agent.ClrThread;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
import org.apache.skywalking.oap.server.core.source.ServiceInstanceCLRCPU;
import org.apache.skywalking.oap.server.core.source.ServiceInstanceCLRGC;
import org.apache.skywalking.oap.server.core.source.ServiceInstanceCLRThread;
import org.apache.skywalking.oap.server.core.source.SourceReceiver;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author liuhaoyang
**/
public class CLRSourceDispatcher {
private static final Logger logger = LoggerFactory.getLogger(CLRSourceDispatcher.class);
private final SourceReceiver sourceReceiver;
private final ServiceInstanceInventoryCache instanceInventoryCache;
public CLRSourceDispatcher(ModuleManager moduleManager) {
sourceReceiver = moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
instanceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInstanceInventoryCache.class);
}
void sendMetric(int serviceInstanceId, long minuteTimeBucket, CLRMetric metric) {
ServiceInstanceInventory serviceInstanceInventory = instanceInventoryCache.get(serviceInstanceId);
int serviceId;
if (serviceInstanceInventory == null) {
serviceId = serviceInstanceInventory.getServiceId();
} else {
logger.warn("Can't found service by service instance id from cache, service instance id is: {}", serviceInstanceId);
return;
}
CPU cpu = metric.getCpu();
ServiceInstanceCLRCPU serviceInstanceCLRCPU = new ServiceInstanceCLRCPU();
serviceInstanceCLRCPU.setUsePercent(cpu.getUsagePercent());
serviceInstanceCLRCPU.setTimeBucket(minuteTimeBucket);
serviceInstanceCLRCPU.setId(serviceInstanceId);
serviceInstanceCLRCPU.setName(Const.EMPTY_STRING);
serviceInstanceCLRCPU.setServiceId(serviceId);
serviceInstanceCLRCPU.setServiceName(Const.EMPTY_STRING);
sourceReceiver.receive(serviceInstanceCLRCPU);
ClrGC gc = metric.getGc();
ServiceInstanceCLRGC serviceInstanceCLRGC = new ServiceInstanceCLRGC();
serviceInstanceCLRGC.setGen0CollectCount(gc.getGen0CollectCount());
serviceInstanceCLRGC.setGen1CollectCount(gc.getGen1CollectCount());
serviceInstanceCLRGC.setGen2CollectCount(gc.getGen2CollectCount());
serviceInstanceCLRGC.setHeapMemory(gc.getHeapMemory());
serviceInstanceCLRGC.setTimeBucket(minuteTimeBucket);
serviceInstanceCLRGC.setId(serviceInstanceId);
serviceInstanceCLRGC.setName(Const.EMPTY_STRING);
serviceInstanceCLRGC.setServiceId(serviceId);
serviceInstanceCLRGC.setServiceName(Const.EMPTY_STRING);
sourceReceiver.receive(serviceInstanceCLRGC);
ClrThread thread = metric.getThread();
ServiceInstanceCLRThread serviceInstanceCLRThread = new ServiceInstanceCLRThread();
serviceInstanceCLRThread.setAvailableCompletionPortThreads(thread.getAvailableCompletionPortThreads());
serviceInstanceCLRThread.setAvailableWorkerThreads(thread.getAvailableWorkerThreads());
serviceInstanceCLRThread.setMaxCompletionPortThreads(thread.getMaxCompletionPortThreads());
serviceInstanceCLRThread.setMaxWorkerThreads(thread.getMaxWorkerThreads());
serviceInstanceCLRThread.setTimeBucket(minuteTimeBucket);
serviceInstanceCLRThread.setId(serviceInstanceId);
serviceInstanceCLRThread.setName(Const.EMPTY_STRING);
serviceInstanceCLRThread.setServiceId(serviceId);
serviceInstanceCLRThread.setServiceName(Const.EMPTY_STRING);
sourceReceiver.receive(serviceInstanceCLRThread);
}
}
#
# 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.
#
#
org.apache.skywalking.oap.server.receiver.clr.module.CLRModule
\ No newline at end of file
#
# 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.
#
#
org.apache.skywalking.oap.server.receiver.clr.provider.CLRModuleProvider
\ No newline at end of file
......@@ -84,6 +84,8 @@ receiver-trace:
slowDBAccessThreshold: ${SW_SLOW_DB_THRESHOLD:default:200,mongodb:100} # The slow database access thresholds. Unit ms.
receiver-jvm:
default:
receiver-clr:
default:
service-mesh:
default:
bufferPath: ${SW_SERVICE_MESH_BUFFER_PATH:../mesh-buffer/} # Path to trace buffer files, suggest to use absolute path
......
......@@ -84,6 +84,8 @@ receiver-trace:
slowDBAccessThreshold: ${SW_SLOW_DB_THRESHOLD:default:200,mongodb:100} # The slow database access thresholds. Unit ms.
receiver-jvm:
default:
receiver-clr:
default:
service-mesh:
default:
bufferPath: ${SW_SERVICE_MESH_BUFFER_PATH:../mesh-buffer/} # Path to trace buffer files, suggest to use absolute path
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册