You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@servicecomb.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/12/03 00:16:00 UTC

[jira] [Commented] (SCB-1044) add current process CPU rate and net packets in the metrics

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

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

heyile 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_r237763091
 
 

 ##########
 File path: metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/meter/os/CpuMeter.java
 ##########
 @@ -18,68 +18,126 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.lang.management.ManagementFactory;
 import java.nio.charset.StandardCharsets;
 import java.util.List;
 
 import org.apache.commons.io.FileUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.netflix.spectator.api.BasicTag;
 import com.netflix.spectator.api.Id;
 import com.netflix.spectator.api.Measurement;
+import com.netflix.spectator.api.Tag;
 
 public class CpuMeter {
   private static final Logger LOGGER = LoggerFactory.getLogger(CpuMeter.class);
 
+  public static final String STATISTIC = "statistic";
+
+  public static final Tag TAG_All = new BasicTag(STATISTIC, "allProcess");
+
+  public static final Tag TAG_CURRENT = new BasicTag(STATISTIC, "currentProcess");
+
   private double rate;
 
+  private double processRate;
+
   private long lastTotalTime;
 
   private long lastIdleTime;
 
+  private long lastProcessTime;
+
   private int cpuNum;
 
-  private Id id;
+  // process id
+  private String pid;
+
+  // allProcess
+  private Id AId;
+
+  // currentProcess
+  private Id CId;
 
   public CpuMeter(Id id) {
-    this.id = id;
+    this.AId = id.withTag(TAG_All);
+    this.CId = id.withTag(TAG_CURRENT);
+
+    this.pid = getCurrentPid();
     this.cpuNum = Runtime.getRuntime().availableProcessors();
     refreshCpu();
     rate = 0.0;
+    processRate = 0.0;
+  }
+
+  private String getCurrentPid() {
+    String name = ManagementFactory.getRuntimeMXBean().getName();
+    if (name.contains("@")) {
+      return name.substring(0, name.indexOf("@"));
+    }
+    LOGGER.warn("Failed to get current process id. {}", name);
 
 Review comment:
   do not know when will the pid is null. It's impossible that the pid is null.

----------------------------------------------------------------
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:
users@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)