camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject git commit: CAMEL-7696: camel-metrics - Add a route policy to expose route stats as codehale metrics. Work in progress.
Date Sat, 30 Aug 2014 14:49:09 GMT
Repository: camel
Updated Branches:
  refs/heads/master e28e8ac4d -> 4769d97f1


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/4769d97f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4769d97f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4769d97f

Branch: refs/heads/master
Commit: 4769d97f17d949dd8d1d2a63233a21df7f92ca24
Parents: e28e8ac
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Aug 30 16:48:32 2014 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Aug 30 16:48:32 2014 +0200

----------------------------------------------------------------------
 .../routepolicy/MetricsRegistryService.java     | 20 +++++++++++++-
 .../metrics/routepolicy/MetricsRoutePolicy.java | 22 +++++++++++++++
 .../routepolicy/MetricsRoutePolicyFactory.java  | 28 ++++++++++++++++++++
 3 files changed, 69 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4769d97f/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 8ec1534..2bde7f0 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
@@ -45,6 +45,8 @@ public final class MetricsRegistryService extends ServiceSupport implements
Came
     private boolean useJmx;
     private String jmxDomain = "org.apache.camel.metrics";
     private boolean prettyPrint;
+    private TimeUnit rateUnit = TimeUnit.SECONDS;
+    private TimeUnit durationUnit = TimeUnit.MILLISECONDS;
     private transient ObjectMapper mapper;
 
     public MetricRegistry getMetricsRegistry() {
@@ -87,6 +89,22 @@ public final class MetricsRegistryService extends ServiceSupport implements
Came
         this.prettyPrint = prettyPrint;
     }
 
+    public TimeUnit getRateUnit() {
+        return rateUnit;
+    }
+
+    public void setRateUnit(TimeUnit rateUnit) {
+        this.rateUnit = rateUnit;
+    }
+
+    public TimeUnit getDurationUnit() {
+        return durationUnit;
+    }
+
+    public void setDurationUnit(TimeUnit durationUnit) {
+        this.durationUnit = durationUnit;
+    }
+
     @Override
     protected void doStart() throws Exception {
         if (metricsRegistry == null) {
@@ -107,7 +125,7 @@ public final class MetricsRegistryService extends ServiceSupport implements
Came
         }
 
         // json mapper
-        this.mapper = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS,
TimeUnit.SECONDS, false));
+        this.mapper = new ObjectMapper().registerModule(new MetricsModule(getRateUnit(),
getDurationUnit(), false));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/4769d97f/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
index 100bfa7..d28044a 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.metrics.routepolicy;
 
+import java.util.concurrent.TimeUnit;
+
 import com.codahale.metrics.Counter;
 import com.codahale.metrics.Meter;
 import com.codahale.metrics.MetricRegistry;
@@ -38,6 +40,8 @@ public class MetricsRoutePolicy extends RoutePolicySupport {
     private boolean useJmx = true;
     private String jmxDomain = "org.apache.camel.metrics";
     private boolean prettyPrint;
+    private TimeUnit rateUnit = TimeUnit.SECONDS;
+    private TimeUnit durationUnit = TimeUnit.MILLISECONDS;
     private MetricsStatistics statistics;
     private Route route;
 
@@ -105,6 +109,22 @@ public class MetricsRoutePolicy extends RoutePolicySupport {
         this.prettyPrint = prettyPrint;
     }
 
+    public TimeUnit getRateUnit() {
+        return rateUnit;
+    }
+
+    public void setRateUnit(TimeUnit rateUnit) {
+        this.rateUnit = rateUnit;
+    }
+
+    public TimeUnit getDurationUnit() {
+        return durationUnit;
+    }
+
+    public void setDurationUnit(TimeUnit durationUnit) {
+        this.durationUnit = durationUnit;
+    }
+
     @Override
     public void onInit(Route route) {
         super.onInit(route);
@@ -118,6 +138,8 @@ public class MetricsRoutePolicy extends RoutePolicySupport {
                 registryService.setUseJmx(isUseJmx());
                 registryService.setJmxDomain(getJmxDomain());
                 registryService.setPrettyPrint(isPrettyPrint());
+                registryService.setRateUnit(getRateUnit());
+                registryService.setDurationUnit(getDurationUnit());
                 route.getRouteContext().getCamelContext().addService(registryService);
             }
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/camel/blob/4769d97f/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicyFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicyFactory.java
b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicyFactory.java
index 584db54..d4ad80d 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicyFactory.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicyFactory.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.metrics.routepolicy;
 
+import java.util.concurrent.TimeUnit;
+
 import com.codahale.metrics.MetricRegistry;
 import org.apache.camel.CamelContext;
 import org.apache.camel.model.RouteDefinition;
@@ -31,6 +33,8 @@ public class MetricsRoutePolicyFactory implements RoutePolicyFactory {
     private boolean useJmx;
     private String jmxDomain = "org.apache.camel.metrics";
     private boolean prettyPrint;
+    private TimeUnit rateUnit = TimeUnit.SECONDS;
+    private TimeUnit durationUnit = TimeUnit.MILLISECONDS;
 
     /**
      * To use a specific {@link com.codahale.metrics.MetricRegistry} instance.
@@ -78,6 +82,28 @@ public class MetricsRoutePolicyFactory implements RoutePolicyFactory {
         this.prettyPrint = prettyPrint;
     }
 
+    public TimeUnit getRateUnit() {
+        return rateUnit;
+    }
+
+    /**
+     * Sets the time unit to use for requests per unit (eg requests per second)
+     */
+    public void setRateUnit(TimeUnit rateUnit) {
+        this.rateUnit = rateUnit;
+    }
+
+    public TimeUnit getDurationUnit() {
+        return durationUnit;
+    }
+
+    /**
+     * Sets the time unit to use for timing the duration of processing a message in the route
+     */
+    public void setDurationUnit(TimeUnit durationUnit) {
+        this.durationUnit = durationUnit;
+    }
+
     @Override
     public RoutePolicy createRoutePolicy(CamelContext camelContext, String routeId, RouteDefinition
routeDefinition) {
         MetricsRoutePolicy answer = new MetricsRoutePolicy();
@@ -85,6 +111,8 @@ public class MetricsRoutePolicyFactory implements RoutePolicyFactory {
         answer.setUseJmx(isUseJmx());
         answer.setJmxDomain(getJmxDomain());
         answer.setPrettyPrint(isPrettyPrint());
+        answer.setRateUnit(getRateUnit());
+        answer.setDurationUnit(getDurationUnit());
         return answer;
     }
 


Mime
View raw message