You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by dl...@apache.org on 2017/08/04 18:45:22 UTC

[1/2] incubator-edgent git commit: Implemented support for csv. Which periodically appends to a set of .csv files in a given directory

Repository: incubator-edgent
Updated Branches:
  refs/heads/master e440dad54 -> bdb2cd815


Implemented support for csv. Which periodically appends to a set of .csv files in a given directory


Project: http://git-wip-us.apache.org/repos/asf/incubator-edgent/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-edgent/commit/fe7c3c21
Tree: http://git-wip-us.apache.org/repos/asf/incubator-edgent/tree/fe7c3c21
Diff: http://git-wip-us.apache.org/repos/asf/incubator-edgent/diff/fe7c3c21

Branch: refs/heads/master
Commit: fe7c3c21fbb168fd0159e8bbf8848f1beba757c6
Parents: e440dad
Author: Thomas Cristanis <tc...@cin.ufpe.br>
Authored: Wed Jul 19 20:35:56 2017 -0300
Committer: Thomas Cristanis <tc...@cin.ufpe.br>
Committed: Wed Jul 19 20:35:56 2017 -0300

----------------------------------------------------------------------
 .../org/apache/edgent/metrics/MetricsSetup.java | 51 ++++++++++++++++++++
 1 file changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/fe7c3c21/utils/metrics/src/main/java/org/apache/edgent/metrics/MetricsSetup.java
----------------------------------------------------------------------
diff --git a/utils/metrics/src/main/java/org/apache/edgent/metrics/MetricsSetup.java b/utils/metrics/src/main/java/org/apache/edgent/metrics/MetricsSetup.java
index 5ab4564..2d421bc 100644
--- a/utils/metrics/src/main/java/org/apache/edgent/metrics/MetricsSetup.java
+++ b/utils/metrics/src/main/java/org/apache/edgent/metrics/MetricsSetup.java
@@ -18,7 +18,11 @@ under the License.
 */
 package org.apache.edgent.metrics;
 
+import java.io.File;
 import java.lang.management.ManagementFactory;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Locale;
 import java.util.concurrent.TimeUnit;
 
 import javax.management.MBeanServer;
@@ -41,6 +45,7 @@ import com.codahale.metrics.MetricRegistry;
 public class MetricsSetup {
     private static final TimeUnit durationsUnit = TimeUnit.MILLISECONDS;
     private static final TimeUnit ratesUnit = TimeUnit.SECONDS;
+    private static final String FOLDER_METRICS = "/metrics";
 
     private final MetricRegistry metricRegistry;
     private MBeanServer mBeanServer;
@@ -85,6 +90,33 @@ public class MetricsSetup {
         reporter.start();
         return this;
     }
+
+    /**
+     * Starts the metric {@code CsvReporter}. If no MBeanServer was set, use the
+     * virtual machine's platform MBeanServer.
+     * 
+     * @param pathMetrics
+     *            pathname where the metric files are stored. If the path does
+     *            not exist or is null is created in a standard directory,
+     *            called metrics
+     * @return this
+     */
+    public MetricsSetup startCSVReporter(String pathMetrics) {
+
+        if (pathMetrics == null) { // pathMetrics is NULL
+            pathMetrics = createDefaultDirectory();
+        } else {
+            File directory = new File(pathMetrics);
+            if (!directory.exists() && !directory.mkdirs()) {
+                pathMetrics = createDefaultDirectory();
+            }
+        }
+
+        final CsvReporter reporter = CsvReporter.forRegistry(registry()).formatFor(Locale.US).convertRatesTo(ratesUnit)
+                .convertDurationsTo(durationsUnit).build(new File(pathMetrics));
+        reporter.start(1, TimeUnit.SECONDS);
+        return this;
+    }
     
     /**
      * Starts the metric {@code ConsoleReporter} polling every second.
@@ -111,6 +143,25 @@ public class MetricsSetup {
         }
         return mBeanServer;
     }
+
+    /**
+     * Creates a default directory for metrics.
+     * 
+     * @return directory.getPath()
+     */
+    private String createDefaultDirectory() {
+        Path currentRelativePath = Paths.get("");
+        String pathMetrics = currentRelativePath.toAbsolutePath().toString() + FOLDER_METRICS;
+        File directory = new File(pathMetrics);
+        
+        if (!directory.mkdirs()) {
+            // Log: "Could not create the directory log"
+        } else {
+            // Log: "The directory was created successfully: "
+        }
+
+        return directory.getPath();
+    }
     
     private class MetricOpletCleaner implements BiConsumer<String, String> {
         


[2/2] incubator-edgent git commit: Implemented support for csv. Which periodically appends to a set of .csv files in a given directory

Posted by dl...@apache.org.
Implemented support for csv. Which periodically appends to a set of .csv files in a given directory


Project: http://git-wip-us.apache.org/repos/asf/incubator-edgent/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-edgent/commit/bdb2cd81
Tree: http://git-wip-us.apache.org/repos/asf/incubator-edgent/tree/bdb2cd81
Diff: http://git-wip-us.apache.org/repos/asf/incubator-edgent/diff/bdb2cd81

Branch: refs/heads/master
Commit: bdb2cd815bf34c6b83a36cc204a2954a909197ff
Parents: fe7c3c2
Author: Thomas Cristanis <tc...@cin.ufpe.br>
Authored: Wed Jul 19 20:59:37 2017 -0300
Committer: Thomas Cristanis <tc...@cin.ufpe.br>
Committed: Wed Jul 19 20:59:37 2017 -0300

----------------------------------------------------------------------
 .../src/main/java/org/apache/edgent/metrics/MetricsSetup.java       | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/bdb2cd81/utils/metrics/src/main/java/org/apache/edgent/metrics/MetricsSetup.java
----------------------------------------------------------------------
diff --git a/utils/metrics/src/main/java/org/apache/edgent/metrics/MetricsSetup.java b/utils/metrics/src/main/java/org/apache/edgent/metrics/MetricsSetup.java
index 2d421bc..88d8d50 100644
--- a/utils/metrics/src/main/java/org/apache/edgent/metrics/MetricsSetup.java
+++ b/utils/metrics/src/main/java/org/apache/edgent/metrics/MetricsSetup.java
@@ -31,6 +31,7 @@ import org.apache.edgent.execution.services.ServiceContainer;
 import org.apache.edgent.function.BiConsumer;
 
 import com.codahale.metrics.ConsoleReporter;
+import com.codahale.metrics.CsvReporter;
 import com.codahale.metrics.JmxReporter;
 import com.codahale.metrics.Metric;
 import com.codahale.metrics.MetricFilter;