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

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

wujimin commented on a change in pull request #476: [SCB-85] Upgrade Metrics 
File Output from 0.5.0 to 1.0.0-m1
URL: 
https://github.com/apache/incubator-servicecomb-java-chassis/pull/476#discussion_r160050542
 
 

 ##########
 File path: 
metrics/metrics-extension/metrics-write-file/src/main/java/io/servicecomb/metrics/extension/writefile/SimpleFileContentConvertor.java
 ##########
 @@ -0,0 +1,61 @@
+/*
+ * 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.extension.writefile;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import com.netflix.config.DynamicPropertyFactory;
+
+import io.servicecomb.metrics.common.RegistryMetric;
+
+public class SimpleFileContentConvertor implements FileContentConvertor {
+
+  private static final String METRICS_ROUND_PLACES = 
"servicecomb.metrics.round_places";
+
+  private final int doubleRoundPlaces;
+
+  private final String doubleStringFormatter;
+
+  public SimpleFileContentConvertor() {
+    doubleRoundPlaces = 
DynamicPropertyFactory.getInstance().getIntProperty(METRICS_ROUND_PLACES, 
1).get();
+    doubleStringFormatter = "%." + String.valueOf(doubleRoundPlaces) + "f";
+  }
+
+  @Override
+  public Map<String, String> convert(RegistryMetric registryMetric) {
+    Map<String, String> pickedMetrics = new HashMap<>();
+    for (Entry<String, Number> metric : registryMetric.toMap().entrySet()) {
+      pickedMetrics.put(metric.getKey(), String.format(doubleStringFormatter,
+          round(metric.getValue().doubleValue(), doubleRoundPlaces)));
+    }
+    return pickedMetrics;
+  }
+
+  private double round(double value, int places) {
+    if (!Double.isNaN(value)) {
+      BigDecimal decimal = new BigDecimal(value);
+      return decimal.setScale(places, RoundingMode.HALF_UP).doubleValue();
+    } else {
 
 Review comment:
   no "else"

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


> Upgrade Metrics File Output from 0.5.0 to 1.0.0-m1
> --------------------------------------------------
>
>                 Key: SCB-85
>                 URL: https://issues.apache.org/jira/browse/SCB-85
>             Project: Apache ServiceComb
>          Issue Type: Sub-task
>          Components: Java-Chassis
>            Reporter: yangyongzheng
>            Assignee: yangyongzheng
>             Fix For: java-chassis-1.0.0-m1
>
>
> Because metrics had complete reflected in 1.0.0-m1,so we need upgrade file 
> output example and show new features.
> 1.support more build-in metric
> 2.support output operation level metric



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to