提交 37a52873 编写于 作者: P peng-yongsheng

JVM metric aggregate tested.

上级 1435cbb1
/*
* 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.collector.agent.grpc.provider.handler;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.apache.skywalking.apm.network.proto.Application;
import org.apache.skywalking.apm.network.proto.ApplicationMapping;
import org.apache.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class ApplicationRegisterServiceHandlerTestCase {
private final Logger logger = LoggerFactory.getLogger(ApplicationRegisterServiceHandlerTestCase.class);
private ApplicationRegisterServiceGrpc.ApplicationRegisterServiceBlockingStub stub;
public void testRegister() {
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 11800).usePlaintext(true).build();
stub = ApplicationRegisterServiceGrpc.newBlockingStub(channel);
Application application = Application.newBuilder().setApplicationCode("test141").build();
ApplicationMapping mapping = stub.applicationCodeRegister(application);
logger.debug(mapping.getApplication().getKey() + ", " + mapping.getApplication().getValue());
}
}
......@@ -16,25 +16,35 @@
*
*/
package org.apache.skywalking.apm.collector.agent.grpc.provider.handler;
package org.apache.skywalking.apm.collector.agent.grpc.provider.handler.mock;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.apache.skywalking.apm.network.proto.ApplicationInstanceHeartbeat;
import org.apache.skywalking.apm.network.proto.InstanceDiscoveryServiceGrpc;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class InstHeartBeatServiceTestCase {
public class AgentDataMock {
public static void main(String[] args) {
private static final Logger logger = LoggerFactory.getLogger(TraceSegmentMock.class);
public static void main(String[] args) throws InterruptedException {
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 11800).usePlaintext(true).build();
InstanceDiscoveryServiceGrpc.InstanceDiscoveryServiceBlockingStub blockingStub = InstanceDiscoveryServiceGrpc.newBlockingStub(channel);
ApplicationInstanceHeartbeat.Builder builder = ApplicationInstanceHeartbeat.newBuilder();
builder.setApplicationInstanceId(2);
builder.setHeartbeatTime(System.currentTimeMillis());
blockingStub.heartbeat(builder.build());
RegisterMock registerMock = new RegisterMock();
registerMock.mock(channel);
Long[] times = TimeBuilder.INSTANCE.generateTimes();
logger.info("times size: {}", times.length);
TraceSegmentMock segmentMock = new TraceSegmentMock();
segmentMock.mock(channel, times);
JVMMetricMock jvmMetricMock = new JVMMetricMock();
jvmMetricMock.mock(channel, times);
Thread.sleep(60);
}
}
......@@ -16,10 +16,13 @@
*
*/
package org.apache.skywalking.apm.collector.agent.grpc.provider.handler;
package org.apache.skywalking.apm.collector.agent.grpc.provider.handler.mock;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.skywalking.apm.network.proto.CPU;
import org.apache.skywalking.apm.network.proto.GC;
import org.apache.skywalking.apm.network.proto.GCPhrase;
......@@ -29,66 +32,128 @@ import org.apache.skywalking.apm.network.proto.JVMMetricsServiceGrpc;
import org.apache.skywalking.apm.network.proto.Memory;
import org.apache.skywalking.apm.network.proto.MemoryPool;
import org.apache.skywalking.apm.network.proto.PoolType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class JVMMetricServiceHandlerTestCase {
class JVMMetricMock {
public static void main(String[] args) {
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 11800).usePlaintext(true).build();
JVMMetricsServiceGrpc.JVMMetricsServiceBlockingStub blockingStub = JVMMetricsServiceGrpc.newBlockingStub(channel);
private static final Logger logger = LoggerFactory.getLogger(JVMMetricMock.class);
JVMMetrics.Builder builder = JVMMetrics.newBuilder();
builder.setApplicationInstanceId(2);
void mock(ManagedChannel channel, Long[] times) {
JVMMetricsServiceGrpc.JVMMetricsServiceBlockingStub jvmMetricsServiceBlockingStub = JVMMetricsServiceGrpc.newBlockingStub(channel);
JVMMetric.Builder metricBuilder = JVMMetric.newBuilder();
metricBuilder.setTime(System.currentTimeMillis());
Set<Long> timeSet = new HashSet<>();
timeSet.addAll(Arrays.asList(times));
buildCPUMetric(metricBuilder);
buildGCMetric(metricBuilder);
buildMemoryMetric(metricBuilder);
buildMemoryPoolMetric(metricBuilder);
AtomicInteger increment = new AtomicInteger(0);
timeSet.forEach(timestamp -> {
JVMMetrics.Builder jvmMetrics = JVMMetrics.newBuilder();
jvmMetrics.setApplicationInstanceId(2);
builder.addMetrics(metricBuilder.build());
JVMMetric.Builder jvmMetricBuilder = JVMMetric.newBuilder();
jvmMetricBuilder.setTime(timestamp);
blockingStub.collect(builder.build());
buildCPUMetric(jvmMetricBuilder);
buildGCMetric(jvmMetricBuilder);
buildMemoryMetric(jvmMetricBuilder);
buildMemoryPoolMetric(jvmMetricBuilder);
jvmMetrics.addMetrics(jvmMetricBuilder.build());
jvmMetricsServiceBlockingStub.collect(jvmMetrics.build());
if (increment.incrementAndGet() % 100 == 0) {
logger.info("sending jvm metric number: {}", increment.get());
}
});
logger.info("sending jvm metric number: {}", increment.get());
}
private static void buildMemoryPoolMetric(JVMMetric.Builder metricBuilder) {
MemoryPool.Builder builder = MemoryPool.newBuilder();
builder.setInit(20);
builder.setMax(50);
builder.setCommited(20);
builder.setUsed(15);
builder.setType(PoolType.NEWGEN_USAGE);
metricBuilder.addMemoryPool(builder);
MemoryPool.Builder codeCache = MemoryPool.newBuilder();
codeCache.setInit(10);
codeCache.setMax(100);
codeCache.setCommited(10);
codeCache.setUsed(50);
codeCache.setType(PoolType.CODE_CACHE_USAGE);
metricBuilder.addMemoryPool(codeCache);
MemoryPool.Builder newGen = MemoryPool.newBuilder();
newGen.setInit(10);
newGen.setMax(100);
newGen.setCommited(10);
newGen.setUsed(50);
newGen.setType(PoolType.NEWGEN_USAGE);
metricBuilder.addMemoryPool(newGen);
MemoryPool.Builder oldGen = MemoryPool.newBuilder();
oldGen.setInit(10);
oldGen.setMax(100);
oldGen.setCommited(10);
oldGen.setUsed(50);
oldGen.setType(PoolType.OLDGEN_USAGE);
metricBuilder.addMemoryPool(oldGen);
MemoryPool.Builder survivor = MemoryPool.newBuilder();
survivor.setInit(10);
survivor.setMax(100);
survivor.setCommited(10);
survivor.setUsed(50);
survivor.setType(PoolType.SURVIVOR_USAGE);
metricBuilder.addMemoryPool(survivor);
MemoryPool.Builder permGen = MemoryPool.newBuilder();
permGen.setInit(10);
permGen.setMax(100);
permGen.setCommited(10);
permGen.setUsed(50);
permGen.setType(PoolType.PERMGEN_USAGE);
metricBuilder.addMemoryPool(permGen);
MemoryPool.Builder metaSpace = MemoryPool.newBuilder();
metaSpace.setInit(10);
metaSpace.setMax(100);
metaSpace.setCommited(10);
metaSpace.setUsed(50);
metaSpace.setType(PoolType.METASPACE_USAGE);
metricBuilder.addMemoryPool(metaSpace);
}
private static void buildMemoryMetric(JVMMetric.Builder metricBuilder) {
Memory.Builder builder = Memory.newBuilder();
builder.setInit(20);
builder.setMax(50);
builder.setCommitted(20);
builder.setUsed(15);
builder.setIsHeap(true);
metricBuilder.addMemory(builder);
Memory.Builder isHeap = Memory.newBuilder();
isHeap.setInit(20);
isHeap.setMax(100);
isHeap.setCommitted(20);
isHeap.setUsed(60);
isHeap.setIsHeap(true);
metricBuilder.addMemory(isHeap);
Memory.Builder nonHeap = Memory.newBuilder();
nonHeap.setInit(20);
nonHeap.setMax(100);
nonHeap.setCommitted(20);
nonHeap.setUsed(60);
nonHeap.setIsHeap(false);
metricBuilder.addMemory(nonHeap);
}
private static void buildGCMetric(JVMMetric.Builder metricBuilder) {
GC.Builder builder = GC.newBuilder();
builder.setPhrase(GCPhrase.NEW);
builder.setCount(2);
metricBuilder.addGc(builder);
GC.Builder newGC = GC.newBuilder();
newGC.setPhrase(GCPhrase.NEW);
newGC.setCount(2);
metricBuilder.addGc(newGC);
GC.Builder oldGC = GC.newBuilder();
oldGC.setPhrase(GCPhrase.OLD);
oldGC.setCount(4);
metricBuilder.addGc(oldGC);
}
private static void buildCPUMetric(JVMMetric.Builder metricBuilder) {
CPU.Builder builder = CPU.newBuilder();
builder.setUsagePercent(20);
metricBuilder.setCpu(builder.build());
CPU.Builder cpu = CPU.newBuilder();
cpu.setUsagePercent(20);
metricBuilder.setCpu(cpu.build());
}
}
......@@ -19,7 +19,6 @@
package org.apache.skywalking.apm.collector.agent.grpc.provider.handler.mock;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.stub.StreamObserver;
import org.apache.skywalking.apm.network.proto.Downstream;
import org.apache.skywalking.apm.network.proto.TraceSegmentServiceGrpc;
......@@ -31,18 +30,11 @@ import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class TraceSegmentMock {
class TraceSegmentMock {
private static final Logger logger = LoggerFactory.getLogger(TraceSegmentMock.class);
public static void main(String[] args) throws InterruptedException {
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 11800).usePlaintext(true).build();
RegisterMock registerMock = new RegisterMock();
registerMock.mock(channel);
Sleeping sleeping = new Sleeping();
void mock(ManagedChannel channel, Long[] times) {
TraceSegmentServiceGrpc.TraceSegmentServiceStub stub = TraceSegmentServiceGrpc.newStub(channel);
StreamObserver<UpstreamSegment> segmentStreamObserver = stub.collect(new StreamObserver<Downstream>() {
@Override public void onNext(Downstream downstream) {
......@@ -52,13 +44,9 @@ public class TraceSegmentMock {
}
@Override public void onCompleted() {
sleeping.setValue(Boolean.FALSE);
}
});
Long[] times = TimeBuilder.INSTANCE.generateTimes();
logger.info("times size: {}", times.length);
for (int i = 0; i < times.length; i++) {
long startTimestamp = times[i];
......@@ -79,23 +67,5 @@ public class TraceSegmentMock {
logger.info("sending segment number: {}", times.length);
segmentStreamObserver.onCompleted();
while (sleeping.getValue()) {
Thread.sleep(200);
}
Thread.sleep(200000);
}
static class Sleeping {
private Boolean value = Boolean.TRUE;
Boolean getValue() {
return value;
}
void setValue(Boolean value) {
this.value = value;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册