You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2017/12/23 07:25:54 UTC

[incubator-servicecomb-java-chassis] branch master updated (e4611cd -> 7fb4030)

This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git.


    from e4611cd  [JAV-589] remove redundant else expression
     new e4b9715  JAV-544 & SC-10 Implement Runtime System Resources Usage Metrics
     new f3c6461  JAV-544 & SCB-10 update asf license
     new 7fb4030  JAV-555 & SCB-10 for trigger ci

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../metrics/core/extra/DefaultSystemResource.java  | 97 ++++++++++++++++++++++
 .../metrics/core/extra/SystemResource.java         | 24 ++++--
 .../metrics/core/metric/InstanceMetric.java        | 13 ++-
 .../metrics/core/metric/RegistryMetric.java        | 13 ++-
 .../metrics/core/metric/SystemMetric.java          | 95 +++++++++++++++++++++
 .../metrics/core/publish/DefaultDataSource.java    | 15 ++--
 .../metrics/core/TestEventAndRunner.java           | 49 +++++++++--
 7 files changed, 283 insertions(+), 23 deletions(-)
 create mode 100644 metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/DefaultSystemResource.java
 copy demo/demo-spring-boot-transport/demo-spring-boot-pojo-client/src/main/java/io/servicecomb/demo/server/Test.java => metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/SystemResource.java (71%)
 create mode 100644 metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/SystemMetric.java

-- 
To stop receiving notification emails like this one, please contact
['"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>'].

[incubator-servicecomb-java-chassis] 02/03: JAV-544 & SCB-10 update asf license

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit f3c64611623709f1206c3e79b7c15561f6bfca20
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Thu Dec 21 09:19:43 2017 +0800

    JAV-544 & SCB-10 update asf license
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../metrics/core/extra/DefaultSystemResource.java           | 13 +++++++------
 .../io/servicecomb/metrics/core/extra/SystemResource.java   | 13 +++++++------
 .../io/servicecomb/metrics/core/metric/SystemMetric.java    | 13 +++++++------
 3 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/DefaultSystemResource.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/DefaultSystemResource.java
index 4934551..c045dc6 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/DefaultSystemResource.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/DefaultSystemResource.java
@@ -1,11 +1,12 @@
 /*
- * Copyright 2017 Huawei Technologies Co., Ltd
+ * 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
  *
- * Licensed 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
+ *     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,
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/SystemResource.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/SystemResource.java
index abe1fe6..d1b72be 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/SystemResource.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/SystemResource.java
@@ -1,11 +1,12 @@
 /*
- * Copyright 2017 Huawei Technologies Co., Ltd
+ * 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
  *
- * Licensed 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
+ *     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,
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/SystemMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/SystemMetric.java
index b5faa04..be7725d 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/SystemMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/SystemMetric.java
@@ -1,11 +1,12 @@
 /*
- * Copyright 2017 Huawei Technologies Co., Ltd
+ * 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
  *
- * Licensed 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
+ *     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,

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 01/03: JAV-544 & SC-10 Implement Runtime System Resources Usage Metrics

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit e4b97156bc7043c4f8bf16fa2261319451b74a91
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Wed Dec 20 11:12:22 2017 +0800

    JAV-544 & SC-10 Implement Runtime System Resources Usage Metrics
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../metrics/core/extra/DefaultSystemResource.java  | 96 ++++++++++++++++++++++
 .../metrics/core/extra/SystemResource.java         | 39 +++++++++
 .../metrics/core/metric/InstanceMetric.java        | 13 ++-
 .../metrics/core/metric/RegistryMetric.java        | 13 ++-
 .../metrics/core/metric/SystemMetric.java          | 94 +++++++++++++++++++++
 .../metrics/core/publish/DefaultDataSource.java    | 15 ++--
 .../metrics/core/TestEventAndRunner.java           | 47 ++++++++++-
 7 files changed, 304 insertions(+), 13 deletions(-)

diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/DefaultSystemResource.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/DefaultSystemResource.java
new file mode 100644
index 0000000..4934551
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/DefaultSystemResource.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd
+ *
+ * Licensed 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 io.servicecomb.metrics.core.extra;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.OperatingSystemMXBean;
+import java.lang.management.ThreadMXBean;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class DefaultSystemResource implements SystemResource {
+
+  private final OperatingSystemMXBean systemMXBean;
+
+  private final ThreadMXBean threadMXBean;
+
+  private final MemoryMXBean memoryMXBean;
+
+  public DefaultSystemResource() {
+    this(ManagementFactory.getOperatingSystemMXBean(), ManagementFactory.getThreadMXBean(),
+        ManagementFactory.getMemoryMXBean());
+  }
+
+  public DefaultSystemResource(OperatingSystemMXBean systemMXBean, ThreadMXBean threadMXBean,
+      MemoryMXBean memoryMXBean) {
+    this.systemMXBean = systemMXBean;
+    this.threadMXBean = threadMXBean;
+    this.memoryMXBean = memoryMXBean;
+  }
+
+  @Override
+  public double getCpuLoad() {
+    return systemMXBean.getSystemLoadAverage();
+  }
+
+  @Override
+  public int getCpuRunningThreads() {
+    return threadMXBean.getThreadCount();
+  }
+
+  @Override
+  public long getHeapInit() {
+    return memoryMXBean.getHeapMemoryUsage().getInit();
+  }
+
+  @Override
+  public long getHeapMax() {
+    return memoryMXBean.getHeapMemoryUsage().getMax();
+  }
+
+  @Override
+  public long getHeapCommit() {
+    return memoryMXBean.getHeapMemoryUsage().getCommitted();
+  }
+
+  @Override
+  public long getHeapUsed() {
+    return memoryMXBean.getHeapMemoryUsage().getUsed();
+  }
+
+  @Override
+  public long getNonHeapInit() {
+    return memoryMXBean.getNonHeapMemoryUsage().getInit();
+  }
+
+  @Override
+  public long getNonHeapMax() {
+    return memoryMXBean.getNonHeapMemoryUsage().getMax();
+  }
+
+  @Override
+  public long getNonHeapCommit() {
+    return memoryMXBean.getNonHeapMemoryUsage().getCommitted();
+  }
+
+  @Override
+  public long getNonHeapUsed() {
+    return memoryMXBean.getNonHeapMemoryUsage().getUsed();
+  }
+}
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/SystemResource.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/SystemResource.java
new file mode 100644
index 0000000..abe1fe6
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/SystemResource.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd
+ *
+ * Licensed 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 io.servicecomb.metrics.core.extra;
+
+public interface SystemResource {
+  double getCpuLoad();
+
+  int getCpuRunningThreads();
+
+  long getHeapInit();
+
+  long getHeapMax();
+
+  long getHeapCommit();
+
+  long getHeapUsed();
+
+  long getNonHeapInit();
+
+  long getNonHeapMax();
+
+  long getNonHeapCommit();
+
+  long getNonHeapUsed();
+}
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InstanceMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InstanceMetric.java
index 1bb5b63..c3e8fa1 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InstanceMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InstanceMetric.java
@@ -18,8 +18,17 @@
 package io.servicecomb.metrics.core.metric;
 
 public class InstanceMetric extends ModelMetric {
-  public InstanceMetric(long waitInQueue, TimerMetric lifeTimeInQueue,
-      TimerMetric executionTime, TimerMetric consumerLatency, TimerMetric producerLatency) {
+
+  private final SystemMetric systemMetric;
+
+  public SystemMetric getSystemMetric() {
+    return systemMetric;
+  }
+
+  public InstanceMetric(long waitInQueue, SystemMetric systemMetric,
+      TimerMetric lifeTimeInQueue, TimerMetric executionTime, TimerMetric consumerLatency,
+      TimerMetric producerLatency) {
     super(waitInQueue, lifeTimeInQueue, executionTime, consumerLatency, producerLatency);
+    this.systemMetric = systemMetric;
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/RegistryMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/RegistryMetric.java
index 4008251..7569420 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/RegistryMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/RegistryMetric.java
@@ -19,6 +19,7 @@ package io.servicecomb.metrics.core.metric;
 
 import java.util.Map;
 
+import io.servicecomb.metrics.core.extra.SystemResource;
 import io.servicecomb.metrics.core.monitor.RegistryMonitor;
 
 public class RegistryMetric {
@@ -35,7 +36,7 @@ public class RegistryMetric {
     return invocationMetrics;
   }
 
-  public RegistryMetric(RegistryMonitor registryMonitor, int pollerIndex) {
+  public RegistryMetric(SystemResource systemResource, RegistryMonitor registryMonitor, int pollerIndex) {
     invocationMetrics = registryMonitor.toInvocationMetrics(pollerIndex);
 
     //sum instance level metric
@@ -51,6 +52,14 @@ public class RegistryMetric {
       consumerLatency = consumerLatency.merge(metric.getConsumerLatency());
       producerLatency = producerLatency.merge(metric.getProducerLatency());
     }
-    instanceMetric = new InstanceMetric(waitInQueue, lifeTimeInQueue, executionTime, consumerLatency, producerLatency);
+
+    SystemMetric systemMetric = new SystemMetric(systemResource.getCpuLoad(), systemResource.getCpuRunningThreads(),
+        systemResource.getHeapInit(), systemResource.getHeapMax(), systemResource.getHeapCommit(),
+        systemResource.getHeapUsed(),
+        systemResource.getNonHeapInit(), systemResource.getNonHeapMax(), systemResource.getNonHeapCommit(),
+        systemResource.getNonHeapUsed());
+
+    instanceMetric = new InstanceMetric(waitInQueue, systemMetric, lifeTimeInQueue, executionTime, consumerLatency,
+        producerLatency);
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/SystemMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/SystemMetric.java
new file mode 100644
index 0000000..b5faa04
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/SystemMetric.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd
+ *
+ * Licensed 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 io.servicecomb.metrics.core.metric;
+
+public class SystemMetric {
+  private final double cpuLoad;
+
+  private final int cpuRunningThreads;
+
+  private final long heapInit;
+
+  private final long heapMax;
+
+  private final long heapCommit;
+
+  private final long heapUsed;
+
+  private final long nonHeapInit;
+
+  private final long nonHeapMax;
+
+  private final long nonHeapCommit;
+
+  private final long nonHeapUsed;
+
+  public double getCpuLoad() {
+    return cpuLoad;
+  }
+
+  public int getCpuRunningThreads() {
+    return cpuRunningThreads;
+  }
+
+  public long getHeapInit() {
+    return heapInit;
+  }
+
+  public long getHeapMax() {
+    return heapMax;
+  }
+
+  public long getHeapCommit() {
+    return heapCommit;
+  }
+
+  public long getHeapUsed() {
+    return heapUsed;
+  }
+
+  public long getNonHeapInit() {
+    return nonHeapInit;
+  }
+
+  public long getNonHeapMax() {
+    return nonHeapMax;
+  }
+
+  public long getNonHeapCommit() {
+    return nonHeapCommit;
+  }
+
+  public long getNonHeapUsed() {
+    return nonHeapUsed;
+  }
+
+  public SystemMetric(double cpuLoad, int cpuRunningThreads,
+      long heapInit, long heapMax, long heapCommit, long heapUsed,
+      long nonHeapInit, long nonHeapMax, long nonHeapCommit, long nonHeapUsed) {
+    this.cpuLoad = cpuLoad;
+    this.cpuRunningThreads = cpuRunningThreads;
+    this.heapInit = heapInit;
+    this.heapMax = heapMax;
+    this.heapCommit = heapCommit;
+    this.heapUsed = heapUsed;
+    this.nonHeapInit = nonHeapInit;
+    this.nonHeapMax = nonHeapMax;
+    this.nonHeapCommit = nonHeapCommit;
+    this.nonHeapUsed = nonHeapUsed;
+  }
+}
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultDataSource.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultDataSource.java
index bd84e54..70ddb18 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultDataSource.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultDataSource.java
@@ -31,6 +31,7 @@ import org.springframework.stereotype.Component;
 import com.netflix.config.DynamicPropertyFactory;
 import com.netflix.servo.monitor.Pollers;
 
+import io.servicecomb.metrics.core.extra.SystemResource;
 import io.servicecomb.metrics.core.metric.RegistryMetric;
 import io.servicecomb.metrics.core.monitor.RegistryMonitor;
 
@@ -44,15 +45,19 @@ public class DefaultDataSource implements DataSource {
 
   private final RegistryMonitor registryMonitor;
 
+  private final SystemResource systemResource;
+
   private final Map<Integer, RegistryMetric> registryMetrics;
 
   @Autowired
-  public DefaultDataSource(RegistryMonitor registryMonitor) {
-    this(registryMonitor, DynamicPropertyFactory.getInstance().getStringProperty(METRICS_POLLING_TIME, "10000").get());
+  public DefaultDataSource(SystemResource systemResource, RegistryMonitor registryMonitor) {
+    this(systemResource, registryMonitor,
+        DynamicPropertyFactory.getInstance().getStringProperty(METRICS_POLLING_TIME, "10000").get());
   }
 
-  public DefaultDataSource(RegistryMonitor registryMonitor, String pollingSettings) {
+  public DefaultDataSource(SystemResource systemResource, RegistryMonitor registryMonitor, String pollingSettings) {
     this.registryMetrics = new ConcurrentHashMap<>();
+    this.systemResource = systemResource;
     this.registryMonitor = registryMonitor;
     //需要限制一下Polling的最小时间间隔, Servo推荐是10000(10秒),默认最低限制为100毫秒
     long minPollingTime = DynamicPropertyFactory.getInstance().getLongProperty(METRICS_POLLING_MIN, 100).get();
@@ -74,7 +79,7 @@ public class DefaultDataSource implements DataSource {
 
   @Override
   public RegistryMetric getRegistryMetric(int pollerIndex) {
-    return registryMetrics.getOrDefault(pollerIndex, new RegistryMetric(registryMonitor, pollerIndex));
+    return registryMetrics.getOrDefault(pollerIndex, new RegistryMetric(systemResource, registryMonitor, pollerIndex));
   }
 
   @Override
@@ -83,6 +88,6 @@ public class DefaultDataSource implements DataSource {
   }
 
   private void reloadRegistryMetric(Integer pollingIndex) {
-    registryMetrics.put(pollingIndex, new RegistryMetric(registryMonitor, pollingIndex));
+    registryMetrics.put(pollingIndex, new RegistryMetric(systemResource, registryMonitor, pollingIndex));
   }
 }
diff --git a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestEventAndRunner.java b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestEventAndRunner.java
index 02aeb63..1b28b95 100644
--- a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestEventAndRunner.java
+++ b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestEventAndRunner.java
@@ -17,16 +17,24 @@
 
 package io.servicecomb.metrics.core;
 
+import static org.mockito.Mockito.when;
+
+import java.lang.management.MemoryMXBean;
+import java.lang.management.MemoryUsage;
+import java.lang.management.OperatingSystemMXBean;
+import java.lang.management.ThreadMXBean;
 import java.util.concurrent.TimeUnit;
 
 import org.junit.Assert;
 import org.junit.Test;
+import org.mockito.Mockito;
 
 import io.servicecomb.core.metrics.InvocationFinishedEvent;
 import io.servicecomb.core.metrics.InvocationStartProcessingEvent;
 import io.servicecomb.core.metrics.InvocationStartedEvent;
 import io.servicecomb.foundation.common.utils.EventUtils;
 import io.servicecomb.metrics.core.event.DefaultEventListenerManager;
+import io.servicecomb.metrics.core.extra.DefaultSystemResource;
 import io.servicecomb.metrics.core.metric.RegistryMetric;
 import io.servicecomb.metrics.core.monitor.RegistryMonitor;
 import io.servicecomb.metrics.core.publish.DefaultDataSource;
@@ -36,8 +44,27 @@ public class TestEventAndRunner {
 
   @Test
   public void test() throws InterruptedException {
+    OperatingSystemMXBean systemMXBean = Mockito.mock(OperatingSystemMXBean.class);
+    when(systemMXBean.getSystemLoadAverage()).thenReturn(1.0);
+    ThreadMXBean threadMXBean = Mockito.mock(ThreadMXBean.class);
+    when(threadMXBean.getThreadCount()).thenReturn(2);
+    MemoryMXBean memoryMXBean = Mockito.mock(MemoryMXBean.class);
+    MemoryUsage heap = Mockito.mock(MemoryUsage.class);
+    when(memoryMXBean.getHeapMemoryUsage()).thenReturn(heap);
+    when(heap.getCommitted()).thenReturn(100L);
+    when(heap.getInit()).thenReturn(200L);
+    when(heap.getMax()).thenReturn(300L);
+    when(heap.getUsed()).thenReturn(400L);
+    MemoryUsage nonHeap = Mockito.mock(MemoryUsage.class);
+    when(memoryMXBean.getNonHeapMemoryUsage()).thenReturn(nonHeap);
+    when(nonHeap.getCommitted()).thenReturn(500L);
+    when(nonHeap.getInit()).thenReturn(600L);
+    when(nonHeap.getMax()).thenReturn(700L);
+    when(nonHeap.getUsed()).thenReturn(800L);
+
     RegistryMonitor monitor = new RegistryMonitor();
-    DefaultDataSource dataSource = new DefaultDataSource(monitor,"2000");
+    DefaultSystemResource systemResource = new DefaultSystemResource(systemMXBean, threadMXBean, memoryMXBean);
+    DefaultDataSource dataSource = new DefaultDataSource(systemResource, monitor, "2000");
 
     DefaultEventListenerManager manager = new DefaultEventListenerManager(monitor);
 
@@ -104,7 +131,6 @@ public class TestEventAndRunner {
     Assert
         .assertEquals(model.getInstanceMetric().getExecutionTime().getAverage(), TimeUnit.MILLISECONDS.toNanos(400), 0);
 
-
     Assert
         .assertEquals(model.getInvocationMetrics().get("fun1").getProducerLatency().getMin(),
             TimeUnit.MILLISECONDS.toNanos(300), 0);
@@ -116,9 +142,11 @@ public class TestEventAndRunner {
             TimeUnit.MILLISECONDS.toNanos(500),
             0);
     Assert.assertEquals(model.getInstanceMetric().getProducerLatency().getMin(), TimeUnit.MILLISECONDS.toNanos(300), 0);
-    Assert.assertEquals(model.getInstanceMetric().getProducerLatency().getMax(), TimeUnit.MILLISECONDS.toNanos(1100), 0);
     Assert
-        .assertEquals(model.getInstanceMetric().getProducerLatency().getAverage(), TimeUnit.MILLISECONDS.toNanos(700), 0);
+        .assertEquals(model.getInstanceMetric().getProducerLatency().getMax(), TimeUnit.MILLISECONDS.toNanos(1100), 0);
+    Assert
+        .assertEquals(model.getInstanceMetric().getProducerLatency().getAverage(), TimeUnit.MILLISECONDS.toNanos(700),
+            0);
 
     Assert
         .assertEquals(model.getInvocationMetrics().get("fun1").getConsumerLatency().getMin(),
@@ -134,5 +162,16 @@ public class TestEventAndRunner {
     Assert.assertEquals(model.getInstanceMetric().getConsumerLatency().getMax(), TimeUnit.MILLISECONDS.toNanos(0), 0);
     Assert
         .assertEquals(model.getInstanceMetric().getConsumerLatency().getAverage(), TimeUnit.MILLISECONDS.toNanos(0), 0);
+
+    Assert.assertEquals(model.getInstanceMetric().getSystemMetric().getCpuLoad(), 1.0, 0);
+    Assert.assertEquals(model.getInstanceMetric().getSystemMetric().getCpuRunningThreads(), 2, 0);
+    Assert.assertEquals(model.getInstanceMetric().getSystemMetric().getHeapCommit(), 100, 0);
+    Assert.assertEquals(model.getInstanceMetric().getSystemMetric().getHeapInit(), 200, 0);
+    Assert.assertEquals(model.getInstanceMetric().getSystemMetric().getHeapMax(), 300, 0);
+    Assert.assertEquals(model.getInstanceMetric().getSystemMetric().getHeapUsed(), 400, 0);
+    Assert.assertEquals(model.getInstanceMetric().getSystemMetric().getNonHeapCommit(), 500, 0);
+    Assert.assertEquals(model.getInstanceMetric().getSystemMetric().getNonHeapInit(), 600, 0);
+    Assert.assertEquals(model.getInstanceMetric().getSystemMetric().getNonHeapMax(), 700, 0);
+    Assert.assertEquals(model.getInstanceMetric().getSystemMetric().getNonHeapUsed(), 800, 0);
   }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 03/03: JAV-555 & SCB-10 for trigger ci

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 7fb40308ce2c9469795c8aab82163f9660804dec
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Fri Dec 22 11:44:47 2017 +0800

    JAV-555 & SCB-10 for trigger ci
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../src/test/java/io/servicecomb/metrics/core/TestEventAndRunner.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestEventAndRunner.java b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestEventAndRunner.java
index 1b28b95..f98f04f 100644
--- a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestEventAndRunner.java
+++ b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestEventAndRunner.java
@@ -174,4 +174,4 @@ public class TestEventAndRunner {
     Assert.assertEquals(model.getInstanceMetric().getSystemMetric().getNonHeapMax(), 700, 0);
     Assert.assertEquals(model.getInstanceMetric().getSystemMetric().getNonHeapUsed(), 800, 0);
   }
-}
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.