Repository: camel
Updated Branches:
  refs/heads/master 5f95e5510 -> 2ebd766b9


CAMEL-7696: camel-metrics - Add a route policy to expose route stats as 
codehale metrics. Work in progress.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2ebd766b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2ebd766b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2ebd766b

Branch: refs/heads/master
Commit: 2ebd766b9951e0cc9a852159e9aaafecac2b1041
Parents: 5f95e55
Author: Claus Ibsen <davscl...@apache.org>
Authored: Sun Aug 31 12:58:03 2014 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Sun Aug 31 12:58:03 2014 +0200

----------------------------------------------------------------------
 .../metrics/routepolicy/MetricsRegistryMBean.java |  3 +++
 .../routepolicy/MetricsRegistryService.java       | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2ebd766b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRegistryMBean.java
----------------------------------------------------------------------
diff --git 
a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRegistryMBean.java
 
b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRegistryMBean.java
index e37f8b6..c0abdc7 100644
--- 
a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRegistryMBean.java
+++ 
b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRegistryMBean.java
@@ -23,4 +23,7 @@ public interface MetricsRegistryMBean {
     @ManagedOperation(description = "Dumps the statistics as json")
     String dumpStatisticsAsJson();
 
+    @ManagedOperation(description = "Dumps the statistics as json using 
seconds for time units")
+    String dumpStatisticsAsJsonTimeUnitSeconds();
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/2ebd766b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRegistryService.java
----------------------------------------------------------------------
diff --git 
a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRegistryService.java
 
b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRegistryService.java
index 2bde7f0..12c6ceb 100644
--- 
a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRegistryService.java
+++ 
b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRegistryService.java
@@ -48,6 +48,7 @@ public final class MetricsRegistryService extends 
ServiceSupport implements Came
     private TimeUnit rateUnit = TimeUnit.SECONDS;
     private TimeUnit durationUnit = TimeUnit.MILLISECONDS;
     private transient ObjectMapper mapper;
+    private transient ObjectMapper secondsMapper;
 
     public MetricRegistry getMetricsRegistry() {
         return metricsRegistry;
@@ -126,6 +127,12 @@ public final class MetricsRegistryService extends 
ServiceSupport implements Came
 
         // json mapper
         this.mapper = new ObjectMapper().registerModule(new 
MetricsModule(getRateUnit(), getDurationUnit(), false));
+        if (getRateUnit() == TimeUnit.SECONDS && getDurationUnit() == 
TimeUnit.SECONDS) {
+            // they both use same units so reuse
+            this.secondsMapper = this.mapper;
+        } else {
+            this.secondsMapper = new ObjectMapper().registerModule(new 
MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false));
+        }
     }
 
     @Override
@@ -149,4 +156,15 @@ public final class MetricsRegistryService extends 
ServiceSupport implements Came
         }
     }
 
+    public String dumpStatisticsAsJsonTimeUnitSeconds() {
+        ObjectWriter writer = secondsMapper.writer();
+        if (isPrettyPrint()) {
+            writer = writer.withDefaultPrettyPrinter();
+        }
+        try {
+            return writer.writeValueAsString(getMetricsRegistry());
+        } catch (JsonProcessingException e) {
+            throw ObjectHelper.wrapRuntimeCamelException(e);
+        }
+    }
 }

Reply via email to