camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] git commit: CAMEL-6419: Added stats action to controlbus component to get performance stats easily.
Date Mon, 03 Jun 2013 17:49:14 GMT
Updated Branches:
  refs/heads/camel-2.11.x 8bc42394f -> ed4d2a3a0
  refs/heads/master 5b942e3e4 -> 8b84f6863


CAMEL-6419: Added stats action to controlbus component to get performance stats easily.


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

Branch: refs/heads/camel-2.11.x
Commit: ed4d2a3a0e6dbacb21a12acabd0e682a599e313d
Parents: 8bc4239
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Jun 3 19:48:04 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Jun 3 19:48:04 2013 +0200

----------------------------------------------------------------------
 .../component/controlbus/ControlBusProducer.java   |   31 ++++++
 .../component/controlbus/ControlBusStatsTest.java  |   78 +++++++++++++++
 2 files changed, 109 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ed4d2a3a/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusProducer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusProducer.java
b/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusProducer.java
index 6a8bd65..78a262a 100644
--- a/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusProducer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusProducer.java
@@ -16,11 +16,17 @@
  */
 package org.apache.camel.component.controlbus;
 
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
 import org.apache.camel.AsyncCallback;
+import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
+import org.apache.camel.Route;
 import org.apache.camel.ServiceStatus;
+import org.apache.camel.api.management.mbean.ManagedCamelContextMBean;
 import org.apache.camel.impl.DefaultAsyncProducer;
 import org.apache.camel.spi.Language;
 import org.apache.camel.util.CamelLogger;
@@ -156,6 +162,31 @@ public class ControlBusProducer extends DefaultAsyncProducer {
                     if (status != null) {
                         result = status.name();
                     }
+                } else if ("stats".equals(action)) {
+
+                    // camel context or per route
+                    String name = getEndpoint().getCamelContext().getManagementName();
+                    if (name == null) {
+                        result = "JMX is disabled, cannot get stats";
+                    } else {
+                        ObjectName on;
+                        String operation;
+                        if (id == null) {
+                            CamelContext camelContext = getEndpoint().getCamelContext();
+                            on = getEndpoint().getCamelContext().getManagementStrategy().getManagementNamingStrategy().getObjectNameForCamelContext(camelContext);
+                            operation = "dumpRoutesStatsAsXml";
+                        } else {
+                            Route route = getEndpoint().getCamelContext().getRoute(id);
+                            on = getEndpoint().getCamelContext().getManagementStrategy().getManagementNamingStrategy().getObjectNameForRoute(route);
+                            operation = "dumpRouteStatsAsXml";
+                        }
+                        if (on != null) {
+                            MBeanServer server = getEndpoint().getCamelContext().getManagementStrategy().getManagementAgent().getMBeanServer();
+                            result = server.invoke(on, operation, new Object[]{true, true},
new String[]{"boolean", "boolean"});
+                        } else {
+                            result = "Cannot lookup route with id " + id;
+                        }
+                    }
                 }
 
                 if (result != null && !getEndpoint().isAsync()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/ed4d2a3a/camel-core/src/test/java/org/apache/camel/component/controlbus/ControlBusStatsTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/controlbus/ControlBusStatsTest.java
b/camel-core/src/test/java/org/apache/camel/component/controlbus/ControlBusStatsTest.java
new file mode 100644
index 0000000..20b100b
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/controlbus/ControlBusStatsTest.java
@@ -0,0 +1,78 @@
+/**
+ * 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.controlbus;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ *
+ */
+public class ControlBusStatsTest extends ContextTestSupport {
+
+    @Override
+    protected boolean useJmx() {
+        return true;
+    }
+
+    public void testControlBusRouteStat() throws Exception {
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+
+        template.sendBody("direct:foo", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        String xml = template.requestBody("controlbus:route?routeId=foo&action=stats",
null, String.class);
+        assertNotNull(xml);
+
+        assertTrue(xml.contains("routeStat"));
+        assertTrue(xml.contains("processorStat"));
+        assertTrue(xml.contains("id=\"foo\""));
+        assertTrue(xml.contains("exchangesCompleted=\"1\""));
+    }
+
+    public void testControlBusContextStat() throws Exception {
+        getMockEndpoint("mock:bar").expectedBodiesReceived("Hello World");
+
+        template.sendBody("direct:bar", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        String xml = template.requestBody("controlbus:route?action=stats", null, String.class);
+        assertNotNull(xml);
+
+        assertTrue(xml.contains("camelContextStat"));
+        assertTrue(xml.contains("routeStat"));
+        assertTrue(xml.contains("processorStat"));
+        assertTrue(xml.contains("id=\"bar\""));
+        assertTrue(xml.contains("id=\"foo\""));
+        assertTrue(xml.contains("exchangesCompleted=\"1\""));
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:foo").routeId("foo")
+                    .to("mock:foo");
+
+                from("direct:bar").routeId("bar")
+                    .to("mock:bar");
+            }
+        };
+    }
+}


Mime
View raw message