未验证 提交 246ea6b3 编写于 作者: X xbkaishui 提交者: GitHub

Make the cpu usage percent always greater than 1 (#5422)

* fix bug #5417, make the CPU usage percent always >= 1
上级 30ce1959
...@@ -77,7 +77,9 @@ public class JVMSourceDispatcher { ...@@ -77,7 +77,9 @@ public class JVMSourceDispatcher {
serviceInstanceJVMCPU.setName(serviceInstance); serviceInstanceJVMCPU.setName(serviceInstance);
serviceInstanceJVMCPU.setServiceId(serviceId); serviceInstanceJVMCPU.setServiceId(serviceId);
serviceInstanceJVMCPU.setServiceName(service); serviceInstanceJVMCPU.setServiceName(service);
serviceInstanceJVMCPU.setUsePercent(cpu.getUsagePercent()); // If the cpu usage percent is less than 1, will set to 1
double adjustedCpuUsagePercent = Math.max(cpu.getUsagePercent(), 1.0);
serviceInstanceJVMCPU.setUsePercent(adjustedCpuUsagePercent);
serviceInstanceJVMCPU.setTimeBucket(timeBucket); serviceInstanceJVMCPU.setTimeBucket(timeBucket);
sourceReceiver.receive(serviceInstanceJVMCPU); sourceReceiver.receive(serviceInstanceJVMCPU);
} }
......
...@@ -46,6 +46,8 @@ import org.junit.Before; ...@@ -46,6 +46,8 @@ import org.junit.Before;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
public class JVMMetricsHandlerTest { public class JVMMetricsHandlerTest {
private static final String TOPIC_NAME = "skywalking-metrics"; private static final String TOPIC_NAME = "skywalking-metrics";
private JVMMetricsHandler handler = null; private JVMMetricsHandler handler = null;
...@@ -59,6 +61,8 @@ public class JVMMetricsHandlerTest { ...@@ -59,6 +61,8 @@ public class JVMMetricsHandlerTest {
@Override @Override
protected void verify(final List<Source> sourceList) throws Throwable { protected void verify(final List<Source> sourceList) throws Throwable {
Assert.assertTrue(sourceList.get(0) instanceof ServiceInstanceJVMCPU); Assert.assertTrue(sourceList.get(0) instanceof ServiceInstanceJVMCPU);
ServiceInstanceJVMCPU serviceInstanceJVMCPU = (ServiceInstanceJVMCPU) sourceList.get(0);
Assert.assertThat(serviceInstanceJVMCPU.getUsePercent(), is(1.0));
Assert.assertTrue(sourceList.get(1) instanceof ServiceInstanceJVMMemory); Assert.assertTrue(sourceList.get(1) instanceof ServiceInstanceJVMMemory);
Assert.assertTrue(sourceList.get(2) instanceof ServiceInstanceJVMMemoryPool); Assert.assertTrue(sourceList.get(2) instanceof ServiceInstanceJVMMemoryPool);
Assert.assertTrue(sourceList.get(3) instanceof ServiceInstanceJVMGC); Assert.assertTrue(sourceList.get(3) instanceof ServiceInstanceJVMGC);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册