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

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

wujimin commented on a change in pull request #987: [SCB-1017]add os cpu net 
info in the metrics with linux os
URL: 
https://github.com/apache/servicecomb-java-chassis/pull/987#discussion_r233083251
 
 

 ##########
 File path: 
metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/DefaultLogPublisher.java
 ##########
 @@ -102,14 +111,67 @@ protected void printLog(List<Meter> meters) {
     DefaultPublishModel model = factory.createDefaultPublishModel();
 
     printThreadPoolMetrics(model, sb);
-
+    printOsLog(factory.getTree(), sb);
     printConsumerLog(model, sb);
     printProducerLog(model, sb);
     printEdgeLog(model, sb);
 
     LOGGER.info(sb.toString());
   }
 
+  protected void printOsLog(MeasurementTree tree, StringBuilder sb) {
+    if (!DynamicPropertyFactory.getInstance()
+        .getBooleanProperty(METRICS_OS_ENABLED, false)
+        .get()) {
+      return;
+    }
+    MeasurementNode OsNode = 
tree.findChild(OsStatisticsMeter.OS_STATISTICS_NAME);
+    if (OsNode != null && !OsNode.getMeasurements().isEmpty()) {
+      MeasurementNode netNode = OsNode.findChild("net");
+      MeasurementNode cpuNode = OsNode.findChild("cpu");
+      if (cpuNode != null && !cpuNode.getMeasurements().isEmpty()) {
+        double rate = cpuNode.findChild("allCpu", 
OsCpuMeter.tagCpuRate.value()).summary();
+        String ratePercentStr = "calc ...";
+        NumberFormat nt = NumberFormat.getPercentInstance();
+        if (rate > 0.0) {
+          nt.setMaximumFractionDigits(3);
+          ratePercentStr = nt.format(rate);
+        }
+        sb.append("os:\n")
+            .append(String.format("  cpu: %s\n", ratePercentStr));
+      }
+      if (netNode != null && !netNode.getMeasurements().isEmpty()) {
+        sb.append("  net:\n    interface                     send              
                         recv\n");
+        for (MeasurementNode iNode : netNode.getChildren().values()) {
+          double sendRate = 
iNode.findChild(OsNetMeter.tagBytesTransmit.value()).summary();
+          double receiveRate = 
iNode.findChild(OsNetMeter.tagBytesReceive.value()).summary();
+          if (sendRate == 0.0 && receiveRate == 0.0) {
+            //interface with rate 0.0 should be skipped
+            continue;
+          }
+          String sendRateStr = "calc ...";
+          String receiveRateStr = "calc ...";
+          if (sendRate != OsNetMeter.DEFAULT_INIT_RATE || receiveRate != 
OsNetMeter.DEFAULT_INIT_RATE) {
+            sendRateStr = getRealTimeNetStr(sendRate);
+            receiveRateStr = getRealTimeNetStr(receiveRate);
+          }
+          sb.append(String.format("    %-29s %-42s %s\n",
+              iNode.getName(), sendRateStr, receiveRateStr));
+        }
+      }
+    }
+  }
+
+  private String getRealTimeNetStr(Double netBytes) {
 
 Review comment:
     public static String humanReadableBytes(long bytes) {
       int unit = 1024;
       if (bytes < unit) {
         return bytes + " B";
       }
   
       int exp = (int) (Math.log(bytes) / Math.log(unit));
       char pre = "KMGTPE".charAt(exp - 1);
       return String.format("%.3f %cB", bytes / Math.pow(unit, exp), pre);
     }
   
   put it to org.apache.servicecomb.foundation.common.net.NetUtils

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


> [SCB-1017] add os cpu net info  in the metrics with linux os
> ------------------------------------------------------------
>
>                 Key: SCB-1017
>                 URL: https://issues.apache.org/jira/browse/SCB-1017
>             Project: Apache ServiceComb
>          Issue Type: Improvement
>            Reporter: 何一乐
>            Priority: Major
>




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

Reply via email to