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 Fri, 15 Aug 2014 10:40:31 GMT
Repository: camel
Updated Branches:
  refs/heads/master 95c6c773e -> 718d76779


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

Branch: refs/heads/master
Commit: 718d7677919b09536a30ee17c559a9c46577dd90
Parents: 95c6c77
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Aug 15 12:40:09 2014 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Aug 15 12:40:09 2014 +0200

----------------------------------------------------------------------
 .../metrics/routepolicy/MetricsRoutePolicy.java | 33 +++++++-------------
 .../routepolicy/MetricsRoutePolicyFactory.java  | 33 ++++++++++++++++++++
 .../routepolicy/MetricsRoutePolicyTest.java     |  7 ++---
 3 files changed, 48 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/718d7677/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 ef1a60e..d640611 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,9 +16,6 @@
  */
 package org.apache.camel.component.metrics.routepolicy;
 
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
 import com.codahale.metrics.Counter;
 import com.codahale.metrics.Meter;
 import com.codahale.metrics.Timer;
@@ -35,12 +32,11 @@ import org.apache.camel.util.ObjectHelper;
 public class MetricsRoutePolicy extends RoutePolicySupport {
 
     // TODO: allow to configure which counters/meters/timers to capture
-    // TODO: allow to configur the reporer and jmx domain etc on MetricsRegistryService
-    // TODO: RoutePolicyFactory to make this configurable once and apply automatic for all
routes
+    // TODO: allow to configure the reporter and jmx domain etc on MetricsRegistryService
     // TODO: allow to lookup and get hold of com.codahale.metrics.MetricRegistry from java
api
 
     private MetricsRegistryService registry;
-    private final ConcurrentMap<Route, MetricsStatistics> statistics = new ConcurrentHashMap<Route,
MetricsStatistics>();
+    private MetricsStatistics statistics;
     private Route route;
 
     private static final class MetricsStatistics {
@@ -90,15 +86,12 @@ public class MetricsRoutePolicy extends RoutePolicySupport {
             throw ObjectHelper.wrapRuntimeCamelException(e);
         }
 
-        MetricsStatistics stats = statistics.get(route);
-        if (stats == null) {
-            Counter total = registry.getRegistry().counter(createName("total"));
-            Counter inflight = registry.getRegistry().counter(createName("inflight"));
-            Meter requests = registry.getRegistry().meter(createName("requests"));
-            Timer responses = registry.getRegistry().timer(createName("responses"));
-            stats = new MetricsStatistics(total, inflight, requests, responses);
-            statistics.putIfAbsent(route, stats);
-        }
+        // create statistics holder
+        Counter total = registry.getRegistry().counter(createName("total"));
+        Counter inflight = registry.getRegistry().counter(createName("inflight"));
+        Meter requests = registry.getRegistry().meter(createName("requests"));
+        Timer responses = registry.getRegistry().timer(createName("responses"));
+        statistics = new MetricsStatistics(total, inflight, requests, responses);
     }
 
     private String createName(String type) {
@@ -107,17 +100,15 @@ public class MetricsRoutePolicy extends RoutePolicySupport {
 
     @Override
     public void onExchangeBegin(Route route, Exchange exchange) {
-        MetricsStatistics stats = statistics.get(route);
-        if (stats != null) {
-            stats.onExchangeBegin(exchange);
+        if (statistics != null) {
+            statistics.onExchangeBegin(exchange);
         }
     }
 
     @Override
     public void onExchangeDone(Route route, Exchange exchange) {
-        MetricsStatistics stats = statistics.get(route);
-        if (stats != null) {
-            stats.onExchangeDone(exchange);
+        if (statistics != null) {
+            statistics.onExchangeDone(exchange);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/718d7677/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
new file mode 100644
index 0000000..b354225
--- /dev/null
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicyFactory.java
@@ -0,0 +1,33 @@
+/**
+ * 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 org.apache.camel.component.metrics.routepolicy;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.spi.RoutePolicy;
+import org.apache.camel.spi.RoutePolicyFactory;
+
+/**
+ * A {@link org.apache.camel.spi.RoutePolicyFactory} to plugin and use metrics for gathering
route utilization statistics
+ */
+public class MetricsRoutePolicyFactory implements RoutePolicyFactory {
+
+    @Override
+    public RoutePolicy createRoutePolicy(CamelContext camelContext, String routeId, RouteDefinition
routeDefinition) {
+        return new MetricsRoutePolicy();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/718d7677/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicyTest.java
b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicyTest.java
index 8903131..95a4ad4 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicyTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicyTest.java
@@ -17,7 +17,6 @@
 package org.apache.camel.component.metrics.routepolicy;
 
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.spi.RoutePolicy;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
@@ -50,13 +49,13 @@ public class MetricsRoutePolicyTest extends CamelTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                RoutePolicy policy = new MetricsRoutePolicy();
+                context.addRoutePolicyFactory(new MetricsRoutePolicyFactory());
 
-                from("seda:foo").routeId("foo").routePolicy(policy)
+                from("seda:foo").routeId("foo")
                     .delayer(100)
                     .to("mock:result");
 
-                from("seda:bar").routeId("bar").routePolicy(policy)
+                from("seda:bar").routeId("bar")
                     .delayer(250)
                     .to("mock:result");
             }


Mime
View raw message