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/27 01:26:14 UTC

[incubator-servicecomb-java-chassis] branch master updated (7cf73d6 -> fca6aeb)

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 7cf73d6  [JAV-590] add null pointer check in ClassUtils
     new bc882a5  JAV-539 & SC-9 Implement CallCount and TPS Metrics
     new 4504cd6  JAV-539 & SCB-9 update asf license
     new 6eb8066  JAV-539 & SCB-9 fix pr comment separate Consumer and Producer invocation metric SCB-91 All Monitor can convert to Map with plain-key when polling data
     new 16ffc2b  JAV-539 & SCB-9 add InvocationMonitorType comment
     new b897083  JAV-539 & SCB-9 direct return servo monitor collect data (not cache anymore)
     new 1dbd8bd  JAV-539 & SCB-9 change time-related output from nanosecond to millisecond
     new 7a490c4  JAV-539 & SCB-9 add code comment for windowtime
     new d820323  JAV-539 & SCB-9 resolve conflicts and change "SystemResource" -> "SystemMonitor"
     new ad623b5  JAV-539 & SCB-9 fix pr comment
     new 9a22829  JAV-539 & SCB-9 fix pr comment
     new 09723c5  JAV-539 & SCB-9 minor refactor
     new fca6aeb  JAV-539 SCB-9 resolve conflict

The 12 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:
 .../common/rest/AbstractRestInvocation.java        |   5 +-
 .../common/rest/TestAbstractRestInvocation.java    |  14 +-
 .../core/metrics/InvocationFinishedEvent.java      |  18 +-
 .../metrics/InvocationStartProcessingEvent.java    |  15 +-
 .../core/metrics/InvocationStartedEvent.java       |  10 +-
 .../io/servicecomb/metrics/core/MetricsConst.java  |  16 +-
 .../event/InvocationFinishedEventListener.java     |   6 +-
 .../InvocationStartProcessingEventListener.java    |   6 +-
 .../core/event/InvocationStartedEventListener.java |  12 +-
 .../metrics/core/metric/CallMetric.java            |  40 ++--
 ...elMetric.java => ConsumerInvocationMetric.java} |  49 ++--
 .../metrics/core/metric/InstanceMetric.java        |  24 +-
 .../metrics/core/metric/InvocationMetric.java      |  14 +-
 ...elMetric.java => ProducerInvocationMetric.java} |  44 +++-
 .../metrics/core/metric/RegistryMetric.java        |  73 ++++--
 .../metrics/core/metric/SystemMetric.java          |  19 ++
 .../metrics/core/metric/TimerMetric.java           |  28 ++-
 .../metrics/core/monitor/CallMonitor.java          |  55 +++++
 .../core/monitor/ConsumerInvocationMonitor.java    |  46 ++++
 .../DefaultSystemMonitor.java}                     |  17 +-
 .../metrics/core/monitor/InvocationMonitor.java    |  51 +----
 ...Monitor.java => ProducerInvocationMonitor.java} |  48 ++--
 .../metrics/core/monitor/RegistryMonitor.java      |  41 +++-
 .../SystemMonitor.java}                            |   8 +-
 .../metrics/core/monitor/TimerMonitor.java         |  40 +++-
 .../metrics/core/publish/DataSource.java           |  38 +++-
 .../metrics/core/publish/DefaultDataSource.java    |  54 +----
 .../metrics/core/TestEventAndRunner.java           | 253 ++++++++++++++-------
 .../src/main/resources/microservice.yaml           |  40 ++--
 .../transport/highway/HighwayServerInvoke.java     |   3 +-
 30 files changed, 702 insertions(+), 385 deletions(-)
 copy common/common-protobuf/src/main/java/io/servicecomb/codec/protobuf/utils/WrapClassConfig.java => metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/MetricsConst.java (64%)
 copy swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/engine/SwaggerConsumer.java => metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java (53%)
 copy metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/{ModelMetric.java => ConsumerInvocationMetric.java} (53%)
 rename metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/{ModelMetric.java => ProducerInvocationMetric.java} (55%)
 create mode 100644 metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java
 create mode 100644 metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/ConsumerInvocationMonitor.java
 rename metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/{extra/DefaultSystemResource.java => monitor/DefaultSystemMonitor.java} (81%)
 copy metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/{InvocationMonitor.java => ProducerInvocationMonitor.java} (52%)
 rename metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/{extra/SystemResource.java => monitor/SystemMonitor.java} (86%)

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

[incubator-servicecomb-java-chassis] 05/12: JAV-539 & SCB-9 direct return servo monitor collect data (not cache anymore)

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 b8970835af714e6530483a38cd05f69b1f9b2aa4
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Sat Dec 23 09:27:52 2017 +0800

    JAV-539 & SCB-9 direct return servo monitor collect data (not cache anymore)
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../metrics/core/metric/RegistryMetric.java        |  2 +-
 .../DataSource.java => monitor/BasicMonitor.java}  | 21 ++++++-----
 .../metrics/core/monitor/CallMonitor.java          |  8 ++--
 .../metrics/core/monitor/InvocationMonitor.java    | 16 ++++----
 .../metrics/core/monitor/RegistryMonitor.java      |  6 +--
 .../metrics/core/monitor/TimerMonitor.java         | 11 ++++--
 .../metrics/core/publish/DataSource.java           |  6 +--
 .../metrics/core/publish/DefaultDataSource.java    | 44 ++++------------------
 .../metrics/core/TestEventAndRunner.java           | 23 +++++------
 9 files changed, 58 insertions(+), 79 deletions(-)

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 7238f92..e7e1460 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
@@ -53,7 +53,7 @@ public class RegistryMetric {
     consumerMetrics = new HashMap<>();
     producerMetrics = new HashMap<>();
 
-    //TODO:current java chassis unable know invocation type before starting process,ProducerInvocation + UnknownTypeInvocation
+    //TODO:current java chassis unable know invocation type before starting process,totalWaitInQueue = ProducerInvocation + UnknownTypeInvocation
     long totalWaitInQueue = 0;
     long producerWaitInQueue = 0;
     TimerMetric lifeTimeInQueue = new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".lifeTimeInQueue");
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DataSource.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/BasicMonitor.java
similarity index 64%
copy from metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DataSource.java
copy to metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/BasicMonitor.java
index de39777..69227ac 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DataSource.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/BasicMonitor.java
@@ -15,16 +15,19 @@
  * limitations under the License.
  */
 
-package io.servicecomb.metrics.core.publish;
+package io.servicecomb.metrics.core.monitor;
 
-import java.util.List;
+public class BasicMonitor {
 
-import io.servicecomb.metrics.core.metric.RegistryMetric;
+  //for time-related monitor type, if stop poll value over one window time,
+  //the value may return -1 because servo can't known precise value of previous step
+  //so must change to return 0
+  public double adjustValue(double value) {
+    return value < 0 ? 0 : value;
+  }
 
-public interface DataSource {
-
-  //为上层提供Metric信息
-  RegistryMetric getRegistryMetric(int pollerIndex);
-
-  List<Long> getAppliedPollingIntervals();
+  //same as above
+  public long adjustValue(long value) {
+    return value < 0 ? 0 : value;
+  }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java
index 259a604..ee62a54 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java
@@ -23,7 +23,7 @@ import com.netflix.servo.monitor.StepCounter;
 
 import io.servicecomb.metrics.core.metric.CallMetric;
 
-public class CallMonitor {
+public class CallMonitor extends BasicMonitor {
   private final String prefix;
 
   private final BasicCounter total;
@@ -41,8 +41,8 @@ public class CallMonitor {
     tps.increment();
   }
 
-  public CallMetric toCallMetric(int pollerIndex) {
-    return new CallMetric(this.prefix, total.getValue(pollerIndex).longValue(),
-        tps.getValue(pollerIndex).doubleValue());
+  public CallMetric toCallMetric(int windowTimeIndex) {
+    return new CallMetric(this.prefix, total.getValue(windowTimeIndex).longValue(),
+        this.adjustValue(tps.getValue(windowTimeIndex).doubleValue()));
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitor.java
index e11ee89..f5430f7 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitor.java
@@ -26,7 +26,7 @@ import io.servicecomb.metrics.core.metric.InvocationMetric;
 import io.servicecomb.metrics.core.metric.ProducerInvocationMetric;
 import io.servicecomb.swagger.invocation.InvocationType;
 
-public class InvocationMonitor {
+public class InvocationMonitor extends BasicMonitor {
   private final String operationName;
 
   private final String consumerPrefix;
@@ -104,18 +104,18 @@ public class InvocationMonitor {
     this.producerCall = new CallMonitor(producerPrefix + ".producerCall");
   }
 
-  public InvocationMetric toInvocationMetric(int pollerIndex) {
+  public InvocationMetric toInvocationMetric(int windowTimeIndex) {
     InvocationMetric metric;
-    long queueCount = waitInQueue.getValue(pollerIndex).longValue();
+    long queueCount = waitInQueue.getValue(windowTimeIndex).longValue();
     if (invocationMonitorType.equals(InvocationMonitorType.PRODUCER)) {
       metric = new ProducerInvocationMetric(operationName, producerPrefix, queueCount,
-          lifeTimeInQueue.toTimerMetric(pollerIndex),
-          executionTime.toTimerMetric(pollerIndex),
-          producerLatency.toTimerMetric(pollerIndex),
-          producerCall.toCallMetric(pollerIndex));
+          lifeTimeInQueue.toTimerMetric(windowTimeIndex),
+          executionTime.toTimerMetric(windowTimeIndex),
+          producerLatency.toTimerMetric(windowTimeIndex),
+          producerCall.toCallMetric(windowTimeIndex));
     } else if (invocationMonitorType.equals(InvocationMonitorType.CONSUMER)) {
       metric = new ConsumerInvocationMetric(operationName, consumerPrefix, queueCount,
-          consumerLatency.toTimerMetric(pollerIndex), consumerCall.toCallMetric(pollerIndex));
+          consumerLatency.toTimerMetric(windowTimeIndex), consumerCall.toCallMetric(windowTimeIndex));
     } else {
       metric = new InvocationMetric(operationName, consumerPrefix, queueCount);
     }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/RegistryMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/RegistryMonitor.java
index fd2fc53..0f592d2 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/RegistryMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/RegistryMonitor.java
@@ -27,7 +27,7 @@ import io.servicecomb.metrics.core.metric.InvocationMetric;
 import io.servicecomb.metrics.core.metric.RegistryMetric;
 
 @Component
-public class RegistryMonitor {
+public class RegistryMonitor extends BasicMonitor {
 
   private final Map<String, InvocationMonitor> invocationMonitors;
 
@@ -39,10 +39,10 @@ public class RegistryMonitor {
     return invocationMonitors.computeIfAbsent(operationName, i -> new InvocationMonitor(operationName));
   }
 
-  public RegistryMetric toRegistryMetric(int pollerIndex) {
+  public RegistryMetric toRegistryMetric(int windowTimeIndex) {
     Map<String, InvocationMetric> invocationMetrics = new HashMap<>();
     for (InvocationMonitor monitor : invocationMonitors.values()) {
-      invocationMetrics.put(monitor.getOperationName(), monitor.toInvocationMetric(pollerIndex));
+      invocationMetrics.put(monitor.getOperationName(), monitor.toInvocationMetric(windowTimeIndex));
     }
     return new RegistryMetric(invocationMetrics);
   }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/TimerMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/TimerMonitor.java
index a2120e3..a1aec71 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/TimerMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/TimerMonitor.java
@@ -24,7 +24,7 @@ import com.netflix.servo.monitor.StepCounter;
 
 import io.servicecomb.metrics.core.metric.TimerMetric;
 
-public class TimerMonitor {
+public class TimerMonitor extends BasicMonitor {
   private final String prefix;
 
   private final StepCounter total;
@@ -52,8 +52,11 @@ public class TimerMonitor {
     max = new MaxGauge(MonitorConfig.builder(prefix + ".max").build());
   }
 
-  public TimerMetric toTimerMetric(int pollerIndex) {
-    return new TimerMetric(this.prefix, total.getCount(pollerIndex), count.getCount(pollerIndex),
-        min.getValue(pollerIndex), max.getValue(pollerIndex));
+  public TimerMetric toTimerMetric(int windowTimeIndex) {
+    return new TimerMetric(this.prefix,
+        this.adjustValue(total.getCount(windowTimeIndex)),
+        this.adjustValue(count.getCount(windowTimeIndex)),
+        this.adjustValue(min.getValue(windowTimeIndex)),
+        this.adjustValue(max.getValue(windowTimeIndex)));
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DataSource.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DataSource.java
index de39777..fbd47d4 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DataSource.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DataSource.java
@@ -22,9 +22,9 @@ import java.util.List;
 import io.servicecomb.metrics.core.metric.RegistryMetric;
 
 public interface DataSource {
+  RegistryMetric getRegistryMetric();
 
-  //为上层提供Metric信息
-  RegistryMetric getRegistryMetric(int pollerIndex);
+  RegistryMetric getRegistryMetric(int windowTimeIndex);
 
-  List<Long> getAppliedPollingIntervals();
+  List<Long> getAppliedWindowTime();
 }
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 6aa0420..59a9d91 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
@@ -17,13 +17,7 @@
 
 package io.servicecomb.metrics.core.publish;
 
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-
-import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.Executors;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -38,52 +32,30 @@ import io.servicecomb.metrics.core.monitor.RegistryMonitor;
 public class DefaultDataSource implements DataSource {
   private static final String METRICS_POLLING_TIME = "servicecomb.metrics.polling.time";
 
-  private static final String METRICS_POLLING_MIN = "servicecomb.metrics.polling.min";
-
-  private final List<Long> appliedPollingIntervals;
-
   private final RegistryMonitor registryMonitor;
 
-  private final Map<Integer, RegistryMetric> registryMetrics;
-
   @Autowired
   public DefaultDataSource(RegistryMonitor registryMonitor) {
-    this(registryMonitor, DynamicPropertyFactory.getInstance().getStringProperty(METRICS_POLLING_TIME, "10000").get());
+    this(registryMonitor, DynamicPropertyFactory.getInstance().getStringProperty(METRICS_POLLING_TIME, "5000").get());
   }
 
   public DefaultDataSource(RegistryMonitor registryMonitor, String pollingSettings) {
-    this.registryMetrics = new ConcurrentHashMap<>();
     this.registryMonitor = registryMonitor;
-    //需要限制一下Polling的最小时间间隔, Servo推荐是10000(10秒),默认最低限制为100毫秒
-    long minPollingTime = DynamicPropertyFactory.getInstance().getLongProperty(METRICS_POLLING_MIN, 100).get();
     System.getProperties().setProperty("servo.pollers", pollingSettings);
-
-    List<Long> intervals = Pollers.getPollingIntervals();
-    List<Long> appliedIntervals = new ArrayList<>();
-    for (int index = 0; index < intervals.size(); index++) {
-      int finalIndex = index;
-      long finalInterval = intervals.get(finalIndex) < minPollingTime ? minPollingTime : intervals.get(finalIndex);
-      long pollerInterval = (long) (finalInterval * 0.5);
-      final Runnable poller = () -> reloadRegistryMetric(finalIndex);
-      Executors.newScheduledThreadPool(1)
-          //for step counter correct work we need poll in time ,otherwise current step will return Datapoint.UNKNOWN (missing last sample)
-          .scheduleWithFixedDelay(poller, pollerInterval, pollerInterval, MILLISECONDS);
-      appliedIntervals.add(finalInterval);
-    }
-    this.appliedPollingIntervals = appliedIntervals;
   }
 
   @Override
-  public RegistryMetric getRegistryMetric(int pollerIndex) {
-    return registryMetrics.getOrDefault(pollerIndex, new RegistryMetric());
+  public RegistryMetric getRegistryMetric() {
+    return getRegistryMetric(0);
   }
 
   @Override
-  public List<Long> getAppliedPollingIntervals() {
-    return appliedPollingIntervals;
+  public RegistryMetric getRegistryMetric(int windowTimeIndex) {
+    return registryMonitor.toRegistryMetric(windowTimeIndex);
   }
 
-  private void reloadRegistryMetric(Integer pollerIndex) {
-    registryMetrics.put(pollerIndex, registryMonitor.toRegistryMetric(pollerIndex));
+  @Override
+  public List<Long> getAppliedWindowTime() {
+    return Pollers.getPollingIntervals();
   }
 }
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 06d2b77..9b3a194 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
@@ -39,13 +39,13 @@ public class TestEventAndRunner {
   @Test
   public void test() throws InterruptedException {
     RegistryMonitor monitor = new RegistryMonitor();
-    DefaultDataSource dataSource = new DefaultDataSource(monitor, "2000");
+    DefaultDataSource dataSource = new DefaultDataSource(monitor, "1000");
 
-    List<Long> intervals = dataSource.getAppliedPollingIntervals();
+    List<Long> intervals = dataSource.getAppliedWindowTime();
     Assert.assertEquals(intervals.size(), 1);
-    Assert.assertEquals(intervals.get(0).intValue(), 2000);
+    Assert.assertEquals(intervals.get(0).intValue(), 1000);
 
-    DefaultEventListenerManager manager = new DefaultEventListenerManager(monitor);
+    new DefaultEventListenerManager(monitor);
 
     //fun1 is a PRODUCER invocation call twice and all is completed
     EventUtils.triggerEvent(new InvocationStartedEvent("fun1", System.nanoTime()));
@@ -82,9 +82,10 @@ public class TestEventAndRunner {
     //fun4 is a invocation call only started and no processing start and finished
     EventUtils.triggerEvent(new InvocationStartedEvent("fun4", System.nanoTime()));
 
-    Thread.sleep(2000);
+    //sim lease one window time
+    Thread.sleep(1000);
 
-    RegistryMetric model = dataSource.getRegistryMetric(0);
+    RegistryMetric model = dataSource.getRegistryMetric();
 
     //check InstanceMetric
     Assert.assertEquals(model.getInstanceMetric().getWaitInQueue(), 1);
@@ -119,7 +120,7 @@ public class TestEventAndRunner {
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerLatency().getMin(),
         TimeUnit.MILLISECONDS.toNanos(300));
 
-    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerCall().getTps(), 1.5, 0);
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerCall().getTps(), 3, 0);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerCall().getTotal(), 3);
 
     Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerLatency().getCount(), 1);
@@ -132,7 +133,7 @@ public class TestEventAndRunner {
     Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerLatency().getMin(),
         TimeUnit.MILLISECONDS.toNanos(300));
 
-    Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerCall().getTps(), 0.5, 0);
+    Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerCall().getTps(), 1, 0);
     Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerCall().getTotal(), 1);
 
     //check ProducerMetrics
@@ -167,7 +168,7 @@ public class TestEventAndRunner {
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerLatency().getMin(),
         TimeUnit.MILLISECONDS.toNanos(300));
 
-    Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerCall().getTps(), 1, 0);
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerCall().getTps(), 2, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerCall().getTotal(), 2);
 
     //fun3
@@ -202,7 +203,7 @@ public class TestEventAndRunner {
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerLatency().getMin(),
         TimeUnit.MILLISECONDS.toNanos(0));
 
-    Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerCall().getTps(), 0.5, 0);
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerCall().getTps(), 1, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerCall().getTotal(), 1);
 
     //check ConsumerMetrics
@@ -218,7 +219,7 @@ public class TestEventAndRunner {
     Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerLatency().getMin(),
         TimeUnit.MILLISECONDS.toNanos(300));
 
-    Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerCall().getTps(), 0.5, 0);
+    Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerCall().getTps(), 1, 0);
     Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerCall().getTotal(), 1);
 
     Map<String, Number> metrics = model.toMap();

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

[incubator-servicecomb-java-chassis] 07/12: JAV-539 & SCB-9 add code comment for windowtime

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 7a490c47e05db24a345b0c105ed08e72601834a1
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Sat Dec 23 10:27:59 2017 +0800

    JAV-539 & SCB-9 add code comment for windowtime
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../metrics/core/publish/DataSource.java           | 36 ++++++++++++++++++++--
 .../metrics/core/publish/DefaultDataSource.java    |  2 +-
 .../src/main/resources/microservice.yaml           |  9 +++---
 3 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DataSource.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DataSource.java
index fbd47d4..47f7c83 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DataSource.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DataSource.java
@@ -22,9 +22,41 @@ import java.util.List;
 import io.servicecomb.metrics.core.metric.RegistryMetric;
 
 public interface DataSource {
-  RegistryMetric getRegistryMetric();
 
-  RegistryMetric getRegistryMetric(int windowTimeIndex);
+  /**  What's the WindowTime ?
+  We all know there are two major type of metric :
+   1.Time-unrelated,you can get the latest value any time immediately:
+   Counter -> increase or decrease
+   Guage -> set a certain one value
+   2.Time-related,only after a centain time pass you can compute the right value,"a centain time" called WindowTime
+   Max & Min -> the max value or min value in a centain time
+   Average -> average value, the simplest algorithm is f = sum / count
+   Rate -> like TPS,algorithm is f = sum / second
 
+   Will be return "servicecomb.metrics.window_time" setting in microservice.yaml
+  */
   List<Long> getAppliedWindowTime();
+
+  //return getRegistryMetric(0)
+  RegistryMetric getRegistryMetric();
+
+  /**
+   * windowTimeIndex usage example:
+   * if there is two window time set in "servicecomb.metrics.window_time" like 1000,2000
+   * then windowTimeIndex = 0 will return result of the setting 1000(1 second)
+   * windowTimeIndex = 1 will return result of the setting 2000(2 second)
+   *
+   * there are three monitor of max,min,total
+   * 0----------1----------2----------            <-time line (second)
+   *   100,200    300,400                         <-value record
+   *
+   *                 ↑ getRegistryMetric(0) will return max=200 min=100 total=300
+   *                   getRegistryMetric(1) will return max=0 min=0 total=0
+   *                             ↑ getRegistryMetric(0) will return max=300 min=400 total=700
+   *                               getRegistryMetric(1) will return max=400 min=100 total=1000
+   *
+   * @param windowTimeIndex index of getAppliedWindowTime() item
+   * @return RegistryMetric
+   */
+  RegistryMetric getRegistryMetric(int windowTimeIndex);
 }
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 59a9d91..9549884 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
@@ -30,7 +30,7 @@ import io.servicecomb.metrics.core.monitor.RegistryMonitor;
 
 @Component
 public class DefaultDataSource implements DataSource {
-  private static final String METRICS_POLLING_TIME = "servicecomb.metrics.polling.time";
+  private static final String METRICS_POLLING_TIME = "servicecomb.metrics.window_time";
 
   private final RegistryMonitor registryMonitor;
 
diff --git a/metrics/metrics-sample/metrics-performance-test/src/main/resources/microservice.yaml b/metrics/metrics-sample/metrics-performance-test/src/main/resources/microservice.yaml
index 52596aa..b5edcd1 100644
--- a/metrics/metrics-sample/metrics-performance-test/src/main/resources/microservice.yaml
+++ b/metrics/metrics-sample/metrics-performance-test/src/main/resources/microservice.yaml
@@ -30,7 +30,8 @@ cse:
 
 servicecomb:
   metrics:
-    #polling setting
-    polling:
-      #Support Muti-Polling Time (MILLISECONDS) like 10000,60000 (10s and 60s), Use pollerIndex make selection,start from 0
-      time: 10000
\ No newline at end of file
+    #Support Muti-WindowTime (MILLISECONDS) like 10000,60000 (10s and 60s), Use WindowTimeIndex make selection,start from 0
+    #Default value is single WindowTime : 5000 (5 second)
+    #Will direct set value of "servo.pollers"
+    #More info can be found here : https://github.com/Netflix/servo/wiki/Getting-Started -> Polling Intervals Chapter
+    window_time: 5000
\ No newline at end of file

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

[incubator-servicecomb-java-chassis] 11/12: JAV-539 & SCB-9 minor refactor

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 09723c5e1780f9c542151d8854d4a1f9aa50e03e
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Mon Dec 25 15:46:18 2017 +0800

    JAV-539 & SCB-9 minor refactor
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../common/rest/AbstractRestInvocation.java        |   5 +-
 .../common/rest/TestAbstractRestInvocation.java    |  13 +--
 .../core/metrics/InvocationFinishedEvent.java      |  18 ++--
 .../metrics/InvocationStartProcessingEvent.java    |  15 +--
 .../core/metrics/InvocationStartedEvent.java       |  10 +-
 .../event/InvocationFinishedEventListener.java     |   6 +-
 .../InvocationStartProcessingEventListener.java    |  11 +-
 .../core/event/InvocationStartedEventListener.java |  13 ++-
 .../core/metric/ConsumerInvocationMetric.java      |  18 +---
 .../core/metric/InstanceCalculationMetric.java     | 117 ---------------------
 .../metrics/core/metric/InstanceMetric.java        |   9 +-
 .../metrics/core/metric/InvocationMetric.java      |  21 +---
 .../core/metric/ProducerInvocationMetric.java      |  20 ++--
 .../metrics/core/metric/RegistryMetric.java        |  42 +++++---
 .../metrics/core/metric/SystemMetric.java          |  19 ++++
 .../metrics/core/monitor/BasicMonitor.java         |  41 --------
 .../metrics/core/monitor/CallMonitor.java          |  11 +-
 .../core/monitor/ConsumerInvocationMonitor.java    |  46 ++++++++
 .../metrics/core/monitor/DefaultSystemMonitor.java |   2 +-
 .../metrics/core/monitor/InvocationMonitor.java    |  99 ++---------------
 .../core/monitor/InvocationMonitorType.java        |  25 -----
 .../core/monitor/ProducerInvocationMonitor.java    |  74 +++++++++++++
 .../metrics/core/monitor/RegistryMonitor.java      |  32 ++++--
 .../metrics/core/monitor/SystemMonitor.java        |   2 +-
 .../metrics/core/monitor/TimerMonitor.java         |  19 +++-
 .../metrics/core/TestEventAndRunner.java           |  20 ++--
 .../transport/highway/HighwayServerInvoke.java     |   3 +-
 27 files changed, 302 insertions(+), 409 deletions(-)

diff --git a/common/common-rest/src/main/java/io/servicecomb/common/rest/AbstractRestInvocation.java b/common/common-rest/src/main/java/io/servicecomb/common/rest/AbstractRestInvocation.java
index f7f5134..8fae4ef 100644
--- a/common/common-rest/src/main/java/io/servicecomb/common/rest/AbstractRestInvocation.java
+++ b/common/common-rest/src/main/java/io/servicecomb/common/rest/AbstractRestInvocation.java
@@ -51,6 +51,7 @@ import io.servicecomb.foundation.metrics.performance.QueueMetricsData;
 import io.servicecomb.foundation.vertx.http.HttpServletRequestEx;
 import io.servicecomb.foundation.vertx.http.HttpServletResponseEx;
 import io.servicecomb.foundation.vertx.stream.BufferOutputStream;
+import io.servicecomb.swagger.invocation.InvocationType;
 import io.servicecomb.swagger.invocation.Response;
 import io.servicecomb.swagger.invocation.exception.InvocationException;
 
@@ -109,7 +110,7 @@ public abstract class AbstractRestInvocation {
     OperationMeta operationMeta = restOperationMeta.getOperationMeta();
 
     InvocationStartedEvent startedEvent = new InvocationStartedEvent(operationMeta.getMicroserviceQualifiedName(),
-        System.nanoTime());
+        InvocationType.PRODUCER, System.nanoTime());
     EventUtils.triggerEvent(startedEvent);
 
     QueueMetrics metricsData = initMetrics(operationMeta);
@@ -226,7 +227,7 @@ public abstract class AbstractRestInvocation {
       }
     }
     responseEx.setStatus(response.getStatusCode(), response.getReasonPhrase());
-    responseEx.setContentType(produceProcessor.getName()+"; charset=utf-8");
+    responseEx.setContentType(produceProcessor.getName() + "; charset=utf-8");
 
     Object body = response.getResult();
     if (response.isFailed()) {
diff --git a/common/common-rest/src/test/java/io/servicecomb/common/rest/TestAbstractRestInvocation.java b/common/common-rest/src/test/java/io/servicecomb/common/rest/TestAbstractRestInvocation.java
index ddab596..278c331 100644
--- a/common/common-rest/src/test/java/io/servicecomb/common/rest/TestAbstractRestInvocation.java
+++ b/common/common-rest/src/test/java/io/servicecomb/common/rest/TestAbstractRestInvocation.java
@@ -51,13 +51,11 @@ import io.servicecomb.core.definition.SchemaMeta;
 import io.servicecomb.core.executor.ReactiveExecutor;
 import io.servicecomb.core.provider.consumer.ReferenceConfig;
 import io.servicecomb.foundation.common.utils.JsonUtils;
-import io.servicecomb.foundation.metrics.MetricsServoRegistry;
-import io.servicecomb.foundation.metrics.performance.QueueMetrics;
-import io.servicecomb.foundation.metrics.performance.QueueMetricsData;
 import io.servicecomb.foundation.vertx.http.AbstractHttpServletRequest;
 import io.servicecomb.foundation.vertx.http.HttpServletRequestEx;
 import io.servicecomb.foundation.vertx.http.HttpServletResponseEx;
 import io.servicecomb.swagger.invocation.AsyncResponse;
+import io.servicecomb.swagger.invocation.InvocationType;
 import io.servicecomb.swagger.invocation.Response;
 import io.servicecomb.swagger.invocation.exception.CommonExceptionData;
 import io.servicecomb.swagger.invocation.exception.InvocationException;
@@ -374,7 +372,6 @@ public class TestAbstractRestInvocation {
     restInvocation.sendResponseQuietly(response);
 
     Assert.assertSame(response, result.value);
-
   }
 
   @Test
@@ -625,7 +622,7 @@ public class TestAbstractRestInvocation {
     Error error = new Error("run on executor");
     restInvocation = new AbstractRestInvocationForTest() {
       @Override
-      protected void runOnExecutor(QueueMetrics metricsData,InvocationStartedEvent startedEvent) {
+      protected void runOnExecutor(InvocationStartedEvent startedEvent) {
         throw error;
       }
 
@@ -662,7 +659,7 @@ public class TestAbstractRestInvocation {
 
     restInvocation = new AbstractRestInvocationForTest() {
       @Override
-      protected void runOnExecutor(QueueMetrics metricsData,InvocationStartedEvent startedEvent) {
+      protected void runOnExecutor(InvocationStartedEvent startedEvent) {
         throw new Error("run on executor");
       }
 
@@ -698,7 +695,7 @@ public class TestAbstractRestInvocation {
     Holder<Boolean> result = new Holder<>();
     restInvocation = new AbstractRestInvocationForTest() {
       @Override
-      protected void runOnExecutor(QueueMetrics metricsData,InvocationStartedEvent startedEvent) {
+      protected void runOnExecutor(InvocationStartedEvent startedEvent) {
         result.value = true;
       }
     };
@@ -729,7 +726,7 @@ public class TestAbstractRestInvocation {
     restInvocation.requestEx = requestEx;
     restInvocation.restOperationMeta = restOperation;
 
-    restInvocation.runOnExecutor(null, new InvocationStartedEvent("", System.nanoTime()));
+    restInvocation.runOnExecutor(null,new InvocationStartedEvent("", InvocationType.PRODUCER, System.nanoTime()));
     Assert.assertTrue(result.value);
     Assert.assertSame(invocation, restInvocation.invocation);
   }
diff --git a/core/src/main/java/io/servicecomb/core/metrics/InvocationFinishedEvent.java b/core/src/main/java/io/servicecomb/core/metrics/InvocationFinishedEvent.java
index 90260ca..077e9a8 100644
--- a/core/src/main/java/io/servicecomb/core/metrics/InvocationFinishedEvent.java
+++ b/core/src/main/java/io/servicecomb/core/metrics/InvocationFinishedEvent.java
@@ -23,13 +23,21 @@ import io.servicecomb.swagger.invocation.InvocationType;
 public class InvocationFinishedEvent implements Event {
   private final String operationName;
 
+  private final InvocationType invocationType;
+
   private final long finishedTime;
 
   private final long processElapsedNanoTime;
 
   private final long totalElapsedNanoTime;
 
-  private final InvocationType invocationType;
+  public String getOperationName() {
+    return operationName;
+  }
+
+  public InvocationType getInvocationType() {
+    return invocationType;
+  }
 
   public long getProcessElapsedNanoTime() {
     return processElapsedNanoTime;
@@ -39,14 +47,6 @@ public class InvocationFinishedEvent implements Event {
     return totalElapsedNanoTime;
   }
 
-  public InvocationType getInvocationType() {
-    return invocationType;
-  }
-
-  public String getOperationName() {
-    return operationName;
-  }
-
   public InvocationFinishedEvent(String operationName, InvocationType invocationType, long finishedTime,
       long processElapsedNanoTime,
       long totalElapsedNanoTime) {
diff --git a/core/src/main/java/io/servicecomb/core/metrics/InvocationStartProcessingEvent.java b/core/src/main/java/io/servicecomb/core/metrics/InvocationStartProcessingEvent.java
index 3d39982..9f8ec94 100644
--- a/core/src/main/java/io/servicecomb/core/metrics/InvocationStartProcessingEvent.java
+++ b/core/src/main/java/io/servicecomb/core/metrics/InvocationStartProcessingEvent.java
@@ -23,16 +23,12 @@ import io.servicecomb.swagger.invocation.InvocationType;
 public class InvocationStartProcessingEvent implements Event {
   private final String operationName;
 
+  private final InvocationType invocationType;
+
   private final long startProcessingTime;
 
   private final long inQueueNanoTime;
 
-  private final InvocationType invocationType;
-
-  public long getInQueueNanoTime() {
-    return inQueueNanoTime;
-  }
-
   public String getOperationName() {
     return operationName;
   }
@@ -41,7 +37,12 @@ public class InvocationStartProcessingEvent implements Event {
     return invocationType;
   }
 
-  public InvocationStartProcessingEvent(String operationName, InvocationType invocationType, long startProcessingTime, long inQueueNanoTime) {
+  public long getInQueueNanoTime() {
+    return inQueueNanoTime;
+  }
+
+  public InvocationStartProcessingEvent(String operationName, InvocationType invocationType, long startProcessingTime,
+      long inQueueNanoTime) {
     this.operationName = operationName;
     this.invocationType = invocationType;
     this.startProcessingTime = startProcessingTime;
diff --git a/core/src/main/java/io/servicecomb/core/metrics/InvocationStartedEvent.java b/core/src/main/java/io/servicecomb/core/metrics/InvocationStartedEvent.java
index 09b205b..b233a62 100644
--- a/core/src/main/java/io/servicecomb/core/metrics/InvocationStartedEvent.java
+++ b/core/src/main/java/io/servicecomb/core/metrics/InvocationStartedEvent.java
@@ -18,22 +18,30 @@
 package io.servicecomb.core.metrics;
 
 import io.servicecomb.foundation.common.event.Event;
+import io.servicecomb.swagger.invocation.InvocationType;
 
 public class InvocationStartedEvent implements Event {
   private final String operationName;
 
+  private final InvocationType invocationType;
+
   private final long startedTime;
 
   public String getOperationName() {
     return operationName;
   }
 
+  public InvocationType getInvocationType() {
+    return invocationType;
+  }
+
   public long getStartedTime() {
     return startedTime;
   }
 
-  public InvocationStartedEvent(String operationName, long startedTime) {
+  public InvocationStartedEvent(String operationName, InvocationType invocationType, long startedTime) {
     this.operationName = operationName;
+    this.invocationType = invocationType;
     this.startedTime = startedTime;
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationFinishedEventListener.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationFinishedEventListener.java
index 63ecc99..4c03dc8 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationFinishedEventListener.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationFinishedEventListener.java
@@ -20,7 +20,8 @@ package io.servicecomb.metrics.core.event;
 import io.servicecomb.core.metrics.InvocationFinishedEvent;
 import io.servicecomb.foundation.common.event.Event;
 import io.servicecomb.foundation.common.event.EventListener;
-import io.servicecomb.metrics.core.monitor.InvocationMonitor;
+import io.servicecomb.metrics.core.monitor.ConsumerInvocationMonitor;
+import io.servicecomb.metrics.core.monitor.ProducerInvocationMonitor;
 import io.servicecomb.metrics.core.monitor.RegistryMonitor;
 import io.servicecomb.swagger.invocation.InvocationType;
 
@@ -40,11 +41,12 @@ public class InvocationFinishedEventListener implements EventListener {
   @Override
   public void process(Event data) {
     InvocationFinishedEvent event = (InvocationFinishedEvent) data;
-    InvocationMonitor monitor = registryMonitor.getInvocationMonitor(event.getOperationName());
     if (InvocationType.PRODUCER.equals(event.getInvocationType())) {
+      ProducerInvocationMonitor monitor = registryMonitor.getProducerInvocationMonitor(event.getOperationName());
       monitor.getExecutionTime().update(event.getProcessElapsedNanoTime());
       monitor.getProducerLatency().update(event.getTotalElapsedNanoTime());
     } else {
+      ConsumerInvocationMonitor monitor = registryMonitor.getConsumerInvocationMonitor(event.getOperationName());
       monitor.getConsumerLatency().update(event.getTotalElapsedNanoTime());
     }
   }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartProcessingEventListener.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartProcessingEventListener.java
index d0288f4..dd29b3b 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartProcessingEventListener.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartProcessingEventListener.java
@@ -20,7 +20,7 @@ package io.servicecomb.metrics.core.event;
 import io.servicecomb.core.metrics.InvocationStartProcessingEvent;
 import io.servicecomb.foundation.common.event.Event;
 import io.servicecomb.foundation.common.event.EventListener;
-import io.servicecomb.metrics.core.monitor.InvocationMonitor;
+import io.servicecomb.metrics.core.monitor.ProducerInvocationMonitor;
 import io.servicecomb.metrics.core.monitor.RegistryMonitor;
 import io.servicecomb.swagger.invocation.InvocationType;
 
@@ -40,15 +40,10 @@ public class InvocationStartProcessingEventListener implements EventListener {
   @Override
   public void process(Event data) {
     InvocationStartProcessingEvent event = (InvocationStartProcessingEvent) data;
-    InvocationMonitor monitor = registryMonitor.getInvocationMonitor(event.getOperationName());
-    //TODO:current java chassis unable know invocation type before starting process,so all type WaitInQueue increment(-1) (decrement)
-    monitor.getWaitInQueue().increment(-1);
-    monitor.setInvocationMonitorType(event.getInvocationType());
     if (InvocationType.PRODUCER.equals(event.getInvocationType())) {
+      ProducerInvocationMonitor monitor = registryMonitor.getProducerInvocationMonitor(event.getOperationName());
+      monitor.getWaitInQueue().increment(-1);
       monitor.getLifeTimeInQueue().update(event.getInQueueNanoTime());
-      monitor.getProducerCall().increment();
-    } else {
-      monitor.getConsumerCall().increment();
     }
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartedEventListener.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartedEventListener.java
index ffb97b1..7602c82 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartedEventListener.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartedEventListener.java
@@ -20,7 +20,10 @@ package io.servicecomb.metrics.core.event;
 import io.servicecomb.core.metrics.InvocationStartedEvent;
 import io.servicecomb.foundation.common.event.Event;
 import io.servicecomb.foundation.common.event.EventListener;
+import io.servicecomb.metrics.core.monitor.ConsumerInvocationMonitor;
+import io.servicecomb.metrics.core.monitor.ProducerInvocationMonitor;
 import io.servicecomb.metrics.core.monitor.RegistryMonitor;
+import io.servicecomb.swagger.invocation.InvocationType;
 
 public class InvocationStartedEventListener implements EventListener {
 
@@ -38,7 +41,13 @@ public class InvocationStartedEventListener implements EventListener {
   @Override
   public void process(Event data) {
     InvocationStartedEvent event = (InvocationStartedEvent) data;
-    //TODO:current java chassis unable know invocation type before starting process,so all type WaitInQueue increment
-    registryMonitor.getInvocationMonitor(event.getOperationName()).getWaitInQueue().increment();
+    if (InvocationType.PRODUCER.equals(event.getInvocationType())) {
+      ProducerInvocationMonitor monitor = registryMonitor.getProducerInvocationMonitor(event.getOperationName());
+      monitor.getWaitInQueue().increment();
+      monitor.getProducerCall().increment();
+    } else {
+      ConsumerInvocationMonitor monitor = registryMonitor.getConsumerInvocationMonitor(event.getOperationName());
+      monitor.getConsumerCall().increment();
+    }
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ConsumerInvocationMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ConsumerInvocationMetric.java
index b184cc9..0c0ddfe 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ConsumerInvocationMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ConsumerInvocationMetric.java
@@ -33,25 +33,17 @@ public class ConsumerInvocationMetric extends InvocationMetric {
     return consumerCall;
   }
 
-  public ConsumerInvocationMetric(String operationName, String prefix, long waitInQueue,
+  public ConsumerInvocationMetric(String operationName, String prefix,
       TimerMetric consumerLatency, CallMetric consumerCall) {
-    super(operationName, prefix, waitInQueue);
+    super(operationName, prefix);
     this.consumerLatency = consumerLatency;
     this.consumerCall = consumerCall;
   }
 
-  @Override
-  public InstanceCalculationMetric merge(InstanceCalculationMetric metric) {
-    metric.getConsumerMetrics().put(this.getOperationName(), this);
-    return new InstanceCalculationMetric(metric.getTotalWaitInQueue(),
-        metric.getProducerWaitInQueue(),
-        metric.getConsumerMetrics(), metric.getProducerMetrics(),
-        metric.getLifeTimeInQueue(),
-        metric.getExecutionTime(),
+  public ConsumerInvocationMetric merge(ConsumerInvocationMetric metric) {
+    return new ConsumerInvocationMetric(this.getOperationName(), this.getPrefix(),
         metric.getConsumerLatency().merge(consumerLatency),
-        metric.getProducerLatency(),
-        metric.getConsumerCall().merge(consumerCall),
-        metric.getProducerCall());
+        metric.getConsumerCall().merge(consumerCall));
   }
 
   public Map<String, Number> toMap() {
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InstanceCalculationMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InstanceCalculationMetric.java
deleted file mode 100644
index d923449..0000000
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InstanceCalculationMetric.java
+++ /dev/null
@@ -1,117 +0,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 io.servicecomb.metrics.core.metric;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import io.servicecomb.metrics.core.MetricsConst;
-
-public class InstanceCalculationMetric {
-  private final Map<String, ConsumerInvocationMetric> consumerMetrics;
-
-  private final Map<String, ProducerInvocationMetric> producerMetrics;
-
-  //TODO:current java chassis unable know invocation type before starting process,totalWaitInQueue = ProducerInvocation + UnknownTypeInvocation
-  private final long totalWaitInQueue;
-
-  private final long producerWaitInQueue;
-
-  private final TimerMetric lifeTimeInQueue;
-
-  private final TimerMetric executionTime;
-
-  private final TimerMetric consumerLatency;
-
-  private final TimerMetric producerLatency;
-
-  private final CallMetric consumerCall;
-
-  private final CallMetric producerCall;
-
-  public long getTotalWaitInQueue() {
-    return totalWaitInQueue;
-  }
-
-  public long getProducerWaitInQueue() {
-    return producerWaitInQueue;
-  }
-
-  public Map<String, ConsumerInvocationMetric> getConsumerMetrics() {
-    return consumerMetrics;
-  }
-
-  public Map<String, ProducerInvocationMetric> getProducerMetrics() {
-    return producerMetrics;
-  }
-
-  public TimerMetric getLifeTimeInQueue() {
-    return lifeTimeInQueue;
-  }
-
-  public TimerMetric getExecutionTime() {
-    return executionTime;
-  }
-
-  public TimerMetric getConsumerLatency() {
-    return consumerLatency;
-  }
-
-  public TimerMetric getProducerLatency() {
-    return producerLatency;
-  }
-
-  public CallMetric getConsumerCall() {
-    return consumerCall;
-  }
-
-  public CallMetric getProducerCall() {
-    return producerCall;
-  }
-
-  public InstanceCalculationMetric() {
-    this.totalWaitInQueue = 0;
-    this.producerWaitInQueue = 0;
-    this.consumerMetrics = new HashMap<>();
-    this.producerMetrics = new HashMap<>();
-    this.lifeTimeInQueue = new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".lifeTimeInQueue");
-    this.executionTime = new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".executionTime");
-    this.consumerLatency = new TimerMetric(MetricsConst.INSTANCE_CONSUMER_PREFIX + ".consumerLatency");
-    this.producerLatency = new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".producerLatency");
-    this.consumerCall = new CallMetric(MetricsConst.INSTANCE_CONSUMER_PREFIX + ".consumerCall");
-    this.producerCall = new CallMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".producerCall");
-  }
-
-  public InstanceCalculationMetric(long totalWaitInQueue, long producerWaitInQueue,
-      Map<String, ConsumerInvocationMetric> consumerMetrics,
-      Map<String, ProducerInvocationMetric> producerMetrics,
-      TimerMetric lifeTimeInQueue, TimerMetric executionTime,
-      TimerMetric consumerLatency, TimerMetric producerLatency,
-      CallMetric consumerCall, CallMetric producerCall) {
-    this.totalWaitInQueue = totalWaitInQueue;
-    this.producerWaitInQueue = producerWaitInQueue;
-    this.consumerMetrics = consumerMetrics;
-    this.producerMetrics = producerMetrics;
-    this.lifeTimeInQueue = lifeTimeInQueue;
-    this.executionTime = executionTime;
-    this.consumerLatency = consumerLatency;
-    this.producerLatency = producerLatency;
-    this.consumerCall = consumerCall;
-    this.producerCall = producerCall;
-  }
-}
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 283a664..614fa48 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,18 +18,12 @@
 package io.servicecomb.metrics.core.metric;
 
 public class InstanceMetric {
-  private final long waitInQueue;
-
   private final SystemMetric systemMetric;
 
   private final ConsumerInvocationMetric consumerMetric;
 
   private final ProducerInvocationMetric producerMetric;
 
-  public long getWaitInQueue() {
-    return waitInQueue;
-  }
-
   public SystemMetric getSystemMetric() {
     return systemMetric;
   }
@@ -42,10 +36,9 @@ public class InstanceMetric {
     return producerMetric;
   }
 
-  public InstanceMetric(long waitInQueue, SystemMetric systemMetric,
+  public InstanceMetric(SystemMetric systemMetric,
       ConsumerInvocationMetric consumerMetric,
       ProducerInvocationMetric producerMetric) {
-    this.waitInQueue = waitInQueue;
     this.systemMetric = systemMetric;
     this.consumerMetric = consumerMetric;
     this.producerMetric = producerMetric;
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java
index a33c093..c452a4e 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java
@@ -22,8 +22,6 @@ public class InvocationMetric {
 
   private final String prefix;
 
-  private final long waitInQueue;
-
   public String getOperationName() {
     return operationName;
   }
@@ -32,25 +30,8 @@ public class InvocationMetric {
     return prefix;
   }
 
-  public long getWaitInQueue() {
-    return waitInQueue;
-  }
-
-  public InvocationMetric(String operationName, String prefix, long waitInQueue) {
+  public InvocationMetric(String operationName, String prefix) {
     this.operationName = operationName;
     this.prefix = prefix;
-    this.waitInQueue = waitInQueue;
-  }
-
-  public InstanceCalculationMetric merge(InstanceCalculationMetric metric) {
-    return new InstanceCalculationMetric(metric.getTotalWaitInQueue() + waitInQueue,
-        metric.getProducerWaitInQueue(),
-        metric.getConsumerMetrics(), metric.getProducerMetrics(),
-        metric.getLifeTimeInQueue(),
-        metric.getExecutionTime(),
-        metric.getConsumerLatency(),
-        metric.getProducerLatency(),
-        metric.getConsumerCall(),
-        metric.getProducerCall());
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ProducerInvocationMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ProducerInvocationMetric.java
index b2d53cb..0692e90 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ProducerInvocationMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ProducerInvocationMetric.java
@@ -21,6 +21,8 @@ import java.util.HashMap;
 import java.util.Map;
 
 public class ProducerInvocationMetric extends InvocationMetric {
+  private final long waitInQueue;
+
   private final TimerMetric lifeTimeInQueue;
 
   private final TimerMetric executionTime;
@@ -29,6 +31,10 @@ public class ProducerInvocationMetric extends InvocationMetric {
 
   private final CallMetric producerCall;
 
+  public long getWaitInQueue() {
+    return waitInQueue;
+  }
+
   public TimerMetric getLifeTimeInQueue() {
     return lifeTimeInQueue;
   }
@@ -47,24 +53,20 @@ public class ProducerInvocationMetric extends InvocationMetric {
 
   public ProducerInvocationMetric(String operationName, String prefix, long waitInQueue,
       TimerMetric lifeTimeInQueue, TimerMetric executionTime, TimerMetric producerLatency, CallMetric producerCall) {
-    super(operationName, prefix, waitInQueue);
+    super(operationName, prefix);
+    this.waitInQueue = waitInQueue;
     this.lifeTimeInQueue = lifeTimeInQueue;
     this.executionTime = executionTime;
     this.producerLatency = producerLatency;
     this.producerCall = producerCall;
   }
 
-  @Override
-  public InstanceCalculationMetric merge(InstanceCalculationMetric metric) {
-    metric.getProducerMetrics().put(this.getOperationName(), this);
-    return new InstanceCalculationMetric(metric.getTotalWaitInQueue() + getWaitInQueue(),
-        metric.getProducerWaitInQueue() + getWaitInQueue(),
-        metric.getConsumerMetrics(), metric.getProducerMetrics(),
+  public ProducerInvocationMetric merge(ProducerInvocationMetric metric) {
+    return new ProducerInvocationMetric(this.getOperationName(), this.getPrefix(),
+        this.getWaitInQueue() + metric.getWaitInQueue(),
         metric.getLifeTimeInQueue().merge(lifeTimeInQueue),
         metric.getExecutionTime().merge(executionTime),
-        metric.getConsumerLatency(),
         metric.getProducerLatency().merge(producerLatency),
-        metric.getConsumerCall(),
         metric.getProducerCall().merge(producerCall));
   }
 
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 745a324..7bafee7 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
@@ -42,31 +42,41 @@ public class RegistryMetric {
     return producerMetrics;
   }
 
-  public RegistryMetric(SystemMetric systemMetric, Map<String, InvocationMetric> invocationMetrics) {
+  public RegistryMetric(SystemMetric systemMetric,
+      Map<String, ConsumerInvocationMetric> consumerMetrics,
+      Map<String, ProducerInvocationMetric> producerMetrics) {
+
+    this.consumerMetrics = consumerMetrics;
+    this.producerMetrics = producerMetrics;
+
+    ConsumerInvocationMetric instanceConsumerInvocationMetric = new ConsumerInvocationMetric("instance",
+        MetricsConst.INSTANCE_CONSUMER_PREFIX,
+        new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".producerLatency"),
+        new CallMetric(MetricsConst.INSTANCE_CONSUMER_PREFIX + ".consumerCall"));
+    ProducerInvocationMetric instanceProducerInvocationMetric = new ProducerInvocationMetric("instance",
+        MetricsConst.INSTANCE_PRODUCER_PREFIX, 0,
+        new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".lifeTimeInQueue"),
+        new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".executionTime"),
+        new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".producerLatency"),
+        new CallMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".producerCall"));
+
     //sum instance level metric
-    InstanceCalculationMetric calculationMetric = new InstanceCalculationMetric();
-    for (InvocationMetric metric : invocationMetrics.values()) {
-      calculationMetric = metric.merge(calculationMetric);
+    for (ConsumerInvocationMetric metric : consumerMetrics.values()) {
+      instanceConsumerInvocationMetric = instanceConsumerInvocationMetric.merge(metric);
+    }
+    for (ProducerInvocationMetric metric : producerMetrics.values()) {
+      instanceProducerInvocationMetric = instanceProducerInvocationMetric.merge(metric);
     }
 
-    this.instanceMetric = new InstanceMetric(calculationMetric.getTotalWaitInQueue(), systemMetric,
-        new ConsumerInvocationMetric("instance", MetricsConst.INSTANCE_CONSUMER_PREFIX,
-            calculationMetric.getProducerWaitInQueue(),
-            calculationMetric.getConsumerLatency(), calculationMetric.getConsumerCall()),
-        new ProducerInvocationMetric("instance", MetricsConst.INSTANCE_PRODUCER_PREFIX,
-            calculationMetric.getProducerWaitInQueue(),
-            calculationMetric.getLifeTimeInQueue(), calculationMetric.getExecutionTime(),
-            calculationMetric.getProducerLatency(), calculationMetric.getProducerCall()));
-    this.producerMetrics = calculationMetric.getProducerMetrics();
-    this.consumerMetrics = calculationMetric.getConsumerMetrics();
+    this.instanceMetric = new InstanceMetric(systemMetric,
+        instanceConsumerInvocationMetric, instanceProducerInvocationMetric);
   }
 
   public Map<String, Number> toMap() {
     Map<String, Number> metrics = new HashMap<>();
+    metrics.putAll(instanceMetric.getSystemMetric().toMap());
     metrics.putAll(instanceMetric.getConsumerMetric().toMap());
     metrics.putAll(instanceMetric.getProducerMetric().toMap());
-    //will override waitInQueue.count value
-    metrics.put(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".waitInQueue.count", instanceMetric.getWaitInQueue());
     for (ConsumerInvocationMetric metric : consumerMetrics.values()) {
       metrics.putAll(metric.toMap());
     }
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 be7725d..68fff72 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
@@ -17,6 +17,9 @@
 
 package io.servicecomb.metrics.core.metric;
 
+import java.util.HashMap;
+import java.util.Map;
+
 public class SystemMetric {
   private final double cpuLoad;
 
@@ -92,4 +95,20 @@ public class SystemMetric {
     this.nonHeapCommit = nonHeapCommit;
     this.nonHeapUsed = nonHeapUsed;
   }
+
+  public Map<String, Number> toMap() {
+    String prefix = "servicecomb.instance.system";
+    Map<String, Number> metrics = new HashMap<>();
+    metrics.put(prefix + ".cpu.load", cpuLoad);
+    metrics.put(prefix + ".cpu.runningThreads", cpuRunningThreads);
+    metrics.put(prefix + ".heap.init", heapInit);
+    metrics.put(prefix + ".heap.max", heapMax);
+    metrics.put(prefix + ".heap.commit", heapCommit);
+    metrics.put(prefix + ".heap.used", heapUsed);
+    metrics.put(prefix + ".nonHeap.init", nonHeapInit);
+    metrics.put(prefix + ".nonHeap.max", nonHeapMax);
+    metrics.put(prefix + ".nonHeap.commit", nonHeapCommit);
+    metrics.put(prefix + ".nonHeap.used", nonHeapUsed);
+    return metrics;
+  }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/BasicMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/BasicMonitor.java
deleted file mode 100644
index c881865..0000000
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/BasicMonitor.java
+++ /dev/null
@@ -1,41 +0,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 io.servicecomb.metrics.core.monitor;
-
-import java.util.concurrent.TimeUnit;
-
-public class BasicMonitor {
-
-  //for time-related monitor type, if stop poll value over one window time,
-  //the value may return -1 because servo can't known precise value of previous step
-  //so must change to return 0
-  public double adjustValue(double value) {
-    return value < 0 ? 0 : value;
-  }
-
-  //same as above
-  public long adjustValue(long value) {
-    return value < 0 ? 0 : value;
-  }
-
-  //Counting use System.nano get more precise time
-  //so we need change unit to millisecond when ouput
-  public long convertNanosecondToMillisecond(long nanoValue) {
-    return TimeUnit.NANOSECONDS.toMillis(nanoValue);
-  }
-}
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java
index ee62a54..76778ca 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java
@@ -23,7 +23,7 @@ import com.netflix.servo.monitor.StepCounter;
 
 import io.servicecomb.metrics.core.metric.CallMetric;
 
-public class CallMonitor extends BasicMonitor {
+public class CallMonitor {
   private final String prefix;
 
   private final BasicCounter total;
@@ -41,8 +41,15 @@ public class CallMonitor extends BasicMonitor {
     tps.increment();
   }
 
-  public CallMetric toCallMetric(int windowTimeIndex) {
+  public CallMetric toMetric(int windowTimeIndex) {
     return new CallMetric(this.prefix, total.getValue(windowTimeIndex).longValue(),
         this.adjustValue(tps.getValue(windowTimeIndex).doubleValue()));
   }
+
+  //for time-related monitor type, if stop poll value over one window time,
+  //the value may return -1 because servo can't known precise value of previous step
+  //so must change to return 0
+  public double adjustValue(double value) {
+    return value < 0 ? 0 : value;
+  }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/ConsumerInvocationMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/ConsumerInvocationMonitor.java
new file mode 100644
index 0000000..a297ec4
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/ConsumerInvocationMonitor.java
@@ -0,0 +1,46 @@
+/*
+ * 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 io.servicecomb.metrics.core.monitor;
+
+import io.servicecomb.metrics.core.MetricsConst;
+import io.servicecomb.metrics.core.metric.ConsumerInvocationMetric;
+
+public class ConsumerInvocationMonitor extends InvocationMonitor {
+  private final TimerMonitor consumerLatency;
+
+  private final CallMonitor consumerCall;
+
+  public TimerMonitor getConsumerLatency() {
+    return consumerLatency;
+  }
+
+  public CallMonitor getConsumerCall() {
+    return consumerCall;
+  }
+
+  public ConsumerInvocationMonitor(String operationName) {
+    super(operationName, String.format(MetricsConst.CONSUMER_PREFIX_TEMPLATE, operationName));
+    this.consumerLatency = new TimerMonitor(this.getPrefix() + ".consumerLatency");
+    this.consumerCall = new CallMonitor(this.getPrefix() + ".consumerCall");
+  }
+
+  public ConsumerInvocationMetric toMetric(int windowTimeIndex) {
+    return new ConsumerInvocationMetric(this.getOperationName(), this.getPrefix(),
+        consumerLatency.toMetric(windowTimeIndex), consumerCall.toMetric(windowTimeIndex));
+  }
+}
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/DefaultSystemMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/DefaultSystemMonitor.java
index 16b475b..d027a2c 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/DefaultSystemMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/DefaultSystemMonitor.java
@@ -98,7 +98,7 @@ public class DefaultSystemMonitor implements SystemMonitor {
   }
 
   @Override
-  public SystemMetric toSystemMetric() {
+  public SystemMetric toMetric() {
     return new SystemMetric(getCpuLoad(),
         getCpuRunningThreads(), getHeapInit(), getHeapMax(), getHeapCommit(), getHeapUsed(),
         getNonHeapInit(), getNonHeapMax(), getNonHeapCommit(), getNonHeapUsed());
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitor.java
index f5430f7..c3c19a1 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitor.java
@@ -17,108 +17,21 @@
 
 package io.servicecomb.metrics.core.monitor;
 
-import com.netflix.servo.monitor.BasicCounter;
-import com.netflix.servo.monitor.MonitorConfig;
-
-import io.servicecomb.metrics.core.MetricsConst;
-import io.servicecomb.metrics.core.metric.ConsumerInvocationMetric;
-import io.servicecomb.metrics.core.metric.InvocationMetric;
-import io.servicecomb.metrics.core.metric.ProducerInvocationMetric;
-import io.servicecomb.swagger.invocation.InvocationType;
-
-public class InvocationMonitor extends BasicMonitor {
+public class InvocationMonitor {
   private final String operationName;
 
-  private final String consumerPrefix;
-
-  private final String producerPrefix;
-
-  private final BasicCounter waitInQueue;
-
-  private final TimerMonitor lifeTimeInQueue;
-
-  private final TimerMonitor executionTime;
-
-  private final TimerMonitor producerLatency;
-
-  private final TimerMonitor consumerLatency;
-
-  private final CallMonitor producerCall;
-
-  private final CallMonitor consumerCall;
-
-  private InvocationMonitorType invocationMonitorType = InvocationMonitorType.UNKNOWN;
-
-  //TODO:current java chassis unable know invocation type before starting process,so we need set it,can improve later
-  public void setInvocationMonitorType(InvocationType invocationType) {
-    if (InvocationMonitorType.UNKNOWN.equals(this.invocationMonitorType)) {
-      this.invocationMonitorType = invocationType == InvocationType.PRODUCER ?
-          InvocationMonitorType.PRODUCER : InvocationMonitorType.CONSUMER;
-    }
-  }
+  private final String prefix;
 
   public String getOperationName() {
     return operationName;
   }
 
-  public TimerMonitor getConsumerLatency() {
-    return consumerLatency;
-  }
-
-  public TimerMonitor getLifeTimeInQueue() {
-    return lifeTimeInQueue;
+  public String getPrefix() {
+    return prefix;
   }
 
-  public TimerMonitor getExecutionTime() {
-    return executionTime;
-  }
-
-  public TimerMonitor getProducerLatency() {
-    return producerLatency;
-  }
-
-  public CallMonitor getConsumerCall() {
-    return consumerCall;
-  }
-
-  public CallMonitor getProducerCall() {
-    return producerCall;
-  }
-
-  public BasicCounter getWaitInQueue() {
-    return waitInQueue;
-  }
-
-  public InvocationMonitor(String operationName) {
+  public InvocationMonitor(String operationName, String prefix) {
     this.operationName = operationName;
-    this.consumerPrefix = String.format(MetricsConst.CONSUMER_PREFIX_TEMPLATE, operationName);
-    this.producerPrefix = String.format(MetricsConst.PRODUCER_PREFIX_TEMPLATE, operationName);
-    this.waitInQueue = new BasicCounter(MonitorConfig.builder(producerPrefix + ".waitInQueue.count").build());
-
-    this.consumerLatency = new TimerMonitor(consumerPrefix + ".consumerLatency");
-    this.consumerCall = new CallMonitor(consumerPrefix + ".consumerCall");
-
-    this.lifeTimeInQueue = new TimerMonitor(producerPrefix + ".lifeTimeInQueue");
-    this.executionTime = new TimerMonitor(producerPrefix + ".executionTime");
-    this.producerLatency = new TimerMonitor(producerPrefix + ".producerLatency");
-    this.producerCall = new CallMonitor(producerPrefix + ".producerCall");
-  }
-
-  public InvocationMetric toInvocationMetric(int windowTimeIndex) {
-    InvocationMetric metric;
-    long queueCount = waitInQueue.getValue(windowTimeIndex).longValue();
-    if (invocationMonitorType.equals(InvocationMonitorType.PRODUCER)) {
-      metric = new ProducerInvocationMetric(operationName, producerPrefix, queueCount,
-          lifeTimeInQueue.toTimerMetric(windowTimeIndex),
-          executionTime.toTimerMetric(windowTimeIndex),
-          producerLatency.toTimerMetric(windowTimeIndex),
-          producerCall.toCallMetric(windowTimeIndex));
-    } else if (invocationMonitorType.equals(InvocationMonitorType.CONSUMER)) {
-      metric = new ConsumerInvocationMetric(operationName, consumerPrefix, queueCount,
-          consumerLatency.toTimerMetric(windowTimeIndex), consumerCall.toCallMetric(windowTimeIndex));
-    } else {
-      metric = new InvocationMetric(operationName, consumerPrefix, queueCount);
-    }
-    return metric;
+    this.prefix = prefix;
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitorType.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitorType.java
deleted file mode 100644
index d0408f7..0000000
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitorType.java
+++ /dev/null
@@ -1,25 +0,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 io.servicecomb.metrics.core.monitor;
-
-public enum InvocationMonitorType {
-  //when InvocationStartedEvent received,InvocationType is unknown
-  UNKNOWN,
-  CONSUMER,
-  PRODUCER
-}
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/ProducerInvocationMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/ProducerInvocationMonitor.java
new file mode 100644
index 0000000..b1f945f
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/ProducerInvocationMonitor.java
@@ -0,0 +1,74 @@
+/*
+ * 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 io.servicecomb.metrics.core.monitor;
+
+import com.netflix.servo.monitor.BasicCounter;
+import com.netflix.servo.monitor.MonitorConfig;
+
+import io.servicecomb.metrics.core.MetricsConst;
+import io.servicecomb.metrics.core.metric.ProducerInvocationMetric;
+
+public class ProducerInvocationMonitor extends InvocationMonitor {
+  private final BasicCounter waitInQueue;
+
+  private final TimerMonitor lifeTimeInQueue;
+
+  private final TimerMonitor executionTime;
+
+  private final TimerMonitor producerLatency;
+
+  private final CallMonitor producerCall;
+
+  public BasicCounter getWaitInQueue() {
+    return waitInQueue;
+  }
+
+  public TimerMonitor getLifeTimeInQueue() {
+    return lifeTimeInQueue;
+  }
+
+  public TimerMonitor getExecutionTime() {
+    return executionTime;
+  }
+
+  public TimerMonitor getProducerLatency() {
+    return producerLatency;
+  }
+
+  public CallMonitor getProducerCall() {
+    return producerCall;
+  }
+
+  public ProducerInvocationMonitor(String operationName) {
+    super(operationName, String.format(MetricsConst.PRODUCER_PREFIX_TEMPLATE, operationName));
+    this.waitInQueue = new BasicCounter(MonitorConfig.builder(this.getPrefix() + ".waitInQueue.count").build());
+    this.lifeTimeInQueue = new TimerMonitor(this.getPrefix() + ".lifeTimeInQueue");
+    this.executionTime = new TimerMonitor(this.getPrefix() + ".executionTime");
+    this.producerLatency = new TimerMonitor(this.getPrefix() + ".producerLatency");
+    this.producerCall = new CallMonitor(this.getPrefix() + ".producerCall");
+  }
+
+  public ProducerInvocationMetric toMetric(int windowTimeIndex) {
+    return new ProducerInvocationMetric(this.getOperationName(), this.getPrefix(),
+        this.getWaitInQueue().getValue(windowTimeIndex).longValue(),
+        lifeTimeInQueue.toMetric(windowTimeIndex),
+        executionTime.toMetric(windowTimeIndex),
+        producerLatency.toMetric(windowTimeIndex),
+        producerCall.toMetric(windowTimeIndex));
+  }
+}
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/RegistryMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/RegistryMonitor.java
index c1060de..0772463 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/RegistryMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/RegistryMonitor.java
@@ -24,31 +24,43 @@ import java.util.concurrent.ConcurrentHashMap;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import io.servicecomb.metrics.core.metric.InvocationMetric;
+import io.servicecomb.metrics.core.metric.ConsumerInvocationMetric;
+import io.servicecomb.metrics.core.metric.ProducerInvocationMetric;
 import io.servicecomb.metrics.core.metric.RegistryMetric;
 
 @Component
-public class RegistryMonitor extends BasicMonitor {
+public class RegistryMonitor {
 
   private final SystemMonitor systemMonitor;
 
-  private final Map<String, InvocationMonitor> invocationMonitors;
+  private final Map<String, ConsumerInvocationMonitor> consumerInvocationMonitors;
+
+  private final Map<String, ProducerInvocationMonitor> producerInvocationMonitors;
 
   @Autowired
   public RegistryMonitor(SystemMonitor systemMonitor) {
     this.systemMonitor = systemMonitor;
-    this.invocationMonitors = new ConcurrentHashMap<>();
+    this.consumerInvocationMonitors = new ConcurrentHashMap<>();
+    this.producerInvocationMonitors = new ConcurrentHashMap<>();
+  }
+
+  public ConsumerInvocationMonitor getConsumerInvocationMonitor(String operationName) {
+    return consumerInvocationMonitors.computeIfAbsent(operationName, i -> new ConsumerInvocationMonitor(operationName));
   }
 
-  public InvocationMonitor getInvocationMonitor(String operationName) {
-    return invocationMonitors.computeIfAbsent(operationName, i -> new InvocationMonitor(operationName));
+  public ProducerInvocationMonitor getProducerInvocationMonitor(String operationName) {
+    return producerInvocationMonitors.computeIfAbsent(operationName, i -> new ProducerInvocationMonitor(operationName));
   }
 
   public RegistryMetric toRegistryMetric(int windowTimeIndex) {
-    Map<String, InvocationMetric> invocationMetrics = new HashMap<>();
-    for (InvocationMonitor monitor : invocationMonitors.values()) {
-      invocationMetrics.put(monitor.getOperationName(), monitor.toInvocationMetric(windowTimeIndex));
+    Map<String, ConsumerInvocationMetric> consumerInvocationMetrics = new HashMap<>();
+    for (ConsumerInvocationMonitor monitor : this.consumerInvocationMonitors.values()) {
+      consumerInvocationMetrics.put(monitor.getOperationName(), monitor.toMetric(windowTimeIndex));
+    }
+    Map<String, ProducerInvocationMetric> producerInvocationMetrics = new HashMap<>();
+    for (ProducerInvocationMonitor monitor : this.producerInvocationMonitors.values()) {
+      producerInvocationMetrics.put(monitor.getOperationName(), monitor.toMetric(windowTimeIndex));
     }
-    return new RegistryMetric(systemMonitor.toSystemMetric(), invocationMetrics);
+    return new RegistryMetric(systemMonitor.toMetric(), consumerInvocationMetrics, producerInvocationMetrics);
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/SystemMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/SystemMonitor.java
index c35e6cc..1780e3f 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/SystemMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/SystemMonitor.java
@@ -40,5 +40,5 @@ public interface SystemMonitor {
 
   long getNonHeapUsed();
 
-  SystemMetric toSystemMetric();
+  SystemMetric toMetric();
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/TimerMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/TimerMonitor.java
index 9917b5e..1a15571 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/TimerMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/TimerMonitor.java
@@ -17,6 +17,8 @@
 
 package io.servicecomb.metrics.core.monitor;
 
+import java.util.concurrent.TimeUnit;
+
 import com.netflix.servo.monitor.MaxGauge;
 import com.netflix.servo.monitor.MinGauge;
 import com.netflix.servo.monitor.MonitorConfig;
@@ -24,7 +26,7 @@ import com.netflix.servo.monitor.StepCounter;
 
 import io.servicecomb.metrics.core.metric.TimerMetric;
 
-public class TimerMonitor extends BasicMonitor {
+public class TimerMonitor {
   private final String prefix;
 
   //nanosecond sum
@@ -55,11 +57,24 @@ public class TimerMonitor extends BasicMonitor {
     max = new MaxGauge(MonitorConfig.builder(prefix + ".max").build());
   }
 
-  public TimerMetric toTimerMetric(int windowTimeIndex) {
+  public TimerMetric toMetric(int windowTimeIndex) {
     return new TimerMetric(this.prefix,
         this.convertNanosecondToMillisecond(this.adjustValue(total.getCount(windowTimeIndex))),
         this.adjustValue(count.getCount(windowTimeIndex)),
         this.convertNanosecondToMillisecond(this.adjustValue(min.getValue(windowTimeIndex))),
         this.convertNanosecondToMillisecond(this.adjustValue(max.getValue(windowTimeIndex))));
   }
+
+  //for time-related monitor type, if stop poll value over one window time,
+  //the value may return -1 because servo can't known precise value of previous step
+  //so must change to return 0
+  public long adjustValue(long value) {
+    return value < 0 ? 0 : value;
+  }
+
+  //Counting use System.nano get more precise time
+  //so we need change unit to millisecond when ouput
+  public long convertNanosecondToMillisecond(long nanoValue) {
+    return TimeUnit.NANOSECONDS.toMillis(nanoValue);
+  }
 }
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 8618757..d9a7e2b 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
@@ -75,7 +75,7 @@ public class TestEventAndRunner {
     new DefaultEventListenerManager(monitor);
 
     //fun1 is a PRODUCER invocation call twice and all is completed
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun1", System.nanoTime()));
+    EventUtils.triggerEvent(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime()));
     EventUtils.triggerEvent(
         new InvocationStartProcessingEvent("fun1", InvocationType.PRODUCER, System.nanoTime(),
             TimeUnit.MILLISECONDS.toNanos(100)));
@@ -83,7 +83,7 @@ public class TestEventAndRunner {
         .triggerEvent(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER, System.nanoTime(),
             TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300)));
 
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun1", System.nanoTime()));
+    EventUtils.triggerEvent(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime()));
     EventUtils.triggerEvent(
         new InvocationStartProcessingEvent("fun1", InvocationType.PRODUCER, System.nanoTime(),
             TimeUnit.MILLISECONDS.toNanos(300)));
@@ -92,13 +92,13 @@ public class TestEventAndRunner {
             TimeUnit.MILLISECONDS.toNanos(400), TimeUnit.MILLISECONDS.toNanos(700)));
 
     //fun3 is a PRODUCER invocation call uncompleted
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun3", System.nanoTime()));
+    EventUtils.triggerEvent(new InvocationStartedEvent("fun3", InvocationType.PRODUCER, System.nanoTime()));
     EventUtils.triggerEvent(
         new InvocationStartProcessingEvent("fun3", InvocationType.PRODUCER, System.nanoTime(),
             TimeUnit.MILLISECONDS.toNanos(500)));
 
     //fun2 is a CONSUMER invocation call once and completed
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun2", System.nanoTime()));
+    EventUtils.triggerEvent(new InvocationStartedEvent("fun2", InvocationType.CONSUMER, System.nanoTime()));
     EventUtils.triggerEvent(
         new InvocationStartProcessingEvent("fun2", InvocationType.CONSUMER, System.nanoTime(),
             TimeUnit.MILLISECONDS.toNanos(100)));
@@ -107,7 +107,7 @@ public class TestEventAndRunner {
             TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300)));
 
     //fun4 is a invocation call only started and no processing start and finished
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun4", System.nanoTime()));
+    EventUtils.triggerEvent(new InvocationStartedEvent("fun4", InvocationType.PRODUCER, System.nanoTime()));
 
     //sim lease one window time
     Thread.sleep(1000);
@@ -115,8 +115,7 @@ public class TestEventAndRunner {
     RegistryMetric model = dataSource.getRegistryMetric();
 
     //check InstanceMetric
-    Assert.assertEquals(model.getInstanceMetric().getWaitInQueue(), 1);
-    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getWaitInQueue(), 0);
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getWaitInQueue(), 1);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getLifeTimeInQueue().getCount(), 3);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getLifeTimeInQueue().getTotal(),
         900, 0);
@@ -147,8 +146,8 @@ public class TestEventAndRunner {
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerLatency().getMin(),
         300, 0);
 
-    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerCall().getTps(), 3, 0);
-    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerCall().getTotal(), 3);
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerCall().getTps(), 4, 0);
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerCall().getTotal(), 4);
 
     Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerLatency().getCount(), 1);
     Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerLatency().getTotal(),
@@ -235,7 +234,6 @@ public class TestEventAndRunner {
 
     //check ConsumerMetrics
     //no need
-    Assert.assertEquals(model.getConsumerMetrics().get("fun2").getWaitInQueue(), 0);
     Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerLatency().getCount(), 1);
     Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerLatency().getTotal(),
         300, 0);
@@ -250,7 +248,7 @@ public class TestEventAndRunner {
     Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerCall().getTotal(), 1);
 
     Map<String, Number> metrics = model.toMap();
-    Assert.assertEquals(metrics.size(), 68);
+    Assert.assertEquals(metrics.size(), 72);
 
     Assert.assertEquals(model.getInstanceMetric().getSystemMetric().getCpuLoad(), 1.0, 0);
     Assert.assertEquals(model.getInstanceMetric().getSystemMetric().getCpuRunningThreads(), 2, 0);
diff --git a/transports/transport-highway/src/main/java/io/servicecomb/transport/highway/HighwayServerInvoke.java b/transports/transport-highway/src/main/java/io/servicecomb/transport/highway/HighwayServerInvoke.java
index 68e95e3..8a14252 100644
--- a/transports/transport-highway/src/main/java/io/servicecomb/transport/highway/HighwayServerInvoke.java
+++ b/transports/transport-highway/src/main/java/io/servicecomb/transport/highway/HighwayServerInvoke.java
@@ -39,6 +39,7 @@ import io.servicecomb.foundation.metrics.MetricsServoRegistry;
 import io.servicecomb.foundation.metrics.performance.QueueMetrics;
 import io.servicecomb.foundation.metrics.performance.QueueMetricsData;
 import io.servicecomb.foundation.vertx.tcp.TcpConnection;
+import io.servicecomb.swagger.invocation.InvocationType;
 import io.servicecomb.swagger.invocation.Response;
 import io.servicecomb.swagger.invocation.exception.InvocationException;
 import io.servicecomb.transport.highway.message.RequestHeader;
@@ -167,7 +168,7 @@ public class HighwayServerInvoke {
    */
   public void execute() {
     InvocationStartedEvent startedEvent = new InvocationStartedEvent(operationMeta.getMicroserviceQualifiedName(),
-        System.nanoTime());
+        InvocationType.PRODUCER, System.nanoTime());
     EventUtils.triggerEvent(startedEvent);
     QueueMetrics metricsData = initMetrics(operationMeta);
     operationMeta.getExecutor().execute(() -> runInExecutor(metricsData,startedEvent));

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

[incubator-servicecomb-java-chassis] 08/12: JAV-539 & SCB-9 resolve conflicts and change "SystemResource" -> "SystemMonitor"

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 d8203236c3b033bf275c68c21ecda3f6cda3f836
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Sat Dec 23 16:13:55 2017 +0800

    JAV-539 & SCB-9 resolve conflicts and change "SystemResource" -> "SystemMonitor"
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../metrics/core/metric/CallMetric.java            |  3 --
 .../metrics/core/metric/InstanceMetric.java        | 16 +++++----
 .../metrics/core/metric/InvocationMetric.java      |  3 --
 .../metrics/core/metric/RegistryMetric.java        | 10 ++----
 .../metrics/core/metric/TimerMetric.java           |  3 --
 .../DefaultSystemMonitor.java}                     | 17 ++++++---
 .../metrics/core/monitor/RegistryMonitor.java      |  9 +++--
 .../SystemMonitor.java}                            |  8 +++--
 .../metrics/core/TestEventAndRunner.java           | 40 +++++++++++++++++++++-
 9 files changed, 76 insertions(+), 33 deletions(-)

diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java
index 84a06e4..9c3b0a7 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java
@@ -20,10 +20,7 @@ package io.servicecomb.metrics.core.metric;
 import java.util.HashMap;
 import java.util.Map;
 
-import com.fasterxml.jackson.annotation.JsonIgnore;
-
 public class CallMetric {
-  @JsonIgnore
   private final String prefix;
 
   private final long total;
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 7a934bd..283a664 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
@@ -20,6 +20,8 @@ package io.servicecomb.metrics.core.metric;
 public class InstanceMetric {
   private final long waitInQueue;
 
+  private final SystemMetric systemMetric;
+
   private final ConsumerInvocationMetric consumerMetric;
 
   private final ProducerInvocationMetric producerMetric;
@@ -28,6 +30,10 @@ public class InstanceMetric {
     return waitInQueue;
   }
 
+  public SystemMetric getSystemMetric() {
+    return systemMetric;
+  }
+
   public ConsumerInvocationMetric getConsumerMetric() {
     return consumerMetric;
   }
@@ -36,15 +42,11 @@ public class InstanceMetric {
     return producerMetric;
   }
 
-  public InstanceMetric() {
-    waitInQueue = 0;
-    consumerMetric = null;
-    producerMetric = null;
-  }
-
-  public InstanceMetric(long waitInQueue, ConsumerInvocationMetric consumerMetric,
+  public InstanceMetric(long waitInQueue, SystemMetric systemMetric,
+      ConsumerInvocationMetric consumerMetric,
       ProducerInvocationMetric producerMetric) {
     this.waitInQueue = waitInQueue;
+    this.systemMetric = systemMetric;
     this.consumerMetric = consumerMetric;
     this.producerMetric = producerMetric;
   }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java
index 03c66db..62e489d 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java
@@ -17,12 +17,9 @@
 
 package io.servicecomb.metrics.core.metric;
 
-import com.fasterxml.jackson.annotation.JsonIgnore;
-
 public class InvocationMetric {
   private final String operationName;
 
-  @JsonIgnore
   private final String prefix;
 
   private final long waitInQueue;
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 e7e1460..ccb5706 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
@@ -42,13 +42,7 @@ public class RegistryMetric {
     return producerMetrics;
   }
 
-  public RegistryMetric() {
-    consumerMetrics = new HashMap<>();
-    producerMetrics = new HashMap<>();
-    instanceMetric = new InstanceMetric();
-  }
-
-  public RegistryMetric(Map<String, InvocationMetric> invocationMetrics) {
+  public RegistryMetric(SystemMetric systemMetric, Map<String, InvocationMetric> invocationMetrics) {
     //sum instance level metric
     consumerMetrics = new HashMap<>();
     producerMetrics = new HashMap<>();
@@ -85,7 +79,7 @@ public class RegistryMetric {
       }
     }
 
-    instanceMetric = new InstanceMetric(totalWaitInQueue,
+    instanceMetric = new InstanceMetric(totalWaitInQueue, systemMetric,
         new ConsumerInvocationMetric("instance", MetricsConst.INSTANCE_CONSUMER_PREFIX,
             producerWaitInQueue, consumerLatency, consumerCall),
         new ProducerInvocationMetric("instance", MetricsConst.INSTANCE_PRODUCER_PREFIX,
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java
index 7212806..45f3f57 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java
@@ -20,10 +20,7 @@ package io.servicecomb.metrics.core.metric;
 import java.util.HashMap;
 import java.util.Map;
 
-import com.fasterxml.jackson.annotation.JsonIgnore;
-
 public class TimerMetric {
-  @JsonIgnore
   private final String prefix;
 
   private final double total;
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/monitor/DefaultSystemMonitor.java
similarity index 81%
rename from metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/DefaultSystemResource.java
rename to metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/DefaultSystemMonitor.java
index c045dc6..16b475b 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/monitor/DefaultSystemMonitor.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package io.servicecomb.metrics.core.extra;
+package io.servicecomb.metrics.core.monitor;
 
 import java.lang.management.ManagementFactory;
 import java.lang.management.MemoryMXBean;
@@ -24,8 +24,10 @@ import java.lang.management.ThreadMXBean;
 
 import org.springframework.stereotype.Component;
 
+import io.servicecomb.metrics.core.metric.SystemMetric;
+
 @Component
-public class DefaultSystemResource implements SystemResource {
+public class DefaultSystemMonitor implements SystemMonitor {
 
   private final OperatingSystemMXBean systemMXBean;
 
@@ -33,12 +35,12 @@ public class DefaultSystemResource implements SystemResource {
 
   private final MemoryMXBean memoryMXBean;
 
-  public DefaultSystemResource() {
+  public DefaultSystemMonitor() {
     this(ManagementFactory.getOperatingSystemMXBean(), ManagementFactory.getThreadMXBean(),
         ManagementFactory.getMemoryMXBean());
   }
 
-  public DefaultSystemResource(OperatingSystemMXBean systemMXBean, ThreadMXBean threadMXBean,
+  public DefaultSystemMonitor(OperatingSystemMXBean systemMXBean, ThreadMXBean threadMXBean,
       MemoryMXBean memoryMXBean) {
     this.systemMXBean = systemMXBean;
     this.threadMXBean = threadMXBean;
@@ -94,4 +96,11 @@ public class DefaultSystemResource implements SystemResource {
   public long getNonHeapUsed() {
     return memoryMXBean.getNonHeapMemoryUsage().getUsed();
   }
+
+  @Override
+  public SystemMetric toSystemMetric() {
+    return new SystemMetric(getCpuLoad(),
+        getCpuRunningThreads(), getHeapInit(), getHeapMax(), getHeapCommit(), getHeapUsed(),
+        getNonHeapInit(), getNonHeapMax(), getNonHeapCommit(), getNonHeapUsed());
+  }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/RegistryMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/RegistryMonitor.java
index 0f592d2..c1060de 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/RegistryMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/RegistryMonitor.java
@@ -21,6 +21,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import io.servicecomb.metrics.core.metric.InvocationMetric;
@@ -29,9 +30,13 @@ import io.servicecomb.metrics.core.metric.RegistryMetric;
 @Component
 public class RegistryMonitor extends BasicMonitor {
 
+  private final SystemMonitor systemMonitor;
+
   private final Map<String, InvocationMonitor> invocationMonitors;
 
-  public RegistryMonitor() {
+  @Autowired
+  public RegistryMonitor(SystemMonitor systemMonitor) {
+    this.systemMonitor = systemMonitor;
     this.invocationMonitors = new ConcurrentHashMap<>();
   }
 
@@ -44,6 +49,6 @@ public class RegistryMonitor extends BasicMonitor {
     for (InvocationMonitor monitor : invocationMonitors.values()) {
       invocationMetrics.put(monitor.getOperationName(), monitor.toInvocationMetric(windowTimeIndex));
     }
-    return new RegistryMetric(invocationMetrics);
+    return new RegistryMetric(systemMonitor.toSystemMetric(), invocationMetrics);
   }
 }
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/monitor/SystemMonitor.java
similarity index 86%
rename from metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/extra/SystemResource.java
rename to metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/SystemMonitor.java
index d1b72be..c35e6cc 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/monitor/SystemMonitor.java
@@ -15,9 +15,11 @@
  * limitations under the License.
  */
 
-package io.servicecomb.metrics.core.extra;
+package io.servicecomb.metrics.core.monitor;
 
-public interface SystemResource {
+import io.servicecomb.metrics.core.metric.SystemMetric;
+
+public interface SystemMonitor {
   double getCpuLoad();
 
   int getCpuRunningThreads();
@@ -37,4 +39,6 @@ public interface SystemResource {
   long getNonHeapCommit();
 
   long getNonHeapUsed();
+
+  SystemMetric toSystemMetric();
 }
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 ae518fd..8c638d6 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,12 +17,19 @@
 
 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.List;
 import java.util.Map;
 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;
@@ -30,6 +37,7 @@ 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.metric.RegistryMetric;
+import io.servicecomb.metrics.core.monitor.DefaultSystemMonitor;
 import io.servicecomb.metrics.core.monitor.RegistryMonitor;
 import io.servicecomb.metrics.core.publish.DefaultDataSource;
 import io.servicecomb.swagger.invocation.InvocationType;
@@ -38,7 +46,26 @@ public class TestEventAndRunner {
 
   @Test
   public void test() throws InterruptedException {
-    RegistryMonitor monitor = new RegistryMonitor();
+    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);
+
+    DefaultSystemMonitor systemMonitor = new DefaultSystemMonitor(systemMXBean, threadMXBean, memoryMXBean);
+    RegistryMonitor monitor = new RegistryMonitor(systemMonitor);
     DefaultDataSource dataSource = new DefaultDataSource(monitor, "1000");
 
     List<Long> intervals = dataSource.getAppliedWindowTime();
@@ -224,5 +251,16 @@ public class TestEventAndRunner {
 
     Map<String, Number> metrics = model.toMap();
     Assert.assertEquals(metrics.size(), 68);
+
+    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] 09/12: JAV-539 & SCB-9 fix pr comment

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 ad623b5f253921da0cb08bca62f6b23658d35f4d
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Sat Dec 23 18:00:54 2017 +0800

    JAV-539 & SCB-9 fix pr comment
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../core/metric/ConsumerInvocationMetric.java      |  14 +++
 .../core/metric/InstanceCalculationMetric.java     | 117 +++++++++++++++++++++
 .../metrics/core/metric/InvocationMetric.java      |  12 +++
 .../core/metric/ProducerInvocationMetric.java      |  14 +++
 .../metrics/core/metric/RegistryMetric.java        |  45 ++------
 .../metrics/core/metric/TimerMetric.java           |  18 ++--
 .../metrics/core/monitor/BasicMonitor.java         |   6 +-
 .../metrics/core/TestEventAndRunner.java           |   2 +-
 8 files changed, 181 insertions(+), 47 deletions(-)

diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ConsumerInvocationMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ConsumerInvocationMetric.java
index f0059a3..b184cc9 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ConsumerInvocationMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ConsumerInvocationMetric.java
@@ -40,6 +40,20 @@ public class ConsumerInvocationMetric extends InvocationMetric {
     this.consumerCall = consumerCall;
   }
 
+  @Override
+  public InstanceCalculationMetric merge(InstanceCalculationMetric metric) {
+    metric.getConsumerMetrics().put(this.getOperationName(), this);
+    return new InstanceCalculationMetric(metric.getTotalWaitInQueue(),
+        metric.getProducerWaitInQueue(),
+        metric.getConsumerMetrics(), metric.getProducerMetrics(),
+        metric.getLifeTimeInQueue(),
+        metric.getExecutionTime(),
+        metric.getConsumerLatency().merge(consumerLatency),
+        metric.getProducerLatency(),
+        metric.getConsumerCall().merge(consumerCall),
+        metric.getProducerCall());
+  }
+
   public Map<String, Number> toMap() {
     Map<String, Number> metrics = new HashMap<>();
     metrics.putAll(consumerLatency.toMap());
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InstanceCalculationMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InstanceCalculationMetric.java
new file mode 100644
index 0000000..d923449
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InstanceCalculationMetric.java
@@ -0,0 +1,117 @@
+/*
+ * 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 io.servicecomb.metrics.core.metric;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import io.servicecomb.metrics.core.MetricsConst;
+
+public class InstanceCalculationMetric {
+  private final Map<String, ConsumerInvocationMetric> consumerMetrics;
+
+  private final Map<String, ProducerInvocationMetric> producerMetrics;
+
+  //TODO:current java chassis unable know invocation type before starting process,totalWaitInQueue = ProducerInvocation + UnknownTypeInvocation
+  private final long totalWaitInQueue;
+
+  private final long producerWaitInQueue;
+
+  private final TimerMetric lifeTimeInQueue;
+
+  private final TimerMetric executionTime;
+
+  private final TimerMetric consumerLatency;
+
+  private final TimerMetric producerLatency;
+
+  private final CallMetric consumerCall;
+
+  private final CallMetric producerCall;
+
+  public long getTotalWaitInQueue() {
+    return totalWaitInQueue;
+  }
+
+  public long getProducerWaitInQueue() {
+    return producerWaitInQueue;
+  }
+
+  public Map<String, ConsumerInvocationMetric> getConsumerMetrics() {
+    return consumerMetrics;
+  }
+
+  public Map<String, ProducerInvocationMetric> getProducerMetrics() {
+    return producerMetrics;
+  }
+
+  public TimerMetric getLifeTimeInQueue() {
+    return lifeTimeInQueue;
+  }
+
+  public TimerMetric getExecutionTime() {
+    return executionTime;
+  }
+
+  public TimerMetric getConsumerLatency() {
+    return consumerLatency;
+  }
+
+  public TimerMetric getProducerLatency() {
+    return producerLatency;
+  }
+
+  public CallMetric getConsumerCall() {
+    return consumerCall;
+  }
+
+  public CallMetric getProducerCall() {
+    return producerCall;
+  }
+
+  public InstanceCalculationMetric() {
+    this.totalWaitInQueue = 0;
+    this.producerWaitInQueue = 0;
+    this.consumerMetrics = new HashMap<>();
+    this.producerMetrics = new HashMap<>();
+    this.lifeTimeInQueue = new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".lifeTimeInQueue");
+    this.executionTime = new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".executionTime");
+    this.consumerLatency = new TimerMetric(MetricsConst.INSTANCE_CONSUMER_PREFIX + ".consumerLatency");
+    this.producerLatency = new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".producerLatency");
+    this.consumerCall = new CallMetric(MetricsConst.INSTANCE_CONSUMER_PREFIX + ".consumerCall");
+    this.producerCall = new CallMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".producerCall");
+  }
+
+  public InstanceCalculationMetric(long totalWaitInQueue, long producerWaitInQueue,
+      Map<String, ConsumerInvocationMetric> consumerMetrics,
+      Map<String, ProducerInvocationMetric> producerMetrics,
+      TimerMetric lifeTimeInQueue, TimerMetric executionTime,
+      TimerMetric consumerLatency, TimerMetric producerLatency,
+      CallMetric consumerCall, CallMetric producerCall) {
+    this.totalWaitInQueue = totalWaitInQueue;
+    this.producerWaitInQueue = producerWaitInQueue;
+    this.consumerMetrics = consumerMetrics;
+    this.producerMetrics = producerMetrics;
+    this.lifeTimeInQueue = lifeTimeInQueue;
+    this.executionTime = executionTime;
+    this.consumerLatency = consumerLatency;
+    this.producerLatency = producerLatency;
+    this.consumerCall = consumerCall;
+    this.producerCall = producerCall;
+  }
+}
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java
index 62e489d..a33c093 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java
@@ -41,4 +41,16 @@ public class InvocationMetric {
     this.prefix = prefix;
     this.waitInQueue = waitInQueue;
   }
+
+  public InstanceCalculationMetric merge(InstanceCalculationMetric metric) {
+    return new InstanceCalculationMetric(metric.getTotalWaitInQueue() + waitInQueue,
+        metric.getProducerWaitInQueue(),
+        metric.getConsumerMetrics(), metric.getProducerMetrics(),
+        metric.getLifeTimeInQueue(),
+        metric.getExecutionTime(),
+        metric.getConsumerLatency(),
+        metric.getProducerLatency(),
+        metric.getConsumerCall(),
+        metric.getProducerCall());
+  }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ProducerInvocationMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ProducerInvocationMetric.java
index 4eaa8c3..b2d53cb 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ProducerInvocationMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ProducerInvocationMetric.java
@@ -54,6 +54,20 @@ public class ProducerInvocationMetric extends InvocationMetric {
     this.producerCall = producerCall;
   }
 
+  @Override
+  public InstanceCalculationMetric merge(InstanceCalculationMetric metric) {
+    metric.getProducerMetrics().put(this.getOperationName(), this);
+    return new InstanceCalculationMetric(metric.getTotalWaitInQueue() + getWaitInQueue(),
+        metric.getProducerWaitInQueue() + getWaitInQueue(),
+        metric.getConsumerMetrics(), metric.getProducerMetrics(),
+        metric.getLifeTimeInQueue().merge(lifeTimeInQueue),
+        metric.getExecutionTime().merge(executionTime),
+        metric.getConsumerLatency(),
+        metric.getProducerLatency().merge(producerLatency),
+        metric.getConsumerCall(),
+        metric.getProducerCall().merge(producerCall));
+  }
+
   public Map<String, Number> toMap() {
     Map<String, Number> metrics = new HashMap<>();
     metrics.put(getPrefix() + ".waitInQueue.count", getWaitInQueue());
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 ccb5706..745a324 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
@@ -44,46 +44,21 @@ public class RegistryMetric {
 
   public RegistryMetric(SystemMetric systemMetric, Map<String, InvocationMetric> invocationMetrics) {
     //sum instance level metric
-    consumerMetrics = new HashMap<>();
-    producerMetrics = new HashMap<>();
-
-    //TODO:current java chassis unable know invocation type before starting process,totalWaitInQueue = ProducerInvocation + UnknownTypeInvocation
-    long totalWaitInQueue = 0;
-    long producerWaitInQueue = 0;
-    TimerMetric lifeTimeInQueue = new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".lifeTimeInQueue");
-    TimerMetric executionTime = new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".executionTime");
-    TimerMetric consumerLatency = new TimerMetric(MetricsConst.INSTANCE_CONSUMER_PREFIX + ".consumerLatency");
-    TimerMetric producerLatency = new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".producerLatency");
-    CallMetric consumerCall = new CallMetric(MetricsConst.INSTANCE_CONSUMER_PREFIX + ".consumerCall");
-    CallMetric producerCall = new CallMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".producerCall");
-
+    InstanceCalculationMetric calculationMetric = new InstanceCalculationMetric();
     for (InvocationMetric metric : invocationMetrics.values()) {
-      if (metric != null) {
-        if (metric instanceof ConsumerInvocationMetric) {
-          ConsumerInvocationMetric consumerMetric = (ConsumerInvocationMetric) metric;
-          consumerLatency = consumerLatency.merge(consumerMetric.getConsumerLatency());
-          consumerCall = consumerCall.merge(consumerMetric.getConsumerCall());
-          consumerMetrics.put(metric.getOperationName(), consumerMetric);
-        } else if (metric instanceof ProducerInvocationMetric) {
-          ProducerInvocationMetric producerMetric = (ProducerInvocationMetric) metric;
-          totalWaitInQueue += producerMetric.getWaitInQueue();
-          producerWaitInQueue += producerMetric.getWaitInQueue();
-          lifeTimeInQueue = lifeTimeInQueue.merge(producerMetric.getLifeTimeInQueue());
-          executionTime = executionTime.merge(producerMetric.getExecutionTime());
-          producerLatency = producerLatency.merge(producerMetric.getProducerLatency());
-          producerCall = producerCall.merge(producerMetric.getProducerCall());
-          producerMetrics.put(metric.getOperationName(), producerMetric);
-        } else {
-          totalWaitInQueue += metric.getWaitInQueue();
-        }
-      }
+      calculationMetric = metric.merge(calculationMetric);
     }
 
-    instanceMetric = new InstanceMetric(totalWaitInQueue, systemMetric,
+    this.instanceMetric = new InstanceMetric(calculationMetric.getTotalWaitInQueue(), systemMetric,
         new ConsumerInvocationMetric("instance", MetricsConst.INSTANCE_CONSUMER_PREFIX,
-            producerWaitInQueue, consumerLatency, consumerCall),
+            calculationMetric.getProducerWaitInQueue(),
+            calculationMetric.getConsumerLatency(), calculationMetric.getConsumerCall()),
         new ProducerInvocationMetric("instance", MetricsConst.INSTANCE_PRODUCER_PREFIX,
-            totalWaitInQueue, lifeTimeInQueue, executionTime, producerLatency, producerCall));
+            calculationMetric.getProducerWaitInQueue(),
+            calculationMetric.getLifeTimeInQueue(), calculationMetric.getExecutionTime(),
+            calculationMetric.getProducerLatency(), calculationMetric.getProducerCall()));
+    this.producerMetrics = calculationMetric.getProducerMetrics();
+    this.consumerMetrics = calculationMetric.getConsumerMetrics();
   }
 
   public Map<String, Number> toMap() {
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java
index 45f3f57..0c38480 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java
@@ -23,17 +23,17 @@ import java.util.Map;
 public class TimerMetric {
   private final String prefix;
 
-  private final double total;
+  private final long total;
 
   private final long count;
 
   private final double average;
 
-  private final double min;
+  private final long min;
 
-  private final double max;
+  private final long max;
 
-  public double getTotal() {
+  public long getTotal() {
     return total;
   }
 
@@ -45,11 +45,11 @@ public class TimerMetric {
     return average;
   }
 
-  public double getMin() {
+  public long getMin() {
     return min;
   }
 
-  public double getMax() {
+  public long getMax() {
     return max;
   }
 
@@ -57,7 +57,7 @@ public class TimerMetric {
     this(prefix, 0, 0, 0, 0);
   }
 
-  public TimerMetric(String prefix, double total, long count, double min, double max) {
+  public TimerMetric(String prefix, long total, long count, long min, long max) {
     this.prefix = prefix;
     this.total = total;
     this.count = count;
@@ -75,11 +75,11 @@ public class TimerMetric {
         getMin(this.min, metric.min), getMax(this.max, metric.max));
   }
 
-  private double getMin(double value1, double value2) {
+  private long getMin(long value1, long value2) {
     return value1 == 0 || (value2 != 0 && value2 < value1) ? value2 : value1;
   }
 
-  private double getMax(double value1, double value2) {
+  private long getMax(long value1, long value2) {
     return value2 > value1 ? value2 : value1;
   }
 
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/BasicMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/BasicMonitor.java
index 6045d16..c881865 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/BasicMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/BasicMonitor.java
@@ -17,6 +17,8 @@
 
 package io.servicecomb.metrics.core.monitor;
 
+import java.util.concurrent.TimeUnit;
+
 public class BasicMonitor {
 
   //for time-related monitor type, if stop poll value over one window time,
@@ -33,7 +35,7 @@ public class BasicMonitor {
 
   //Counting use System.nano get more precise time
   //so we need change unit to millisecond when ouput
-  public double convertNanosecondToMillisecond(long nanoValue){
-    return nanoValue * 0.000001;
+  public long convertNanosecondToMillisecond(long nanoValue) {
+    return TimeUnit.NANOSECONDS.toMillis(nanoValue);
   }
 }
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 8c638d6..8618757 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
@@ -116,7 +116,7 @@ public class TestEventAndRunner {
 
     //check InstanceMetric
     Assert.assertEquals(model.getInstanceMetric().getWaitInQueue(), 1);
-    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getWaitInQueue(), 1);
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getWaitInQueue(), 0);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getLifeTimeInQueue().getCount(), 3);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getLifeTimeInQueue().getTotal(),
         900, 0);

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

[incubator-servicecomb-java-chassis] 10/12: JAV-539 & SCB-9 fix pr comment

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 9a2282928b2af9cc2aa79eef283c0b312221f2ae
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Sat Dec 23 18:03:07 2017 +0800

    JAV-539 & SCB-9 fix pr comment
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../src/main/java/io/servicecomb/metrics/core/publish/DataSource.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DataSource.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DataSource.java
index 47f7c83..53ad61e 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DataSource.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DataSource.java
@@ -47,8 +47,8 @@ public interface DataSource {
    * windowTimeIndex = 1 will return result of the setting 2000(2 second)
    *
    * there are three monitor of max,min,total
-   * 0----------1----------2----------            <-time line (second)
-   *   100,200    300,400                         <-value record
+   * 0----------1----------2----------3----------  <-time line (second)
+   *   100,200    300,400                          <-value record
    *
    *                 ↑ getRegistryMetric(0) will return max=200 min=100 total=300
    *                   getRegistryMetric(1) will return max=0 min=0 total=0

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

[incubator-servicecomb-java-chassis] 04/12: JAV-539 & SCB-9 add InvocationMonitorType comment

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 16ffc2bba17cbe43c5e949e8e1b2ab404e1b4886
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Fri Dec 22 10:59:23 2017 +0800

    JAV-539 & SCB-9 add InvocationMonitorType comment
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../java/io/servicecomb/metrics/core/monitor/InvocationMonitorType.java  | 1 +
 1 file changed, 1 insertion(+)

diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitorType.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitorType.java
index 3ef00e3..d0408f7 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitorType.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitorType.java
@@ -18,6 +18,7 @@
 package io.servicecomb.metrics.core.monitor;
 
 public enum InvocationMonitorType {
+  //when InvocationStartedEvent received,InvocationType is unknown
   UNKNOWN,
   CONSUMER,
   PRODUCER

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

[incubator-servicecomb-java-chassis] 12/12: JAV-539 SCB-9 resolve conflict

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 fca6aebe0b524a2d2e51a158b56a4ea90ad66621
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Tue Dec 26 08:54:01 2017 +0800

    JAV-539 SCB-9 resolve conflict
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../servicecomb/common/rest/TestAbstractRestInvocation.java   | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/common/common-rest/src/test/java/io/servicecomb/common/rest/TestAbstractRestInvocation.java b/common/common-rest/src/test/java/io/servicecomb/common/rest/TestAbstractRestInvocation.java
index 278c331..898f0d4 100644
--- a/common/common-rest/src/test/java/io/servicecomb/common/rest/TestAbstractRestInvocation.java
+++ b/common/common-rest/src/test/java/io/servicecomb/common/rest/TestAbstractRestInvocation.java
@@ -43,14 +43,15 @@ import io.servicecomb.core.Const;
 import io.servicecomb.core.Endpoint;
 import io.servicecomb.core.Handler;
 import io.servicecomb.core.Invocation;
-import io.servicecomb.core.metrics.InvocationStartedEvent;
 import io.servicecomb.core.definition.MicroserviceMeta;
 import io.servicecomb.core.definition.MicroserviceMetaManager;
 import io.servicecomb.core.definition.OperationMeta;
 import io.servicecomb.core.definition.SchemaMeta;
 import io.servicecomb.core.executor.ReactiveExecutor;
+import io.servicecomb.core.metrics.InvocationStartedEvent;
 import io.servicecomb.core.provider.consumer.ReferenceConfig;
 import io.servicecomb.foundation.common.utils.JsonUtils;
+import io.servicecomb.foundation.metrics.performance.QueueMetrics;
 import io.servicecomb.foundation.vertx.http.AbstractHttpServletRequest;
 import io.servicecomb.foundation.vertx.http.HttpServletRequestEx;
 import io.servicecomb.foundation.vertx.http.HttpServletResponseEx;
@@ -622,7 +623,7 @@ public class TestAbstractRestInvocation {
     Error error = new Error("run on executor");
     restInvocation = new AbstractRestInvocationForTest() {
       @Override
-      protected void runOnExecutor(InvocationStartedEvent startedEvent) {
+      protected void runOnExecutor(QueueMetrics metricsData, InvocationStartedEvent startedEvent) {
         throw error;
       }
 
@@ -659,7 +660,7 @@ public class TestAbstractRestInvocation {
 
     restInvocation = new AbstractRestInvocationForTest() {
       @Override
-      protected void runOnExecutor(InvocationStartedEvent startedEvent) {
+      protected void runOnExecutor(QueueMetrics metricsData, InvocationStartedEvent startedEvent) {
         throw new Error("run on executor");
       }
 
@@ -695,7 +696,7 @@ public class TestAbstractRestInvocation {
     Holder<Boolean> result = new Holder<>();
     restInvocation = new AbstractRestInvocationForTest() {
       @Override
-      protected void runOnExecutor(InvocationStartedEvent startedEvent) {
+      protected void runOnExecutor(QueueMetrics metricsData, InvocationStartedEvent startedEvent) {
         result.value = true;
       }
     };
@@ -726,7 +727,7 @@ public class TestAbstractRestInvocation {
     restInvocation.requestEx = requestEx;
     restInvocation.restOperationMeta = restOperation;
 
-    restInvocation.runOnExecutor(null,new InvocationStartedEvent("", InvocationType.PRODUCER, System.nanoTime()));
+    restInvocation.runOnExecutor(null, new InvocationStartedEvent("", InvocationType.PRODUCER, System.nanoTime()));
     Assert.assertTrue(result.value);
     Assert.assertSame(invocation, restInvocation.invocation);
   }

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

[incubator-servicecomb-java-chassis] 03/12: JAV-539 & SCB-9 fix pr comment separate Consumer and Producer invocation metric SCB-91 All Monitor can convert to Map with plain-key when polling data

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 6eb8066aa52ab7f9d7cd465bfa1d328dcea4d404
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Thu Dec 21 16:29:05 2017 +0800

    JAV-539 & SCB-9 fix pr comment separate Consumer and Producer invocation metric
    SCB-91 All Monitor can convert to Map with plain-key when polling data
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../{metric/CallMetric.java => MetricsConst.java}  |  29 +--
 .../InvocationStartProcessingEventListener.java    |   1 +
 .../metrics/core/metric/CallMetric.java            |  24 ++-
 ...elMetric.java => ConsumerInvocationMetric.java} |  51 ++---
 .../metrics/core/metric/InstanceMetric.java        |  35 ++-
 .../metrics/core/metric/InvocationMetric.java      |  24 ++-
 ...elMetric.java => ProducerInvocationMetric.java} |  40 ++--
 .../metrics/core/metric/RegistryMetric.java        |  89 ++++++--
 .../metrics/core/metric/TimerMetric.java           |  27 ++-
 .../metrics/core/monitor/CallMonitor.java          |  12 +-
 .../metrics/core/monitor/InvocationMonitor.java    |  75 +++++--
 .../InvocationMonitorType.java}                    |  31 +--
 .../metrics/core/monitor/RegistryMonitor.java      |  12 +-
 .../metrics/core/monitor/TimerMonitor.java         |  15 +-
 .../metrics/core/publish/DefaultDataSource.java    |  20 +-
 .../metrics/core/TestEventAndRunner.java           | 237 ++++++++++++++-------
 .../src/main/resources/microservice.yaml           |   2 +-
 17 files changed, 438 insertions(+), 286 deletions(-)

diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/MetricsConst.java
similarity index 62%
copy from metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java
copy to metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/MetricsConst.java
index 7fa5299..5554796 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/MetricsConst.java
@@ -15,31 +15,14 @@
  * limitations under the License.
  */
 
-package io.servicecomb.metrics.core.metric;
+package io.servicecomb.metrics.core;
 
-public class CallMetric {
-  private final long total;
+public class MetricsConst {
+  public static final String CONSUMER_PREFIX_TEMPLATE = "servicecomb.%s.consumer";
 
-  private final double tps;
+  public static final String PRODUCER_PREFIX_TEMPLATE = "servicecomb.%s.producer";
 
-  public long getTotal() {
-    return total;
-  }
+  public static final String INSTANCE_CONSUMER_PREFIX = String.format(CONSUMER_PREFIX_TEMPLATE, "instance");
 
-  public double getTps() {
-    return tps;
-  }
-
-  public CallMetric() {
-    this(0, 0);
-  }
-
-  public CallMetric(long total, double tps) {
-    this.total = total;
-    this.tps = tps;
-  }
-
-  public CallMetric merge(CallMetric metric) {
-    return new CallMetric(this.total + metric.total, this.tps + metric.tps);
-  }
+  public static final String INSTANCE_PRODUCER_PREFIX = String.format(PRODUCER_PREFIX_TEMPLATE, "instance");
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartProcessingEventListener.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartProcessingEventListener.java
index 1aabd22..d0288f4 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartProcessingEventListener.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartProcessingEventListener.java
@@ -43,6 +43,7 @@ public class InvocationStartProcessingEventListener implements EventListener {
     InvocationMonitor monitor = registryMonitor.getInvocationMonitor(event.getOperationName());
     //TODO:current java chassis unable know invocation type before starting process,so all type WaitInQueue increment(-1) (decrement)
     monitor.getWaitInQueue().increment(-1);
+    monitor.setInvocationMonitorType(event.getInvocationType());
     if (InvocationType.PRODUCER.equals(event.getInvocationType())) {
       monitor.getLifeTimeInQueue().update(event.getInQueueNanoTime());
       monitor.getProducerCall().increment();
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java
index 7fa5299..84a06e4 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java
@@ -17,7 +17,15 @@
 
 package io.servicecomb.metrics.core.metric;
 
+import java.util.HashMap;
+import java.util.Map;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
 public class CallMetric {
+  @JsonIgnore
+  private final String prefix;
+
   private final long total;
 
   private final double tps;
@@ -30,16 +38,24 @@ public class CallMetric {
     return tps;
   }
 
-  public CallMetric() {
-    this(0, 0);
+  public CallMetric(String prefix) {
+    this(prefix, 0, 0);
   }
 
-  public CallMetric(long total, double tps) {
+  public CallMetric(String prefix, long total, double tps) {
+    this.prefix = prefix;
     this.total = total;
     this.tps = tps;
   }
 
   public CallMetric merge(CallMetric metric) {
-    return new CallMetric(this.total + metric.total, this.tps + metric.tps);
+    return new CallMetric(this.prefix, this.total + metric.total, this.tps + metric.tps);
+  }
+
+  public Map<String, Number> toMap() {
+    Map<String, Number> metrics = new HashMap<>();
+    metrics.put(prefix + ".total", total);
+    metrics.put(prefix + ".tps", tps);
+    return metrics;
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ModelMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ConsumerInvocationMetric.java
similarity index 53%
copy from metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ModelMetric.java
copy to metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ConsumerInvocationMetric.java
index 7273171..f0059a3 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ModelMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ConsumerInvocationMetric.java
@@ -17,58 +17,33 @@
 
 package io.servicecomb.metrics.core.metric;
 
-public abstract class ModelMetric {
-  private final long waitInQueue;
-
-  private final TimerMetric lifeTimeInQueue;
-
-  private final TimerMetric executionTime;
+import java.util.HashMap;
+import java.util.Map;
 
+public class ConsumerInvocationMetric extends InvocationMetric {
   private final TimerMetric consumerLatency;
 
-  private final TimerMetric producerLatency;
-
   private final CallMetric consumerCall;
 
-  private final CallMetric producerCall;
-
-  public long getWaitInQueue() {
-    return waitInQueue;
-  }
-
-  public TimerMetric getLifeTimeInQueue() {
-    return lifeTimeInQueue;
-  }
-
-  public TimerMetric getExecutionTime() {
-    return executionTime;
-  }
-
   public TimerMetric getConsumerLatency() {
     return consumerLatency;
   }
 
-  public TimerMetric getProducerLatency() {
-    return producerLatency;
-  }
-
   public CallMetric getConsumerCall() {
     return consumerCall;
   }
 
-  public CallMetric getProducerCall() {
-    return producerCall;
-  }
-
-  public ModelMetric(long waitInQueue,
-      TimerMetric lifeTimeInQueue, TimerMetric executionTime, TimerMetric consumerLatency,
-      TimerMetric producerLatency, CallMetric consumerCall, CallMetric producerCall) {
-    this.waitInQueue = waitInQueue;
-    this.lifeTimeInQueue = lifeTimeInQueue;
-    this.executionTime = executionTime;
+  public ConsumerInvocationMetric(String operationName, String prefix, long waitInQueue,
+      TimerMetric consumerLatency, CallMetric consumerCall) {
+    super(operationName, prefix, waitInQueue);
     this.consumerLatency = consumerLatency;
-    this.producerLatency = producerLatency;
     this.consumerCall = consumerCall;
-    this.producerCall = producerCall;
+  }
+
+  public Map<String, Number> toMap() {
+    Map<String, Number> metrics = new HashMap<>();
+    metrics.putAll(consumerLatency.toMap());
+    metrics.putAll(consumerCall.toMap());
+    return metrics;
   }
 }
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 c3e8fa1..7a934bd 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
@@ -17,18 +17,35 @@
 
 package io.servicecomb.metrics.core.metric;
 
-public class InstanceMetric extends ModelMetric {
+public class InstanceMetric {
+  private final long waitInQueue;
 
-  private final SystemMetric systemMetric;
+  private final ConsumerInvocationMetric consumerMetric;
 
-  public SystemMetric getSystemMetric() {
-    return systemMetric;
+  private final ProducerInvocationMetric producerMetric;
+
+  public long getWaitInQueue() {
+    return waitInQueue;
+  }
+
+  public ConsumerInvocationMetric getConsumerMetric() {
+    return consumerMetric;
+  }
+
+  public ProducerInvocationMetric getProducerMetric() {
+    return producerMetric;
+  }
+
+  public InstanceMetric() {
+    waitInQueue = 0;
+    consumerMetric = null;
+    producerMetric = null;
   }
 
-  public InstanceMetric(long waitInQueue, SystemMetric systemMetric,
-      TimerMetric lifeTimeInQueue, TimerMetric executionTime, TimerMetric consumerLatency,
-      TimerMetric producerLatency) {
-    super(waitInQueue, lifeTimeInQueue, executionTime, consumerLatency, producerLatency);
-    this.systemMetric = systemMetric;
+  public InstanceMetric(long waitInQueue, ConsumerInvocationMetric consumerMetric,
+      ProducerInvocationMetric producerMetric) {
+    this.waitInQueue = waitInQueue;
+    this.consumerMetric = consumerMetric;
+    this.producerMetric = producerMetric;
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java
index e1b5e3e..03c66db 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java
@@ -17,17 +17,31 @@
 
 package io.servicecomb.metrics.core.metric;
 
-public class InvocationMetric extends ModelMetric {
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+public class InvocationMetric {
   private final String operationName;
 
+  @JsonIgnore
+  private final String prefix;
+
+  private final long waitInQueue;
+
   public String getOperationName() {
     return operationName;
   }
 
-  public InvocationMetric(String operationName, long waitInQueue,
-      TimerMetric lifeTimeInQueue, TimerMetric executionTime, TimerMetric consumerLatency,
-      TimerMetric producerLatency, CallMetric consumerCall, CallMetric producerCall) {
-    super(waitInQueue, lifeTimeInQueue, executionTime, consumerLatency, producerLatency, consumerCall, producerCall);
+  public String getPrefix() {
+    return prefix;
+  }
+
+  public long getWaitInQueue() {
+    return waitInQueue;
+  }
+
+  public InvocationMetric(String operationName, String prefix, long waitInQueue) {
     this.operationName = operationName;
+    this.prefix = prefix;
+    this.waitInQueue = waitInQueue;
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ModelMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ProducerInvocationMetric.java
similarity index 70%
rename from metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ModelMetric.java
rename to metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ProducerInvocationMetric.java
index 7273171..4eaa8c3 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ModelMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ProducerInvocationMetric.java
@@ -17,25 +17,18 @@
 
 package io.servicecomb.metrics.core.metric;
 
-public abstract class ModelMetric {
-  private final long waitInQueue;
+import java.util.HashMap;
+import java.util.Map;
 
+public class ProducerInvocationMetric extends InvocationMetric {
   private final TimerMetric lifeTimeInQueue;
 
   private final TimerMetric executionTime;
 
-  private final TimerMetric consumerLatency;
-
   private final TimerMetric producerLatency;
 
-  private final CallMetric consumerCall;
-
   private final CallMetric producerCall;
 
-  public long getWaitInQueue() {
-    return waitInQueue;
-  }
-
   public TimerMetric getLifeTimeInQueue() {
     return lifeTimeInQueue;
   }
@@ -44,31 +37,30 @@ public abstract class ModelMetric {
     return executionTime;
   }
 
-  public TimerMetric getConsumerLatency() {
-    return consumerLatency;
-  }
-
   public TimerMetric getProducerLatency() {
     return producerLatency;
   }
 
-  public CallMetric getConsumerCall() {
-    return consumerCall;
-  }
-
   public CallMetric getProducerCall() {
     return producerCall;
   }
 
-  public ModelMetric(long waitInQueue,
-      TimerMetric lifeTimeInQueue, TimerMetric executionTime, TimerMetric consumerLatency,
-      TimerMetric producerLatency, CallMetric consumerCall, CallMetric producerCall) {
-    this.waitInQueue = waitInQueue;
+  public ProducerInvocationMetric(String operationName, String prefix, long waitInQueue,
+      TimerMetric lifeTimeInQueue, TimerMetric executionTime, TimerMetric producerLatency, CallMetric producerCall) {
+    super(operationName, prefix, waitInQueue);
     this.lifeTimeInQueue = lifeTimeInQueue;
     this.executionTime = executionTime;
-    this.consumerLatency = consumerLatency;
     this.producerLatency = producerLatency;
-    this.consumerCall = consumerCall;
     this.producerCall = producerCall;
   }
+
+  public Map<String, Number> toMap() {
+    Map<String, Number> metrics = new HashMap<>();
+    metrics.put(getPrefix() + ".waitInQueue.count", getWaitInQueue());
+    metrics.putAll(lifeTimeInQueue.toMap());
+    metrics.putAll(executionTime.toMap());
+    metrics.putAll(producerLatency.toMap());
+    metrics.putAll(producerCall.toMap());
+    return metrics;
+  }
 }
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 bf7b5e8..7238f92 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
@@ -17,48 +17,93 @@
 
 package io.servicecomb.metrics.core.metric;
 
+import java.util.HashMap;
 import java.util.Map;
 
-import io.servicecomb.metrics.core.monitor.RegistryMonitor;
+import io.servicecomb.metrics.core.MetricsConst;
 
 public class RegistryMetric {
 
   private final InstanceMetric instanceMetric;
 
-  private final Map<String, InvocationMetric> invocationMetrics;
+  private final Map<String, ConsumerInvocationMetric> consumerMetrics;
+
+  private final Map<String, ProducerInvocationMetric> producerMetrics;
 
   public InstanceMetric getInstanceMetric() {
     return instanceMetric;
   }
 
-  public Map<String, InvocationMetric> getInvocationMetrics() {
-    return invocationMetrics;
+  public Map<String, ConsumerInvocationMetric> getConsumerMetrics() {
+    return consumerMetrics;
+  }
+
+  public Map<String, ProducerInvocationMetric> getProducerMetrics() {
+    return producerMetrics;
   }
 
-  public RegistryMetric(RegistryMonitor registryMonitor, int pollerIndex) {
-    invocationMetrics = registryMonitor.toInvocationMetrics(pollerIndex);
+  public RegistryMetric() {
+    consumerMetrics = new HashMap<>();
+    producerMetrics = new HashMap<>();
+    instanceMetric = new InstanceMetric();
+  }
 
+  public RegistryMetric(Map<String, InvocationMetric> invocationMetrics) {
     //sum instance level metric
-    long waitInQueue = 0;
-    TimerMetric lifeTimeInQueue = new TimerMetric();
-    TimerMetric executionTime = new TimerMetric();
-    TimerMetric consumerLatency = new TimerMetric();
-    TimerMetric producerLatency = new TimerMetric();
+    consumerMetrics = new HashMap<>();
+    producerMetrics = new HashMap<>();
 
-    CallMetric consumerCall = new CallMetric();
-    CallMetric producerCall = new CallMetric();
+    //TODO:current java chassis unable know invocation type before starting process,ProducerInvocation + UnknownTypeInvocation
+    long totalWaitInQueue = 0;
+    long producerWaitInQueue = 0;
+    TimerMetric lifeTimeInQueue = new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".lifeTimeInQueue");
+    TimerMetric executionTime = new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".executionTime");
+    TimerMetric consumerLatency = new TimerMetric(MetricsConst.INSTANCE_CONSUMER_PREFIX + ".consumerLatency");
+    TimerMetric producerLatency = new TimerMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".producerLatency");
+    CallMetric consumerCall = new CallMetric(MetricsConst.INSTANCE_CONSUMER_PREFIX + ".consumerCall");
+    CallMetric producerCall = new CallMetric(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".producerCall");
 
     for (InvocationMetric metric : invocationMetrics.values()) {
-      waitInQueue += metric.getWaitInQueue();
-      lifeTimeInQueue = lifeTimeInQueue.merge(metric.getLifeTimeInQueue());
-      executionTime = executionTime.merge(metric.getExecutionTime());
-      consumerLatency = consumerLatency.merge(metric.getConsumerLatency());
-      producerLatency = producerLatency.merge(metric.getProducerLatency());
-      consumerCall = consumerCall.merge(metric.getConsumerCall());
-      producerCall = producerCall.merge(metric.getProducerCall());
+      if (metric != null) {
+        if (metric instanceof ConsumerInvocationMetric) {
+          ConsumerInvocationMetric consumerMetric = (ConsumerInvocationMetric) metric;
+          consumerLatency = consumerLatency.merge(consumerMetric.getConsumerLatency());
+          consumerCall = consumerCall.merge(consumerMetric.getConsumerCall());
+          consumerMetrics.put(metric.getOperationName(), consumerMetric);
+        } else if (metric instanceof ProducerInvocationMetric) {
+          ProducerInvocationMetric producerMetric = (ProducerInvocationMetric) metric;
+          totalWaitInQueue += producerMetric.getWaitInQueue();
+          producerWaitInQueue += producerMetric.getWaitInQueue();
+          lifeTimeInQueue = lifeTimeInQueue.merge(producerMetric.getLifeTimeInQueue());
+          executionTime = executionTime.merge(producerMetric.getExecutionTime());
+          producerLatency = producerLatency.merge(producerMetric.getProducerLatency());
+          producerCall = producerCall.merge(producerMetric.getProducerCall());
+          producerMetrics.put(metric.getOperationName(), producerMetric);
+        } else {
+          totalWaitInQueue += metric.getWaitInQueue();
+        }
+      }
     }
 
-    instanceMetric = new InstanceMetric(waitInQueue, lifeTimeInQueue, executionTime, consumerLatency, producerLatency,
-        consumerCall, producerCall);
+    instanceMetric = new InstanceMetric(totalWaitInQueue,
+        new ConsumerInvocationMetric("instance", MetricsConst.INSTANCE_CONSUMER_PREFIX,
+            producerWaitInQueue, consumerLatency, consumerCall),
+        new ProducerInvocationMetric("instance", MetricsConst.INSTANCE_PRODUCER_PREFIX,
+            totalWaitInQueue, lifeTimeInQueue, executionTime, producerLatency, producerCall));
+  }
+
+  public Map<String, Number> toMap() {
+    Map<String, Number> metrics = new HashMap<>();
+    metrics.putAll(instanceMetric.getConsumerMetric().toMap());
+    metrics.putAll(instanceMetric.getProducerMetric().toMap());
+    //will override waitInQueue.count value
+    metrics.put(MetricsConst.INSTANCE_PRODUCER_PREFIX + ".waitInQueue.count", instanceMetric.getWaitInQueue());
+    for (ConsumerInvocationMetric metric : consumerMetrics.values()) {
+      metrics.putAll(metric.toMap());
+    }
+    for (ProducerInvocationMetric metric : producerMetrics.values()) {
+      metrics.putAll(metric.toMap());
+    }
+    return metrics;
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java
index 40f82ff..d2587cf 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java
@@ -17,7 +17,15 @@
 
 package io.servicecomb.metrics.core.metric;
 
+import java.util.HashMap;
+import java.util.Map;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
 public class TimerMetric {
+  @JsonIgnore
+  private final String prefix;
+
   private final long total;
 
   private final long count;
@@ -48,11 +56,12 @@ public class TimerMetric {
     return max;
   }
 
-  public TimerMetric() {
-    this(0, 0, 0, 0);
+  public TimerMetric(String prefix) {
+    this(prefix, 0, 0, 0, 0);
   }
 
-  public TimerMetric(long total, long count, long min, long max) {
+  public TimerMetric(String prefix, long total, long count, long min, long max) {
+    this.prefix = prefix;
     this.total = total;
     this.count = count;
     if (count != 0) {
@@ -65,7 +74,7 @@ public class TimerMetric {
   }
 
   public TimerMetric merge(TimerMetric metric) {
-    return new TimerMetric(this.total + metric.total, this.count + metric.count,
+    return new TimerMetric(this.prefix, this.total + metric.total, this.count + metric.count,
         getMin(this.min, metric.min), getMax(this.max, metric.max));
   }
 
@@ -76,4 +85,14 @@ public class TimerMetric {
   private long getMax(long value1, long value2) {
     return value2 > value1 ? value2 : value1;
   }
+
+  public Map<String, Number> toMap() {
+    Map<String, Number> metrics = new HashMap<>();
+    metrics.put(prefix + ".total", total);
+    metrics.put(prefix + ".count", count);
+    metrics.put(prefix + ".average", average);
+    metrics.put(prefix + ".max", max);
+    metrics.put(prefix + ".min", min);
+    return metrics;
+  }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java
index ec38caf..259a604 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java
@@ -24,13 +24,16 @@ import com.netflix.servo.monitor.StepCounter;
 import io.servicecomb.metrics.core.metric.CallMetric;
 
 public class CallMonitor {
+  private final String prefix;
+
   private final BasicCounter total;
 
   private final StepCounter tps;
 
-  public CallMonitor(String name) {
-    this.total = new BasicCounter(MonitorConfig.builder(name + ".total").build());
-    this.tps = new StepCounter(MonitorConfig.builder(name + ".tps").build());
+  public CallMonitor(String prefix) {
+    this.prefix = prefix;
+    this.total = new BasicCounter(MonitorConfig.builder(prefix + ".total").build());
+    this.tps = new StepCounter(MonitorConfig.builder(prefix + ".tps").build());
   }
 
   public void increment() {
@@ -39,6 +42,7 @@ public class CallMonitor {
   }
 
   public CallMetric toCallMetric(int pollerIndex) {
-    return new CallMetric(total.getValue(pollerIndex).longValue(), tps.getValue(pollerIndex).doubleValue());
+    return new CallMetric(this.prefix, total.getValue(pollerIndex).longValue(),
+        tps.getValue(pollerIndex).doubleValue());
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitor.java
index d3588f5..e11ee89 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitor.java
@@ -20,31 +20,49 @@ package io.servicecomb.metrics.core.monitor;
 import com.netflix.servo.monitor.BasicCounter;
 import com.netflix.servo.monitor.MonitorConfig;
 
+import io.servicecomb.metrics.core.MetricsConst;
+import io.servicecomb.metrics.core.metric.ConsumerInvocationMetric;
 import io.servicecomb.metrics.core.metric.InvocationMetric;
+import io.servicecomb.metrics.core.metric.ProducerInvocationMetric;
+import io.servicecomb.swagger.invocation.InvocationType;
 
 public class InvocationMonitor {
   private final String operationName;
 
+  private final String consumerPrefix;
+
+  private final String producerPrefix;
+
   private final BasicCounter waitInQueue;
 
   private final TimerMonitor lifeTimeInQueue;
 
   private final TimerMonitor executionTime;
 
+  private final TimerMonitor producerLatency;
+
   private final TimerMonitor consumerLatency;
 
-  private final TimerMonitor producerLatency;
+  private final CallMonitor producerCall;
 
   private final CallMonitor consumerCall;
 
-  private final CallMonitor producerCall;
+  private InvocationMonitorType invocationMonitorType = InvocationMonitorType.UNKNOWN;
+
+  //TODO:current java chassis unable know invocation type before starting process,so we need set it,can improve later
+  public void setInvocationMonitorType(InvocationType invocationType) {
+    if (InvocationMonitorType.UNKNOWN.equals(this.invocationMonitorType)) {
+      this.invocationMonitorType = invocationType == InvocationType.PRODUCER ?
+          InvocationMonitorType.PRODUCER : InvocationMonitorType.CONSUMER;
+    }
+  }
 
   public String getOperationName() {
     return operationName;
   }
 
-  public BasicCounter getWaitInQueue() {
-    return waitInQueue;
+  public TimerMonitor getConsumerLatency() {
+    return consumerLatency;
   }
 
   public TimerMonitor getLifeTimeInQueue() {
@@ -55,10 +73,6 @@ public class InvocationMonitor {
     return executionTime;
   }
 
-  public TimerMonitor getConsumerLatency() {
-    return consumerLatency;
-  }
-
   public TimerMonitor getProducerLatency() {
     return producerLatency;
   }
@@ -71,25 +85,40 @@ public class InvocationMonitor {
     return producerCall;
   }
 
+  public BasicCounter getWaitInQueue() {
+    return waitInQueue;
+  }
+
   public InvocationMonitor(String operationName) {
     this.operationName = operationName;
-    this.waitInQueue = new BasicCounter(MonitorConfig.builder(operationName + ".waitInQueue.count").build());
-    this.lifeTimeInQueue = new TimerMonitor(operationName + ".lifeTimeInQueue");
-    this.executionTime = new TimerMonitor(operationName + ".executionTime");
-    this.consumerLatency = new TimerMonitor(operationName + ".consumerLatency");
-    this.producerLatency = new TimerMonitor(operationName + ".producerLatency");
-
-    this.consumerCall = new CallMonitor(operationName + ".consumerCall");
-    this.producerCall = new CallMonitor(operationName + ".producerCall");
+    this.consumerPrefix = String.format(MetricsConst.CONSUMER_PREFIX_TEMPLATE, operationName);
+    this.producerPrefix = String.format(MetricsConst.PRODUCER_PREFIX_TEMPLATE, operationName);
+    this.waitInQueue = new BasicCounter(MonitorConfig.builder(producerPrefix + ".waitInQueue.count").build());
+
+    this.consumerLatency = new TimerMonitor(consumerPrefix + ".consumerLatency");
+    this.consumerCall = new CallMonitor(consumerPrefix + ".consumerCall");
+
+    this.lifeTimeInQueue = new TimerMonitor(producerPrefix + ".lifeTimeInQueue");
+    this.executionTime = new TimerMonitor(producerPrefix + ".executionTime");
+    this.producerLatency = new TimerMonitor(producerPrefix + ".producerLatency");
+    this.producerCall = new CallMonitor(producerPrefix + ".producerCall");
   }
 
   public InvocationMetric toInvocationMetric(int pollerIndex) {
-    return new InvocationMetric(this.getOperationName(), this.getWaitInQueue().getValue(pollerIndex).longValue(),
-        this.lifeTimeInQueue.toTimerMetric(pollerIndex),
-        this.executionTime.toTimerMetric(pollerIndex),
-        this.consumerLatency.toTimerMetric(pollerIndex),
-        this.producerLatency.toTimerMetric(pollerIndex),
-        this.consumerCall.toCallMetric(pollerIndex),
-        this.producerCall.toCallMetric(pollerIndex));
+    InvocationMetric metric;
+    long queueCount = waitInQueue.getValue(pollerIndex).longValue();
+    if (invocationMonitorType.equals(InvocationMonitorType.PRODUCER)) {
+      metric = new ProducerInvocationMetric(operationName, producerPrefix, queueCount,
+          lifeTimeInQueue.toTimerMetric(pollerIndex),
+          executionTime.toTimerMetric(pollerIndex),
+          producerLatency.toTimerMetric(pollerIndex),
+          producerCall.toCallMetric(pollerIndex));
+    } else if (invocationMonitorType.equals(InvocationMonitorType.CONSUMER)) {
+      metric = new ConsumerInvocationMetric(operationName, consumerPrefix, queueCount,
+          consumerLatency.toTimerMetric(pollerIndex), consumerCall.toCallMetric(pollerIndex));
+    } else {
+      metric = new InvocationMetric(operationName, consumerPrefix, queueCount);
+    }
+    return metric;
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitorType.java
similarity index 62%
copy from metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java
copy to metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitorType.java
index 7fa5299..3ef00e3 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitorType.java
@@ -15,31 +15,10 @@
  * limitations under the License.
  */
 
-package io.servicecomb.metrics.core.metric;
+package io.servicecomb.metrics.core.monitor;
 
-public class CallMetric {
-  private final long total;
-
-  private final double tps;
-
-  public long getTotal() {
-    return total;
-  }
-
-  public double getTps() {
-    return tps;
-  }
-
-  public CallMetric() {
-    this(0, 0);
-  }
-
-  public CallMetric(long total, double tps) {
-    this.total = total;
-    this.tps = tps;
-  }
-
-  public CallMetric merge(CallMetric metric) {
-    return new CallMetric(this.total + metric.total, this.tps + metric.tps);
-  }
+public enum InvocationMonitorType {
+  UNKNOWN,
+  CONSUMER,
+  PRODUCER
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/RegistryMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/RegistryMonitor.java
index 75ffc33..fd2fc53 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/RegistryMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/RegistryMonitor.java
@@ -17,13 +17,14 @@
 
 package io.servicecomb.metrics.core.monitor;
 
+import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.stream.Collectors;
 
 import org.springframework.stereotype.Component;
 
 import io.servicecomb.metrics.core.metric.InvocationMetric;
+import io.servicecomb.metrics.core.metric.RegistryMetric;
 
 @Component
 public class RegistryMonitor {
@@ -38,8 +39,11 @@ public class RegistryMonitor {
     return invocationMonitors.computeIfAbsent(operationName, i -> new InvocationMonitor(operationName));
   }
 
-  public Map<String, InvocationMetric> toInvocationMetrics(int pollerIndex) {
-    return invocationMonitors.values().stream().collect(Collectors.toMap(InvocationMonitor::getOperationName,
-        monitor -> monitor.toInvocationMetric(pollerIndex)));
+  public RegistryMetric toRegistryMetric(int pollerIndex) {
+    Map<String, InvocationMetric> invocationMetrics = new HashMap<>();
+    for (InvocationMonitor monitor : invocationMonitors.values()) {
+      invocationMetrics.put(monitor.getOperationName(), monitor.toInvocationMetric(pollerIndex));
+    }
+    return new RegistryMetric(invocationMetrics);
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/TimerMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/TimerMonitor.java
index 8d7e276..a2120e3 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/TimerMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/TimerMonitor.java
@@ -25,6 +25,8 @@ import com.netflix.servo.monitor.StepCounter;
 import io.servicecomb.metrics.core.metric.TimerMetric;
 
 public class TimerMonitor {
+  private final String prefix;
+
   private final StepCounter total;
 
   private final StepCounter count;
@@ -42,15 +44,16 @@ public class TimerMonitor {
     }
   }
 
-  public TimerMonitor(String name) {
-    total = new StepCounter(MonitorConfig.builder(name + ".total").build());
-    count = new StepCounter(MonitorConfig.builder(name + ".count").build());
-    min = new MinGauge(MonitorConfig.builder(name + ".min").build());
-    max = new MaxGauge(MonitorConfig.builder(name + ".max").build());
+  public TimerMonitor(String prefix) {
+    this.prefix = prefix;
+    total = new StepCounter(MonitorConfig.builder(prefix + ".total").build());
+    count = new StepCounter(MonitorConfig.builder(prefix + ".count").build());
+    min = new MinGauge(MonitorConfig.builder(prefix + ".min").build());
+    max = new MaxGauge(MonitorConfig.builder(prefix + ".max").build());
   }
 
   public TimerMetric toTimerMetric(int pollerIndex) {
-    return new TimerMetric(total.getCount(pollerIndex), count.getCount(pollerIndex),
+    return new TimerMetric(this.prefix, total.getCount(pollerIndex), count.getCount(pollerIndex),
         min.getValue(pollerIndex), max.getValue(pollerIndex));
   }
 }
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 70ddb18..6aa0420 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,7 +31,6 @@ 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;
 
@@ -45,19 +44,15 @@ public class DefaultDataSource implements DataSource {
 
   private final RegistryMonitor registryMonitor;
 
-  private final SystemResource systemResource;
-
   private final Map<Integer, RegistryMetric> registryMetrics;
 
   @Autowired
-  public DefaultDataSource(SystemResource systemResource, RegistryMonitor registryMonitor) {
-    this(systemResource, registryMonitor,
-        DynamicPropertyFactory.getInstance().getStringProperty(METRICS_POLLING_TIME, "10000").get());
+  public DefaultDataSource(RegistryMonitor registryMonitor) {
+    this(registryMonitor, DynamicPropertyFactory.getInstance().getStringProperty(METRICS_POLLING_TIME, "10000").get());
   }
 
-  public DefaultDataSource(SystemResource systemResource, RegistryMonitor registryMonitor, String pollingSettings) {
+  public DefaultDataSource(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();
@@ -68,10 +63,11 @@ public class DefaultDataSource implements DataSource {
     for (int index = 0; index < intervals.size(); index++) {
       int finalIndex = index;
       long finalInterval = intervals.get(finalIndex) < minPollingTime ? minPollingTime : intervals.get(finalIndex);
+      long pollerInterval = (long) (finalInterval * 0.5);
       final Runnable poller = () -> reloadRegistryMetric(finalIndex);
       Executors.newScheduledThreadPool(1)
           //for step counter correct work we need poll in time ,otherwise current step will return Datapoint.UNKNOWN (missing last sample)
-          .scheduleWithFixedDelay(poller, 0, (long) (finalInterval * 0.5), MILLISECONDS);
+          .scheduleWithFixedDelay(poller, pollerInterval, pollerInterval, MILLISECONDS);
       appliedIntervals.add(finalInterval);
     }
     this.appliedPollingIntervals = appliedIntervals;
@@ -79,7 +75,7 @@ public class DefaultDataSource implements DataSource {
 
   @Override
   public RegistryMetric getRegistryMetric(int pollerIndex) {
-    return registryMetrics.getOrDefault(pollerIndex, new RegistryMetric(systemResource, registryMonitor, pollerIndex));
+    return registryMetrics.getOrDefault(pollerIndex, new RegistryMetric());
   }
 
   @Override
@@ -87,7 +83,7 @@ public class DefaultDataSource implements DataSource {
     return appliedPollingIntervals;
   }
 
-  private void reloadRegistryMetric(Integer pollingIndex) {
-    registryMetrics.put(pollingIndex, new RegistryMetric(systemResource, registryMonitor, pollingIndex));
+  private void reloadRegistryMetric(Integer pollerIndex) {
+    registryMetrics.put(pollerIndex, registryMonitor.toRegistryMetric(pollerIndex));
   }
 }
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 da7f02e..06d2b77 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,6 +17,8 @@
 
 package io.servicecomb.metrics.core;
 
+import java.util.List;
+import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
 import org.junit.Assert;
@@ -39,8 +41,13 @@ public class TestEventAndRunner {
     RegistryMonitor monitor = new RegistryMonitor();
     DefaultDataSource dataSource = new DefaultDataSource(monitor, "2000");
 
+    List<Long> intervals = dataSource.getAppliedPollingIntervals();
+    Assert.assertEquals(intervals.size(), 1);
+    Assert.assertEquals(intervals.get(0).intValue(), 2000);
+
     DefaultEventListenerManager manager = new DefaultEventListenerManager(monitor);
 
+    //fun1 is a PRODUCER invocation call twice and all is completed
     EventUtils.triggerEvent(new InvocationStartedEvent("fun1", System.nanoTime()));
     EventUtils.triggerEvent(
         new InvocationStartProcessingEvent("fun1", InvocationType.PRODUCER, System.nanoTime(),
@@ -57,96 +64,164 @@ public class TestEventAndRunner {
         .triggerEvent(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER, System.nanoTime(),
             TimeUnit.MILLISECONDS.toNanos(400), TimeUnit.MILLISECONDS.toNanos(700)));
 
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun12", System.nanoTime()));
+    //fun3 is a PRODUCER invocation call uncompleted
+    EventUtils.triggerEvent(new InvocationStartedEvent("fun3", System.nanoTime()));
     EventUtils.triggerEvent(
-        new InvocationStartProcessingEvent("fun12", InvocationType.PRODUCER, System.nanoTime(),
+        new InvocationStartProcessingEvent("fun3", InvocationType.PRODUCER, System.nanoTime(),
             TimeUnit.MILLISECONDS.toNanos(500)));
+
+    //fun2 is a CONSUMER invocation call once and completed
+    EventUtils.triggerEvent(new InvocationStartedEvent("fun2", System.nanoTime()));
+    EventUtils.triggerEvent(
+        new InvocationStartProcessingEvent("fun2", InvocationType.CONSUMER, System.nanoTime(),
+            TimeUnit.MILLISECONDS.toNanos(100)));
     EventUtils
-        .triggerEvent(new InvocationFinishedEvent("fun12", InvocationType.PRODUCER, System.nanoTime(),
-            TimeUnit.MILLISECONDS.toNanos(600), TimeUnit.MILLISECONDS.toNanos(1100)));
+        .triggerEvent(new InvocationFinishedEvent("fun2", InvocationType.CONSUMER, System.nanoTime(),
+            TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300)));
 
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun11", System.nanoTime()));
+    //fun4 is a invocation call only started and no processing start and finished
+    EventUtils.triggerEvent(new InvocationStartedEvent("fun4", System.nanoTime()));
 
     Thread.sleep(2000);
 
     RegistryMetric model = dataSource.getRegistryMetric(0);
 
-    Assert.assertEquals(model.getInvocationMetrics().get("fun1").getWaitInQueue(), 0);
-    Assert.assertEquals(model.getInvocationMetrics().get("fun11").getWaitInQueue(), 1);
+    //check InstanceMetric
     Assert.assertEquals(model.getInstanceMetric().getWaitInQueue(), 1);
-
-    Assert.assertEquals(model.getInvocationMetrics().get("fun1").getLifeTimeInQueue().getMin(),
-        TimeUnit.MILLISECONDS.toNanos(100),
-        0);
-    Assert.assertEquals(model.getInvocationMetrics().get("fun1").getLifeTimeInQueue().getMax(),
-        TimeUnit.MILLISECONDS.toNanos(300),
-        0);
-    Assert.assertEquals(
-        model.getInvocationMetrics().get("fun1").getLifeTimeInQueue().getAverage(), TimeUnit.MILLISECONDS.toNanos(200),
-        0);
-    Assert.assertEquals(model.getInstanceMetric().getLifeTimeInQueue().getMin(), TimeUnit.MILLISECONDS.toNanos(100), 0);
-    Assert.assertEquals(model.getInstanceMetric().getLifeTimeInQueue().getMax(), TimeUnit.MILLISECONDS.toNanos(500), 0);
-    Assert.assertEquals(model.getInstanceMetric().getLifeTimeInQueue().getAverage(), TimeUnit.MILLISECONDS.toNanos(300),
-        0);
-
-    Assert
-        .assertEquals(model.getInvocationMetrics().get("fun1").getExecutionTime().getMin(),
-            TimeUnit.MILLISECONDS.toNanos(200), 0);
-    Assert
-        .assertEquals(model.getInvocationMetrics().get("fun1").getExecutionTime().getMax(),
-            TimeUnit.MILLISECONDS.toNanos(400), 0);
-    Assert
-        .assertEquals(model.getInvocationMetrics().get("fun1").getExecutionTime().getAverage(),
-            TimeUnit.MILLISECONDS.toNanos(300),
-            0);
-    Assert.assertEquals(model.getInstanceMetric().getExecutionTime().getMin(), TimeUnit.MILLISECONDS.toNanos(200), 0);
-    Assert.assertEquals(model.getInstanceMetric().getExecutionTime().getMax(), TimeUnit.MILLISECONDS.toNanos(600), 0);
-    Assert
-        .assertEquals(model.getInstanceMetric().getExecutionTime().getAverage(), TimeUnit.MILLISECONDS.toNanos(400), 0);
-
-    Assert
-        .assertEquals(model.getInvocationMetrics().get("fun1").getProducerLatency().getMin(),
-            TimeUnit.MILLISECONDS.toNanos(300), 0);
-    Assert
-        .assertEquals(model.getInvocationMetrics().get("fun1").getProducerLatency().getMax(),
-            TimeUnit.MILLISECONDS.toNanos(700), 0);
-    Assert
-        .assertEquals(model.getInvocationMetrics().get("fun1").getProducerLatency().getAverage(),
-            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);
-
-    Assert
-        .assertEquals(model.getInvocationMetrics().get("fun1").getConsumerLatency().getMin(),
-            TimeUnit.MILLISECONDS.toNanos(0), 0);
-    Assert
-        .assertEquals(model.getInvocationMetrics().get("fun1").getConsumerLatency().getMax(),
-            TimeUnit.MILLISECONDS.toNanos(0), 0);
-    Assert
-        .assertEquals(model.getInvocationMetrics().get("fun1").getConsumerLatency().getAverage(),
-            TimeUnit.MILLISECONDS.toNanos(0),
-            0);
-    Assert.assertEquals(model.getInstanceMetric().getConsumerLatency().getMin(), TimeUnit.MILLISECONDS.toNanos(0), 0);
-    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.getInvocationMetrics().get("fun1").getConsumerCall().getTotal(), 0, 0);
-    Assert.assertEquals(model.getInvocationMetrics().get("fun1").getConsumerCall().getTps(), 0, 0);
-    Assert.assertEquals(model.getInvocationMetrics().get("fun1").getProducerCall().getTotal(), 2, 0);
-    Assert.assertEquals(model.getInvocationMetrics().get("fun1").getProducerCall().getTps(), 1.0, 0);
-    Assert.assertEquals(model.getInvocationMetrics().get("fun12").getConsumerCall().getTotal(), 0, 0);
-    Assert.assertEquals(model.getInvocationMetrics().get("fun12").getConsumerCall().getTps(), 0, 0);
-    Assert.assertEquals(model.getInvocationMetrics().get("fun12").getProducerCall().getTotal(), 1, 0);
-    Assert.assertEquals(model.getInvocationMetrics().get("fun12").getProducerCall().getTps(), 0.5, 0);
-    Assert.assertEquals(model.getInstanceMetric().getConsumerCall().getTotal(), 0, 0);
-    Assert.assertEquals(model.getInstanceMetric().getConsumerCall().getTps(), 0, 0);
-    Assert.assertEquals(model.getInstanceMetric().getProducerCall().getTotal(), 3, 0);
-    Assert.assertEquals(model.getInstanceMetric().getProducerCall().getTps(), 1.5, 0);
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getWaitInQueue(), 1);
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getLifeTimeInQueue().getCount(), 3);
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getLifeTimeInQueue().getTotal(),
+        TimeUnit.MILLISECONDS.toNanos(900));
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getLifeTimeInQueue().getAverage(),
+        TimeUnit.MILLISECONDS.toNanos(300), 0);
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getLifeTimeInQueue().getMax(),
+        TimeUnit.MILLISECONDS.toNanos(500));
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getLifeTimeInQueue().getMin(),
+        TimeUnit.MILLISECONDS.toNanos(100));
+
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getExecutionTime().getCount(), 2);
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getExecutionTime().getTotal(),
+        TimeUnit.MILLISECONDS.toNanos(600));
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getExecutionTime().getAverage(),
+        TimeUnit.MILLISECONDS.toNanos(300), 0);
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getExecutionTime().getMax(),
+        TimeUnit.MILLISECONDS.toNanos(400));
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getExecutionTime().getMin(),
+        TimeUnit.MILLISECONDS.toNanos(200));
+
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerLatency().getCount(), 2);
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerLatency().getTotal(),
+        TimeUnit.MILLISECONDS.toNanos(1000));
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerLatency().getAverage(),
+        TimeUnit.MILLISECONDS.toNanos(500), 0);
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerLatency().getMax(),
+        TimeUnit.MILLISECONDS.toNanos(700));
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerLatency().getMin(),
+        TimeUnit.MILLISECONDS.toNanos(300));
+
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerCall().getTps(), 1.5, 0);
+    Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerCall().getTotal(), 3);
+
+    Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerLatency().getCount(), 1);
+    Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerLatency().getTotal(),
+        TimeUnit.MILLISECONDS.toNanos(300));
+    Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerLatency().getAverage(),
+        TimeUnit.MILLISECONDS.toNanos(300), 0);
+    Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerLatency().getMax(),
+        TimeUnit.MILLISECONDS.toNanos(300));
+    Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerLatency().getMin(),
+        TimeUnit.MILLISECONDS.toNanos(300));
+
+    Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerCall().getTps(), 0.5, 0);
+    Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerCall().getTotal(), 1);
+
+    //check ProducerMetrics
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getWaitInQueue(), 0);
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getLifeTimeInQueue().getCount(), 2);
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getLifeTimeInQueue().getTotal(),
+        TimeUnit.MILLISECONDS.toNanos(400));
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getLifeTimeInQueue().getAverage(),
+        TimeUnit.MILLISECONDS.toNanos(200), 0);
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getLifeTimeInQueue().getMax(),
+        TimeUnit.MILLISECONDS.toNanos(300));
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getLifeTimeInQueue().getMin(),
+        TimeUnit.MILLISECONDS.toNanos(100));
+
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getExecutionTime().getCount(), 2);
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getExecutionTime().getTotal(),
+        TimeUnit.MILLISECONDS.toNanos(600));
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getExecutionTime().getAverage(),
+        TimeUnit.MILLISECONDS.toNanos(300), 0);
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getExecutionTime().getMax(),
+        TimeUnit.MILLISECONDS.toNanos(400));
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getExecutionTime().getMin(),
+        TimeUnit.MILLISECONDS.toNanos(200));
+
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerLatency().getCount(), 2);
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerLatency().getTotal(),
+        TimeUnit.MILLISECONDS.toNanos(1000));
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerLatency().getAverage(),
+        TimeUnit.MILLISECONDS.toNanos(500), 0);
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerLatency().getMax(),
+        TimeUnit.MILLISECONDS.toNanos(700));
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerLatency().getMin(),
+        TimeUnit.MILLISECONDS.toNanos(300));
+
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerCall().getTps(), 1, 0);
+    Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerCall().getTotal(), 2);
+
+    //fun3
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getWaitInQueue(), 0);
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getLifeTimeInQueue().getCount(), 1);
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getLifeTimeInQueue().getTotal(),
+        TimeUnit.MILLISECONDS.toNanos(500));
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getLifeTimeInQueue().getAverage(),
+        TimeUnit.MILLISECONDS.toNanos(500), 0);
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getLifeTimeInQueue().getMax(),
+        TimeUnit.MILLISECONDS.toNanos(500));
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getLifeTimeInQueue().getMin(),
+        TimeUnit.MILLISECONDS.toNanos(500));
+
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getExecutionTime().getCount(), 0);
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getExecutionTime().getTotal(),
+        TimeUnit.MILLISECONDS.toNanos(0));
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getExecutionTime().getAverage(),
+        TimeUnit.MILLISECONDS.toNanos(0), 0);
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getExecutionTime().getMax(),
+        TimeUnit.MILLISECONDS.toNanos(0));
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getExecutionTime().getMin(),
+        TimeUnit.MILLISECONDS.toNanos(0));
+
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerLatency().getCount(), 0);
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerLatency().getTotal(),
+        TimeUnit.MILLISECONDS.toNanos(0));
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerLatency().getAverage(),
+        TimeUnit.MILLISECONDS.toNanos(0), 0);
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerLatency().getMax(),
+        TimeUnit.MILLISECONDS.toNanos(0));
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerLatency().getMin(),
+        TimeUnit.MILLISECONDS.toNanos(0));
+
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerCall().getTps(), 0.5, 0);
+    Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerCall().getTotal(), 1);
+
+    //check ConsumerMetrics
+    //no need
+    Assert.assertEquals(model.getConsumerMetrics().get("fun2").getWaitInQueue(), 0);
+    Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerLatency().getCount(), 1);
+    Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerLatency().getTotal(),
+        TimeUnit.MILLISECONDS.toNanos(300));
+    Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerLatency().getAverage(),
+        TimeUnit.MILLISECONDS.toNanos(300), 0);
+    Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerLatency().getMax(),
+        TimeUnit.MILLISECONDS.toNanos(300));
+    Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerLatency().getMin(),
+        TimeUnit.MILLISECONDS.toNanos(300));
+
+    Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerCall().getTps(), 0.5, 0);
+    Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerCall().getTotal(), 1);
+
+    Map<String, Number> metrics = model.toMap();
+    Assert.assertEquals(metrics.size(), 68);
   }
 }
diff --git a/metrics/metrics-sample/metrics-performance-test/src/main/resources/microservice.yaml b/metrics/metrics-sample/metrics-performance-test/src/main/resources/microservice.yaml
index 664614c..52596aa 100644
--- a/metrics/metrics-sample/metrics-performance-test/src/main/resources/microservice.yaml
+++ b/metrics/metrics-sample/metrics-performance-test/src/main/resources/microservice.yaml
@@ -32,5 +32,5 @@ servicecomb:
   metrics:
     #polling setting
     polling:
-      #Support Muti Polling Time (MILLISECONDS) like 10000,60000 (10s and 60s)
+      #Support Muti-Polling Time (MILLISECONDS) like 10000,60000 (10s and 60s), Use pollerIndex make selection,start from 0
       time: 10000
\ No newline at end of file

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

[incubator-servicecomb-java-chassis] 06/12: JAV-539 & SCB-9 change time-related output from nanosecond to millisecond

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 1dbd8bde0ea99defa63a5358409f86620d301f29
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Sat Dec 23 09:51:32 2017 +0800

    JAV-539 & SCB-9 change time-related output from nanosecond to millisecond
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../metrics/core/metric/TimerMetric.java           | 20 ++---
 .../metrics/core/monitor/BasicMonitor.java         |  6 ++
 .../metrics/core/monitor/TimerMonitor.java         |  9 ++-
 .../metrics/core/TestEventAndRunner.java           | 88 +++++++++++-----------
 4 files changed, 66 insertions(+), 57 deletions(-)

diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java
index d2587cf..7212806 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java
@@ -26,17 +26,17 @@ public class TimerMetric {
   @JsonIgnore
   private final String prefix;
 
-  private final long total;
+  private final double total;
 
   private final long count;
 
   private final double average;
 
-  private final long min;
+  private final double min;
 
-  private final long max;
+  private final double max;
 
-  public long getTotal() {
+  public double getTotal() {
     return total;
   }
 
@@ -48,11 +48,11 @@ public class TimerMetric {
     return average;
   }
 
-  public long getMin() {
+  public double getMin() {
     return min;
   }
 
-  public long getMax() {
+  public double getMax() {
     return max;
   }
 
@@ -60,12 +60,12 @@ public class TimerMetric {
     this(prefix, 0, 0, 0, 0);
   }
 
-  public TimerMetric(String prefix, long total, long count, long min, long max) {
+  public TimerMetric(String prefix, double total, long count, double min, double max) {
     this.prefix = prefix;
     this.total = total;
     this.count = count;
     if (count != 0) {
-      this.average = (double) total / (double) count;
+      this.average = total / (double) count;
     } else {
       this.average = 0;
     }
@@ -78,11 +78,11 @@ public class TimerMetric {
         getMin(this.min, metric.min), getMax(this.max, metric.max));
   }
 
-  private long getMin(long value1, long value2) {
+  private double getMin(double value1, double value2) {
     return value1 == 0 || (value2 != 0 && value2 < value1) ? value2 : value1;
   }
 
-  private long getMax(long value1, long value2) {
+  private double getMax(double value1, double value2) {
     return value2 > value1 ? value2 : value1;
   }
 
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/BasicMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/BasicMonitor.java
index 69227ac..6045d16 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/BasicMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/BasicMonitor.java
@@ -30,4 +30,10 @@ public class BasicMonitor {
   public long adjustValue(long value) {
     return value < 0 ? 0 : value;
   }
+
+  //Counting use System.nano get more precise time
+  //so we need change unit to millisecond when ouput
+  public double convertNanosecondToMillisecond(long nanoValue){
+    return nanoValue * 0.000001;
+  }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/TimerMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/TimerMonitor.java
index a1aec71..9917b5e 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/TimerMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/TimerMonitor.java
@@ -27,12 +27,15 @@ import io.servicecomb.metrics.core.metric.TimerMetric;
 public class TimerMonitor extends BasicMonitor {
   private final String prefix;
 
+  //nanosecond sum
   private final StepCounter total;
 
   private final StepCounter count;
 
+  //nanosecond min
   private final MinGauge min;
 
+  //nanosecond max
   private final MaxGauge max;
 
   public void update(long value) {
@@ -54,9 +57,9 @@ public class TimerMonitor extends BasicMonitor {
 
   public TimerMetric toTimerMetric(int windowTimeIndex) {
     return new TimerMetric(this.prefix,
-        this.adjustValue(total.getCount(windowTimeIndex)),
+        this.convertNanosecondToMillisecond(this.adjustValue(total.getCount(windowTimeIndex))),
         this.adjustValue(count.getCount(windowTimeIndex)),
-        this.adjustValue(min.getValue(windowTimeIndex)),
-        this.adjustValue(max.getValue(windowTimeIndex)));
+        this.convertNanosecondToMillisecond(this.adjustValue(min.getValue(windowTimeIndex))),
+        this.convertNanosecondToMillisecond(this.adjustValue(max.getValue(windowTimeIndex))));
   }
 }
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 9b3a194..ae518fd 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
@@ -92,46 +92,46 @@ public class TestEventAndRunner {
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getWaitInQueue(), 1);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getLifeTimeInQueue().getCount(), 3);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getLifeTimeInQueue().getTotal(),
-        TimeUnit.MILLISECONDS.toNanos(900));
+        900, 0);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getLifeTimeInQueue().getAverage(),
-        TimeUnit.MILLISECONDS.toNanos(300), 0);
+        300, 0);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getLifeTimeInQueue().getMax(),
-        TimeUnit.MILLISECONDS.toNanos(500));
+        500, 0);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getLifeTimeInQueue().getMin(),
-        TimeUnit.MILLISECONDS.toNanos(100));
+        100, 0);
 
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getExecutionTime().getCount(), 2);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getExecutionTime().getTotal(),
-        TimeUnit.MILLISECONDS.toNanos(600));
+        600, 0);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getExecutionTime().getAverage(),
-        TimeUnit.MILLISECONDS.toNanos(300), 0);
+        300, 0);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getExecutionTime().getMax(),
-        TimeUnit.MILLISECONDS.toNanos(400));
+        400, 0);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getExecutionTime().getMin(),
-        TimeUnit.MILLISECONDS.toNanos(200));
+        200, 0);
 
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerLatency().getCount(), 2);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerLatency().getTotal(),
-        TimeUnit.MILLISECONDS.toNanos(1000));
+        1000, 0);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerLatency().getAverage(),
-        TimeUnit.MILLISECONDS.toNanos(500), 0);
+        500, 0);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerLatency().getMax(),
-        TimeUnit.MILLISECONDS.toNanos(700));
+        700, 0);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerLatency().getMin(),
-        TimeUnit.MILLISECONDS.toNanos(300));
+        300, 0);
 
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerCall().getTps(), 3, 0);
     Assert.assertEquals(model.getInstanceMetric().getProducerMetric().getProducerCall().getTotal(), 3);
 
     Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerLatency().getCount(), 1);
     Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerLatency().getTotal(),
-        TimeUnit.MILLISECONDS.toNanos(300));
+        300, 0);
     Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerLatency().getAverage(),
-        TimeUnit.MILLISECONDS.toNanos(300), 0);
+        300, 0);
     Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerLatency().getMax(),
-        TimeUnit.MILLISECONDS.toNanos(300));
+        300, 0);
     Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerLatency().getMin(),
-        TimeUnit.MILLISECONDS.toNanos(300));
+        300, 0);
 
     Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerCall().getTps(), 1, 0);
     Assert.assertEquals(model.getInstanceMetric().getConsumerMetric().getConsumerCall().getTotal(), 1);
@@ -140,33 +140,33 @@ public class TestEventAndRunner {
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getWaitInQueue(), 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getLifeTimeInQueue().getCount(), 2);
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getLifeTimeInQueue().getTotal(),
-        TimeUnit.MILLISECONDS.toNanos(400));
+        400, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getLifeTimeInQueue().getAverage(),
-        TimeUnit.MILLISECONDS.toNanos(200), 0);
+        200, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getLifeTimeInQueue().getMax(),
-        TimeUnit.MILLISECONDS.toNanos(300));
+        300, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getLifeTimeInQueue().getMin(),
-        TimeUnit.MILLISECONDS.toNanos(100));
+        100, 0);
 
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getExecutionTime().getCount(), 2);
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getExecutionTime().getTotal(),
-        TimeUnit.MILLISECONDS.toNanos(600));
+        600, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getExecutionTime().getAverage(),
-        TimeUnit.MILLISECONDS.toNanos(300), 0);
+        300, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getExecutionTime().getMax(),
-        TimeUnit.MILLISECONDS.toNanos(400));
+        400, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getExecutionTime().getMin(),
-        TimeUnit.MILLISECONDS.toNanos(200));
+        200, 0);
 
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerLatency().getCount(), 2);
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerLatency().getTotal(),
-        TimeUnit.MILLISECONDS.toNanos(1000));
+        1000, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerLatency().getAverage(),
-        TimeUnit.MILLISECONDS.toNanos(500), 0);
+        500, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerLatency().getMax(),
-        TimeUnit.MILLISECONDS.toNanos(700));
+        700, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerLatency().getMin(),
-        TimeUnit.MILLISECONDS.toNanos(300));
+        300, 0);
 
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerCall().getTps(), 2, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun1").getProducerCall().getTotal(), 2);
@@ -175,33 +175,33 @@ public class TestEventAndRunner {
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getWaitInQueue(), 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getLifeTimeInQueue().getCount(), 1);
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getLifeTimeInQueue().getTotal(),
-        TimeUnit.MILLISECONDS.toNanos(500));
+        500, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getLifeTimeInQueue().getAverage(),
-        TimeUnit.MILLISECONDS.toNanos(500), 0);
+        500, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getLifeTimeInQueue().getMax(),
-        TimeUnit.MILLISECONDS.toNanos(500));
+        500, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getLifeTimeInQueue().getMin(),
-        TimeUnit.MILLISECONDS.toNanos(500));
+        500, 0);
 
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getExecutionTime().getCount(), 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getExecutionTime().getTotal(),
-        TimeUnit.MILLISECONDS.toNanos(0));
+        0, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getExecutionTime().getAverage(),
-        TimeUnit.MILLISECONDS.toNanos(0), 0);
+        0, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getExecutionTime().getMax(),
-        TimeUnit.MILLISECONDS.toNanos(0));
+        0, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getExecutionTime().getMin(),
-        TimeUnit.MILLISECONDS.toNanos(0));
+        0, 0);
 
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerLatency().getCount(), 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerLatency().getTotal(),
-        TimeUnit.MILLISECONDS.toNanos(0));
+        0, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerLatency().getAverage(),
-        TimeUnit.MILLISECONDS.toNanos(0), 0);
+        0, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerLatency().getMax(),
-        TimeUnit.MILLISECONDS.toNanos(0));
+        0, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerLatency().getMin(),
-        TimeUnit.MILLISECONDS.toNanos(0));
+        0, 0);
 
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerCall().getTps(), 1, 0);
     Assert.assertEquals(model.getProducerMetrics().get("fun3").getProducerCall().getTotal(), 1);
@@ -211,13 +211,13 @@ public class TestEventAndRunner {
     Assert.assertEquals(model.getConsumerMetrics().get("fun2").getWaitInQueue(), 0);
     Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerLatency().getCount(), 1);
     Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerLatency().getTotal(),
-        TimeUnit.MILLISECONDS.toNanos(300));
+        300, 0);
     Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerLatency().getAverage(),
-        TimeUnit.MILLISECONDS.toNanos(300), 0);
+        300, 0);
     Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerLatency().getMax(),
-        TimeUnit.MILLISECONDS.toNanos(300));
+        300, 0);
     Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerLatency().getMin(),
-        TimeUnit.MILLISECONDS.toNanos(300));
+        300, 0);
 
     Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerCall().getTps(), 1, 0);
     Assert.assertEquals(model.getConsumerMetrics().get("fun2").getConsumerCall().getTotal(), 1);

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

[incubator-servicecomb-java-chassis] 02/12: JAV-539 & SCB-9 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 4504cd61af405cc759797557caafe20cb2aeae00
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Thu Dec 21 09:10:05 2017 +0800

    JAV-539 & SCB-9 update asf license
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../metrics/core/metric/CallMetric.java            | 13 ++++-----
 .../metrics/core/monitor/CallMonitor.java          | 13 ++++-----
 .../src/main/resources/microservice.yaml           | 31 +++++++++++-----------
 3 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java
index 210f7fb..7fa5299 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.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/monitor/CallMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java
index 9e89122..ec38caf 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.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-sample/metrics-performance-test/src/main/resources/microservice.yaml b/metrics/metrics-sample/metrics-performance-test/src/main/resources/microservice.yaml
index 5191703..664614c 100644
--- a/metrics/metrics-sample/metrics-performance-test/src/main/resources/microservice.yaml
+++ b/metrics/metrics-sample/metrics-performance-test/src/main/resources/microservice.yaml
@@ -1,18 +1,19 @@
-#
-#  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.
-#
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
 
 # all interconnected microservices must belong to an application wth the same ID
 APPLICATION_ID: metricsPerfTest

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

[incubator-servicecomb-java-chassis] 01/12: JAV-539 & SC-9 Implement CallCount and TPS 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 bc882a5d7b1e5cb418346360a8bc0e9b39152add
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Wed Dec 20 10:33:37 2017 +0800

    JAV-539 & SC-9 Implement CallCount and TPS Metrics
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../InvocationStartProcessingEventListener.java    |  4 ++
 .../core/event/InvocationStartedEventListener.java |  1 +
 .../metrics/core/metric/CallMetric.java            | 44 ++++++++++++++++++
 .../metrics/core/metric/InvocationMetric.java      |  4 +-
 .../metrics/core/metric/ModelMetric.java           | 16 ++++++-
 .../metrics/core/metric/RegistryMetric.java        | 19 ++++----
 .../metrics/core/metric/TimerMetric.java           |  2 +-
 .../metrics/core/monitor/CallMonitor.java          | 43 ++++++++++++++++++
 .../metrics/core/monitor/InvocationMonitor.java    | 29 +++++++++---
 .../metrics/core/TestEventAndRunner.java           | 53 ++++++----------------
 .../src/main/resources/microservice.yaml           |  2 +-
 11 files changed, 157 insertions(+), 60 deletions(-)

diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartProcessingEventListener.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartProcessingEventListener.java
index 1680ec3..1aabd22 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartProcessingEventListener.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartProcessingEventListener.java
@@ -41,9 +41,13 @@ public class InvocationStartProcessingEventListener implements EventListener {
   public void process(Event data) {
     InvocationStartProcessingEvent event = (InvocationStartProcessingEvent) data;
     InvocationMonitor monitor = registryMonitor.getInvocationMonitor(event.getOperationName());
+    //TODO:current java chassis unable know invocation type before starting process,so all type WaitInQueue increment(-1) (decrement)
     monitor.getWaitInQueue().increment(-1);
     if (InvocationType.PRODUCER.equals(event.getInvocationType())) {
       monitor.getLifeTimeInQueue().update(event.getInQueueNanoTime());
+      monitor.getProducerCall().increment();
+    } else {
+      monitor.getConsumerCall().increment();
     }
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartedEventListener.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartedEventListener.java
index c9b7763..ffb97b1 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartedEventListener.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/event/InvocationStartedEventListener.java
@@ -38,6 +38,7 @@ public class InvocationStartedEventListener implements EventListener {
   @Override
   public void process(Event data) {
     InvocationStartedEvent event = (InvocationStartedEvent) data;
+    //TODO:current java chassis unable know invocation type before starting process,so all type WaitInQueue increment
     registryMonitor.getInvocationMonitor(event.getOperationName()).getWaitInQueue().increment();
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java
new file mode 100644
index 0000000..210f7fb
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/CallMetric.java
@@ -0,0 +1,44 @@
+/*
+ * 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 CallMetric {
+  private final long total;
+
+  private final double tps;
+
+  public long getTotal() {
+    return total;
+  }
+
+  public double getTps() {
+    return tps;
+  }
+
+  public CallMetric() {
+    this(0, 0);
+  }
+
+  public CallMetric(long total, double tps) {
+    this.total = total;
+    this.tps = tps;
+  }
+
+  public CallMetric merge(CallMetric metric) {
+    return new CallMetric(this.total + metric.total, this.tps + metric.tps);
+  }
+}
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java
index d62ddc3..e1b5e3e 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/InvocationMetric.java
@@ -26,8 +26,8 @@ public class InvocationMetric extends ModelMetric {
 
   public InvocationMetric(String operationName, long waitInQueue,
       TimerMetric lifeTimeInQueue, TimerMetric executionTime, TimerMetric consumerLatency,
-      TimerMetric producerLatency) {
-    super(waitInQueue, lifeTimeInQueue, executionTime, consumerLatency, producerLatency);
+      TimerMetric producerLatency, CallMetric consumerCall, CallMetric producerCall) {
+    super(waitInQueue, lifeTimeInQueue, executionTime, consumerLatency, producerLatency, consumerCall, producerCall);
     this.operationName = operationName;
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ModelMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ModelMetric.java
index 05436c9..7273171 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ModelMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/ModelMetric.java
@@ -28,6 +28,10 @@ public abstract class ModelMetric {
 
   private final TimerMetric producerLatency;
 
+  private final CallMetric consumerCall;
+
+  private final CallMetric producerCall;
+
   public long getWaitInQueue() {
     return waitInQueue;
   }
@@ -48,13 +52,23 @@ public abstract class ModelMetric {
     return producerLatency;
   }
 
+  public CallMetric getConsumerCall() {
+    return consumerCall;
+  }
+
+  public CallMetric getProducerCall() {
+    return producerCall;
+  }
+
   public ModelMetric(long waitInQueue,
       TimerMetric lifeTimeInQueue, TimerMetric executionTime, TimerMetric consumerLatency,
-      TimerMetric producerLatency) {
+      TimerMetric producerLatency, CallMetric consumerCall, CallMetric producerCall) {
     this.waitInQueue = waitInQueue;
     this.lifeTimeInQueue = lifeTimeInQueue;
     this.executionTime = executionTime;
     this.consumerLatency = consumerLatency;
     this.producerLatency = producerLatency;
+    this.consumerCall = consumerCall;
+    this.producerCall = producerCall;
   }
 }
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 7569420..bf7b5e8 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,7 +19,6 @@ 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 {
@@ -36,7 +35,7 @@ public class RegistryMetric {
     return invocationMetrics;
   }
 
-  public RegistryMetric(SystemResource systemResource, RegistryMonitor registryMonitor, int pollerIndex) {
+  public RegistryMetric(RegistryMonitor registryMonitor, int pollerIndex) {
     invocationMetrics = registryMonitor.toInvocationMetrics(pollerIndex);
 
     //sum instance level metric
@@ -45,21 +44,21 @@ public class RegistryMetric {
     TimerMetric executionTime = new TimerMetric();
     TimerMetric consumerLatency = new TimerMetric();
     TimerMetric producerLatency = new TimerMetric();
+
+    CallMetric consumerCall = new CallMetric();
+    CallMetric producerCall = new CallMetric();
+
     for (InvocationMetric metric : invocationMetrics.values()) {
       waitInQueue += metric.getWaitInQueue();
       lifeTimeInQueue = lifeTimeInQueue.merge(metric.getLifeTimeInQueue());
       executionTime = executionTime.merge(metric.getExecutionTime());
       consumerLatency = consumerLatency.merge(metric.getConsumerLatency());
       producerLatency = producerLatency.merge(metric.getProducerLatency());
+      consumerCall = consumerCall.merge(metric.getConsumerCall());
+      producerCall = producerCall.merge(metric.getProducerCall());
     }
 
-    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);
+    instanceMetric = new InstanceMetric(waitInQueue, lifeTimeInQueue, executionTime, consumerLatency, producerLatency,
+        consumerCall, producerCall);
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java
index 8bd7297..40f82ff 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/metric/TimerMetric.java
@@ -74,6 +74,6 @@ public class TimerMetric {
   }
 
   private long getMax(long value1, long value2) {
-    return value1 == 0 || value2 > value1 ? value2 : value1;
+    return value2 > value1 ? value2 : value1;
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java
new file mode 100644
index 0000000..9e89122
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/CallMonitor.java
@@ -0,0 +1,43 @@
+/*
+ * 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.monitor;
+
+import com.netflix.servo.monitor.BasicCounter;
+import com.netflix.servo.monitor.MonitorConfig;
+import com.netflix.servo.monitor.StepCounter;
+
+import io.servicecomb.metrics.core.metric.CallMetric;
+
+public class CallMonitor {
+  private final BasicCounter total;
+
+  private final StepCounter tps;
+
+  public CallMonitor(String name) {
+    this.total = new BasicCounter(MonitorConfig.builder(name + ".total").build());
+    this.tps = new StepCounter(MonitorConfig.builder(name + ".tps").build());
+  }
+
+  public void increment() {
+    total.increment();
+    tps.increment();
+  }
+
+  public CallMetric toCallMetric(int pollerIndex) {
+    return new CallMetric(total.getValue(pollerIndex).longValue(), tps.getValue(pollerIndex).doubleValue());
+  }
+}
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitor.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitor.java
index 35a6ca8..d3588f5 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitor.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/monitor/InvocationMonitor.java
@@ -35,6 +35,10 @@ public class InvocationMonitor {
 
   private final TimerMonitor producerLatency;
 
+  private final CallMonitor consumerCall;
+
+  private final CallMonitor producerCall;
+
   public String getOperationName() {
     return operationName;
   }
@@ -59,13 +63,24 @@ public class InvocationMonitor {
     return producerLatency;
   }
 
+  public CallMonitor getConsumerCall() {
+    return consumerCall;
+  }
+
+  public CallMonitor getProducerCall() {
+    return producerCall;
+  }
+
   public InvocationMonitor(String operationName) {
     this.operationName = operationName;
-    this.waitInQueue = new BasicCounter(MonitorConfig.builder("waitInQueue").build());
-    this.lifeTimeInQueue = new TimerMonitor("lifeTimeInQueue");
-    this.executionTime = new TimerMonitor("executionTime");
-    this.consumerLatency = new TimerMonitor("consumerLatency");
-    this.producerLatency = new TimerMonitor("producerLatency");
+    this.waitInQueue = new BasicCounter(MonitorConfig.builder(operationName + ".waitInQueue.count").build());
+    this.lifeTimeInQueue = new TimerMonitor(operationName + ".lifeTimeInQueue");
+    this.executionTime = new TimerMonitor(operationName + ".executionTime");
+    this.consumerLatency = new TimerMonitor(operationName + ".consumerLatency");
+    this.producerLatency = new TimerMonitor(operationName + ".producerLatency");
+
+    this.consumerCall = new CallMonitor(operationName + ".consumerCall");
+    this.producerCall = new CallMonitor(operationName + ".producerCall");
   }
 
   public InvocationMetric toInvocationMetric(int pollerIndex) {
@@ -73,6 +88,8 @@ public class InvocationMonitor {
         this.lifeTimeInQueue.toTimerMetric(pollerIndex),
         this.executionTime.toTimerMetric(pollerIndex),
         this.consumerLatency.toTimerMetric(pollerIndex),
-        this.producerLatency.toTimerMetric(pollerIndex));
+        this.producerLatency.toTimerMetric(pollerIndex),
+        this.consumerCall.toCallMetric(pollerIndex),
+        this.producerCall.toCallMetric(pollerIndex));
   }
 }
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 f98f04f..da7f02e 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,24 +17,16 @@
 
 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;
@@ -44,27 +36,8 @@ 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();
-    DefaultSystemResource systemResource = new DefaultSystemResource(systemMXBean, threadMXBean, memoryMXBean);
-    DefaultDataSource dataSource = new DefaultDataSource(systemResource, monitor, "2000");
+    DefaultDataSource dataSource = new DefaultDataSource(monitor, "2000");
 
     DefaultEventListenerManager manager = new DefaultEventListenerManager(monitor);
 
@@ -163,15 +136,17 @@ public class TestEventAndRunner {
     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);
+    Assert.assertEquals(model.getInvocationMetrics().get("fun1").getConsumerCall().getTotal(), 0, 0);
+    Assert.assertEquals(model.getInvocationMetrics().get("fun1").getConsumerCall().getTps(), 0, 0);
+    Assert.assertEquals(model.getInvocationMetrics().get("fun1").getProducerCall().getTotal(), 2, 0);
+    Assert.assertEquals(model.getInvocationMetrics().get("fun1").getProducerCall().getTps(), 1.0, 0);
+    Assert.assertEquals(model.getInvocationMetrics().get("fun12").getConsumerCall().getTotal(), 0, 0);
+    Assert.assertEquals(model.getInvocationMetrics().get("fun12").getConsumerCall().getTps(), 0, 0);
+    Assert.assertEquals(model.getInvocationMetrics().get("fun12").getProducerCall().getTotal(), 1, 0);
+    Assert.assertEquals(model.getInvocationMetrics().get("fun12").getProducerCall().getTps(), 0.5, 0);
+    Assert.assertEquals(model.getInstanceMetric().getConsumerCall().getTotal(), 0, 0);
+    Assert.assertEquals(model.getInstanceMetric().getConsumerCall().getTps(), 0, 0);
+    Assert.assertEquals(model.getInstanceMetric().getProducerCall().getTotal(), 3, 0);
+    Assert.assertEquals(model.getInstanceMetric().getProducerCall().getTps(), 1.5, 0);
   }
-}
\ No newline at end of file
+}
diff --git a/metrics/metrics-sample/metrics-performance-test/src/main/resources/microservice.yaml b/metrics/metrics-sample/metrics-performance-test/src/main/resources/microservice.yaml
index 0e12fde..5191703 100644
--- a/metrics/metrics-sample/metrics-performance-test/src/main/resources/microservice.yaml
+++ b/metrics/metrics-sample/metrics-performance-test/src/main/resources/microservice.yaml
@@ -31,5 +31,5 @@ servicecomb:
   metrics:
     #polling setting
     polling:
-      #Time Unit is MILLISECONDS
+      #Support Muti Polling Time (MILLISECONDS) like 10000,60000 (10s and 60s)
       time: 10000
\ No newline at end of file

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