[ 
https://issues.apache.org/jira/browse/SCB-1044?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16708676#comment-16708676
 ] 

ASF GitHub Bot commented on SCB-1044:
-------------------------------------

wujimin commented on a change in pull request #1012: [SCB-1044]add current 
process CPU rate  and net packets in the metrics
URL: 
https://github.com/apache/servicecomb-java-chassis/pull/1012#discussion_r238654827
 
 

 ##########
 File path: 
metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/meter/os/NetMeter.java
 ##########
 @@ -43,101 +46,48 @@
 
   public static final Tag TAG_RECEIVE = new BasicTag(STATISTIC, "receive");
 
-  public static final Tag TAG_SEND = new BasicTag(STATISTIC, "send");
-
-  private final Id id;
-
-  private Map<String, InterfaceInfo> interfaceInfoMap = new 
ConcurrentHashMap<>();
-
-  public static class InterfaceInfo {
-    private final String name;
-
-    private Id sendId;
-
-    private Id receiveId;
-
-    //receive bytes
-    private long lastRxBytes;
-
-    //transmit bytes
-    private long lastTxBytes;
-
-    // bytes per second
-    private double sendRate;
-
-    private double receiveRate;
-
-    InterfaceInfo(Id id, String name) {
-      this.name = name;
-      id = id.withTag(INTERFACE, name);
-      this.sendId = id.withTag(TAG_SEND);
-      this.receiveId = id.withTag(TAG_RECEIVE);
-    }
-
-    public void update(String interfaceData, long secondInterval) {
-      String[] netInfo = interfaceData.trim().split("\\s+");
-      long rxBytes = Long.parseLong(netInfo[0]);
-      long txBytes = Long.parseLong(netInfo[8]);
-      sendRate = (double) (txBytes - lastTxBytes) / secondInterval;
-      receiveRate = (double) (rxBytes - lastRxBytes) / secondInterval;
-      lastRxBytes = rxBytes;
-      lastTxBytes = txBytes;
-    }
-
-    public String getName() {
-      return name;
-    }
+  public static final Tag TAG_PACKETS_RECEIVE = new BasicTag(STATISTIC, 
"receivePackets");
 
-    public long getLastRxBytes() {
-      return lastRxBytes;
-    }
+  public static final Tag TAG_SEND = new BasicTag(STATISTIC, "send");
 
-    public long getLastTxBytes() {
-      return lastTxBytes;
-    }
+  public static final Tag TAG_PACKETS_SEND = new BasicTag(STATISTIC, 
"sendPackets");
 
-    public double getSendRate() {
-      return sendRate;
-    }
+  private final Id id;
 
-    public double getReceiveRate() {
-      return receiveRate;
-    }
-  }
+  private Map<String, InterfaceUsage> interfaceUsageMap = new 
ConcurrentHashMap<>();
 
   public NetMeter(Id id) {
     this.id = id;
-
-    // init lastRxBytes and lastTxBytes
+    // init lastRxBytes, lastRxPackets, lastTxBytes, lastTxPackets
     refreshNet(1);
-    for (InterfaceInfo interfaceInfo : interfaceInfoMap.values()) {
-      interfaceInfo.sendRate = 0;
-      interfaceInfo.receiveRate = 0;
-    }
+    interfaceUsageMap.values().forEach(interfaceUsage -> {
+      interfaceUsage.getNetStats().forEach(NetStat::clearRate);
+    });
   }
 
   public void calcMeasurements(List<Measurement> measurements, long msNow, 
long secondInterval) {
     refreshNet(secondInterval);
 
-    for (InterfaceInfo interfaceInfo : interfaceInfoMap.values()) {
-      measurements.add(new Measurement(interfaceInfo.sendId, msNow, 
interfaceInfo.sendRate));
-      measurements.add(new Measurement(interfaceInfo.receiveId, msNow, 
interfaceInfo.receiveRate));
-    }
+    interfaceUsageMap.values().stream()
 
 Review comment:
   so complex, create a temp list and loop it to add to another list?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> add current process CPU rate  and net packets in the metrics
> ------------------------------------------------------------
>
>                 Key: SCB-1044
>                 URL: https://issues.apache.org/jira/browse/SCB-1044
>             Project: Apache ServiceComb
>          Issue Type: Improvement
>          Components: Java-Chassis
>            Reporter: 何一乐
>            Assignee: 何一乐
>            Priority: Major
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to