camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-9014: More endpoint usage statitics on the runtime endpoint mbean
Date Mon, 27 Jul 2015 08:37:15 GMT
Repository: camel
Updated Branches:
  refs/heads/master 1ceb5c70d -> e20760513


CAMEL-9014: More endpoint usage statitics on the runtime endpoint mbean


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

Branch: refs/heads/master
Commit: 3ab2cd64a12354ac4648ee6e73fa7d46f775a085
Parents: 1ceb5c7
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Jul 27 10:30:33 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Jul 27 10:30:33 2015 +0200

----------------------------------------------------------------------
 .../management/mbean/CamelOpenMBeanTypes.java   |  6 +-
 .../impl/DefaultRuntimeEndpointRegistry.java    | 71 ++++++++++++++++++--
 .../mbean/ManagedRuntimeEndpointRegistry.java   |  5 +-
 3 files changed, 73 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3ab2cd64/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
index 093d794..71f32f9 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
@@ -72,9 +72,9 @@ public final class CamelOpenMBeanTypes {
     }
 
     public static CompositeType listRuntimeEndpointsCompositeType() throws OpenDataException
{
-        return new CompositeType("endpoints", "Endpoints", new String[]{"index", "url", "routeId",
"direction", "static", "dynamic"},
-                new String[]{"Index", "Url", "Route Id", "Direction", "Static", "Dynamic"},
-                new OpenType[]{SimpleType.INTEGER, SimpleType.STRING, SimpleType.STRING,
SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN});
+        return new CompositeType("endpoints", "Endpoints", new String[]{"index", "url", "routeId",
"direction", "static", "dynamic", "hits"},
+                new String[]{"Index", "Url", "Route Id", "Direction", "Static", "Dynamic",
"Hits"},
+                new OpenType[]{SimpleType.INTEGER, SimpleType.STRING, SimpleType.STRING,
SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN, SimpleType.LONG});
     }
 
     public static TabularType explainComponentTabularType() throws OpenDataException {

http://git-wip-us.apache.org/repos/asf/camel/blob/3ab2cd64/camel-core/src/main/java/org/apache/camel/impl/DefaultRuntimeEndpointRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultRuntimeEndpointRegistry.java
b/camel-core/src/main/java/org/apache/camel/impl/DefaultRuntimeEndpointRegistry.java
index bf8a276..9d1fed0 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultRuntimeEndpointRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultRuntimeEndpointRegistry.java
@@ -25,24 +25,43 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
+import org.apache.camel.management.event.ExchangeCreatedEvent;
 import org.apache.camel.management.event.ExchangeSendingEvent;
 import org.apache.camel.management.event.RouteAddedEvent;
 import org.apache.camel.management.event.RouteRemovedEvent;
+import org.apache.camel.spi.EndpointUtilizationStatistics;
 import org.apache.camel.spi.RouteContext;
 import org.apache.camel.spi.RuntimeEndpointRegistry;
 import org.apache.camel.spi.UnitOfWork;
 import org.apache.camel.support.EventNotifierSupport;
 import org.apache.camel.util.LRUCache;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ServiceHelper;
 
-public class DefaultRuntimeEndpointRegistry extends EventNotifierSupport implements RuntimeEndpointRegistry
{
+public class DefaultRuntimeEndpointRegistry extends EventNotifierSupport implements CamelContextAware,
RuntimeEndpointRegistry {
+
+    private CamelContext camelContext;
 
     // route id -> endpoint urls
     private Map<String, Set<String>> inputs;
     private Map<String, Map<String, String>> outputs;
     private int limit = 1000;
     private boolean enabled = true;
+    private boolean extended;
+    private EndpointUtilizationStatistics inputUtilization;
+    private EndpointUtilizationStatistics outputUtilization;
+
+    public CamelContext getCamelContext() {
+        return camelContext;
+    }
+
+    public void setCamelContext(CamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
 
     public boolean isEnabled() {
         return enabled;
@@ -90,7 +109,14 @@ public class DefaultRuntimeEndpointRegistry extends EventNotifierSupport
impleme
         for (Map.Entry<String, Set<String>> entry : inputs.entrySet()) {
             String routeId = entry.getKey();
             for (String uri : entry.getValue()) {
-                answer.add(new EndpointRuntimeStatistics(uri, routeId, "in", 0));
+                Long hits = 0L;
+                if (extended) {
+                    hits = inputUtilization.getStatistics().get(uri);
+                    if (hits == null) {
+                        hits = 0L;
+                    }
+                }
+                answer.add(new EndpointRuntimeStatistics(uri, routeId, "in", hits));
             }
         }
 
@@ -98,7 +124,14 @@ public class DefaultRuntimeEndpointRegistry extends EventNotifierSupport
impleme
         for (Map.Entry<String, Map<String, String>> entry : outputs.entrySet())
{
             String routeId = entry.getKey();
             for (String uri : entry.getValue().keySet()) {
-                answer.add(new EndpointRuntimeStatistics(uri, routeId, "out", 0));
+                Long hits = 0L;
+                if (extended) {
+                    hits = outputUtilization.getStatistics().get(uri);
+                    if (hits == null) {
+                        hits = 0L;
+                    }
+                }
+                answer.add(new EndpointRuntimeStatistics(uri, routeId, "out", hits));
             }
         }
 
@@ -119,6 +152,12 @@ public class DefaultRuntimeEndpointRegistry extends EventNotifierSupport
impleme
     public void clear() {
         inputs.clear();
         outputs.clear();
+        if (inputUtilization != null) {
+            inputUtilization.clear();
+        }
+        if (outputUtilization != null) {
+            outputUtilization.clear();
+        }
     }
 
     @Override
@@ -130,17 +169,28 @@ public class DefaultRuntimeEndpointRegistry extends EventNotifierSupport
impleme
 
     @Override
     protected void doStart() throws Exception {
+        ObjectHelper.notNull(camelContext, "camelContext", this);
+
         if (inputs == null) {
             inputs = new HashMap<String, Set<String>>();
         }
         if (outputs == null) {
             outputs = new HashMap<String, Map<String, String>>();
         }
+        if (getCamelContext().getManagementStrategy().getManagementAgent() != null) {
+            extended = getCamelContext().getManagementStrategy().getManagementAgent().getStatisticsLevel().isExtended();
+        }
+        if (extended) {
+            inputUtilization = new DefaultEndpointUtilizationStatistics(limit);
+            outputUtilization = new DefaultEndpointUtilizationStatistics(limit);
+        }
+        ServiceHelper.startServices(inputUtilization, outputUtilization);
     }
 
     @Override
     protected void doStop() throws Exception {
         clear();
+        ServiceHelper.stopServices(inputUtilization, outputUtilization);
     }
 
     @Override
@@ -162,6 +212,15 @@ public class DefaultRuntimeEndpointRegistry extends EventNotifierSupport
impleme
             String routeId = rse.getRoute().getId();
             inputs.remove(routeId);
             outputs.remove(routeId);
+            if (extended) {
+                String uri = rse.getRoute().getEndpoint().getEndpointUri();
+                inputUtilization.remove(uri);
+            }
+        } else if (extended && event instanceof ExchangeCreatedEvent) {
+            ExchangeCreatedEvent ece = (ExchangeCreatedEvent) event;
+            Endpoint endpoint = ece.getExchange().getFromEndpoint();
+            String uri = endpoint.getEndpointUri();
+            inputUtilization.onHit(uri);
         } else {
             ExchangeSendingEvent ese = (ExchangeSendingEvent) event;
             Endpoint endpoint = ese.getEndpoint();
@@ -172,6 +231,9 @@ public class DefaultRuntimeEndpointRegistry extends EventNotifierSupport
impleme
             if (uris != null && !uris.containsKey(uri)) {
                 uris.put(uri, uri);
             }
+            if (extended) {
+                outputUtilization.onHit(uri);
+            }
         }
     }
 
@@ -191,7 +253,8 @@ public class DefaultRuntimeEndpointRegistry extends EventNotifierSupport
impleme
 
     @Override
     public boolean isEnabled(EventObject event) {
-        return enabled && event instanceof ExchangeSendingEvent
+        return enabled && event instanceof ExchangeCreatedEvent
+                || event instanceof ExchangeSendingEvent
                 || event instanceof RouteAddedEvent
                 || event instanceof RouteRemovedEvent;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/3ab2cd64/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRuntimeEndpointRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRuntimeEndpointRegistry.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRuntimeEndpointRegistry.java
index 0679047..de589d6 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRuntimeEndpointRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRuntimeEndpointRegistry.java
@@ -103,9 +103,10 @@ public class ManagedRuntimeEndpointRegistry extends ManagedService implements
Ma
                 }
                 String routeId = stat.getRouteId();
                 String direction = stat.getDirection();
+                long hits = stat.getHits();
 
-                CompositeData data = new CompositeDataSupport(ct, new String[]{"index", "url",
"routeId", "direction", "static", "dynamic"},
-                        new Object[]{index, url, routeId, direction, isStatic, isDynamic});
+                CompositeData data = new CompositeDataSupport(ct, new String[]{"index", "url",
"routeId", "direction", "static", "dynamic", "hits"},
+                        new Object[]{index, url, routeId, direction, isStatic, isDynamic,
hits});
                 answer.put(data);
 
                 // use a counter as the single index in the TabularData as we do not want
a multi-value index


Mime
View raw message