This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 9ccda4b9a15 camel-console - Add route console to dump route stats
9ccda4b9a15 is described below
commit 9ccda4b9a15507324e6b2cdd4f264b653b46c9fd
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri May 27 09:36:50 2022 +0200
camel-console - Add route console to dump route stats
---
.../camel/impl/engine/AbstractCamelContext.java | 5 +-
.../services/org/apache/camel/dev-console/route | 2 +
.../camel/impl/console/ContextDevConsole.java | 5 +-
.../apache/camel/impl/console/RouteDevConsole.java | 70 ++++++++++++++++++++++
.../camel/management/mbean/ManagedRoute.java | 2 +-
.../camel/support/RouteWatcherReloadStrategy.java | 5 +-
.../org/apache/camel/main/VertxHttpServer.java | 27 +++++++--
7 files changed, 106 insertions(+), 10 deletions(-)
diff --git
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index bdd9d7d0440..9ca2b73f3c3 100644
---
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -3122,8 +3122,7 @@ public abstract class AbstractCamelContext extends
BaseService
// use basic endpoint uri to not log verbose details or
potential sensitive data
String uri =
order.getRoute().getEndpoint().getEndpointBaseUri();
uri = URISupport.sanitizeUri(uri);
- String loc = order.getRoute().getSourceResource() != null
- ? order.getRoute().getSourceResource().getLocation() :
null;
+ String loc = order.getRoute().getSourceLocation();
if (startupSummaryLevel == StartupSummaryLevel.Verbose && loc
!= null) {
lines.add(String.format(" %s %s (%s) (source: %s)",
status, id, uri, loc));
} else {
@@ -3146,7 +3145,7 @@ public abstract class AbstractCamelContext extends
BaseService
// use basic endpoint uri to not log verbose details or
potential sensitive data
String uri = route.getEndpoint().getEndpointBaseUri();
uri = URISupport.sanitizeUri(uri);
- String loc = route.getSourceResource() != null ?
route.getSourceResource().getLocation() : null;
+ String loc = route.getSourceLocation();
if (startupSummaryLevel == StartupSummaryLevel.Verbose &&
loc != null) {
lines.add(String.format(" %s %s (%s) (source: %s)",
status, id, uri, loc));
} else {
diff --git
a/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/route
b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/route
new file mode 100644
index 00000000000..5df8a7fff46
--- /dev/null
+++
b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/route
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.impl.console.RouteDevConsole
diff --git
a/core/camel-console/src/main/java/org/apache/camel/impl/console/ContextDevConsole.java
b/core/camel-console/src/main/java/org/apache/camel/impl/console/ContextDevConsole.java
index 059d36c1f34..8d8da61e27e 100644
---
a/core/camel-console/src/main/java/org/apache/camel/impl/console/ContextDevConsole.java
+++
b/core/camel-console/src/main/java/org/apache/camel/impl/console/ContextDevConsole.java
@@ -21,6 +21,7 @@ import java.util.Map;
import org.apache.camel.api.management.ManagedCamelContext;
import org.apache.camel.api.management.mbean.ManagedCamelContextMBean;
import org.apache.camel.spi.annotations.DevConsole;
+import org.apache.camel.util.TimeUtils;
@DevConsole("context")
public class ContextDevConsole extends AbstractDevConsole {
@@ -38,13 +39,15 @@ public class ContextDevConsole extends AbstractDevConsole {
getCamelContext().getUptime()));
sb.append("\n");
- // TODO: number of messages should maybe be in another console
ManagedCamelContext mcc =
getCamelContext().getExtension(ManagedCamelContext.class);
if (mcc != null) {
ManagedCamelContextMBean mb = mcc.getManagedCamelContext();
sb.append(String.format("\n Total: %s",
mb.getExchangesTotal()));
sb.append(String.format("\n Failed: %s",
mb.getExchangesFailed()));
sb.append(String.format("\n Inflight: %s",
mb.getExchangesInflight()));
+ sb.append(String.format("\n Mean Time: %s",
TimeUtils.printDuration(mb.getMeanProcessingTime())));
+ sb.append(String.format("\n Max Time: %s",
TimeUtils.printDuration(mb.getMaxProcessingTime())));
+ sb.append(String.format("\n Min Time: %s",
TimeUtils.printDuration(mb.getMinProcessingTime())));
sb.append("\n");
}
diff --git
a/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteDevConsole.java
b/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteDevConsole.java
new file mode 100644
index 00000000000..13fa76d0f6d
--- /dev/null
+++
b/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteDevConsole.java
@@ -0,0 +1,70 @@
+/*
+ * 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.impl.console;
+
+import org.apache.camel.Route;
+import org.apache.camel.api.management.ManagedCamelContext;
+import org.apache.camel.api.management.mbean.ManagedRouteMBean;
+import org.apache.camel.spi.annotations.DevConsole;
+import org.apache.camel.util.TimeUtils;
+
+import java.util.List;
+import java.util.Map;
+
+@DevConsole("route")
+public class RouteDevConsole extends AbstractDevConsole {
+
+ public RouteDevConsole() {
+ super("camel", "route", "Route", "Route information");
+ }
+
+ @Override
+ protected Object doCall(MediaType mediaType, Map<String, Object> options) {
+ // only text is supported
+ StringBuilder sb = new StringBuilder();
+
+ ManagedCamelContext mcc =
getCamelContext().getExtension(ManagedCamelContext.class);
+ if (mcc != null) {
+ List<Route> routes = getCamelContext().getRoutes();
+ routes.sort((o1, o2) ->
o1.getRouteId().compareToIgnoreCase(o2.getRouteId()));
+ for (Route route : routes) {
+ ManagedRouteMBean mrb =
mcc.getManagedRoute(route.getRouteId());
+ if (mrb != null) {
+ if (sb.length() > 0) {
+ sb.append("\n");
+ }
+ sb.append(String.format(" Id: %s", mrb.getRouteId()));
+ if (mrb.getSourceLocation() != null) {
+ sb.append(String.format("\n Source: %s",
mrb.getSourceLocation()));
+ }
+ sb.append(String.format("\n State: %s",
mrb.getState()));
+ sb.append(String.format("\n Uptime: %s",
mrb.getUptime()));
+ sb.append(String.format("\n Total: %s",
mrb.getExchangesTotal()));
+ sb.append(String.format("\n Failed: %s",
mrb.getExchangesFailed()));
+ sb.append(String.format("\n Inflight: %s",
mrb.getExchangesInflight()));
+ sb.append(String.format("\n Mean Time: %s",
TimeUtils.printDuration(mrb.getMeanProcessingTime())));
+ sb.append(String.format("\n Max Time: %s",
TimeUtils.printDuration(mrb.getMaxProcessingTime())));
+ sb.append(String.format("\n Min Time: %s",
TimeUtils.printDuration(mrb.getMinProcessingTime())));
+ sb.append("\n");
+ }
+ }
+ }
+
+ return sb.toString();
+ }
+
+}
diff --git
a/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
b/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
index 436bc8f73fc..0e4eae57b31 100644
---
a/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
+++
b/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
@@ -82,7 +82,7 @@ public class ManagedRoute extends ManagedPerformanceCounter
implements TimerList
this.context = context;
this.description = route.getDescription();
this.configurationId = route.getConfigurationId();
- this.sourceLocation = route.getSourceResource() != null ?
route.getSourceResource().getLocation() : null;
+ this.sourceLocation = route.getSourceLocation();
this.jmxDomain =
context.getManagementStrategy().getManagementAgent().getMBeanObjectDomainName();
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
b/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
index c4c663a1a7e..8fe7c04fd0f 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
@@ -241,7 +241,10 @@ public class RouteWatcherReloadStrategy extends
FileWatcherResourceReloadStrateg
// use basic endpoint uri to not log verbose details or
potential sensitive data
String uri = route.getEndpoint().getEndpointBaseUri();
uri = URISupport.sanitizeUri(uri);
- String loc = route.getSourceResource() != null ?
route.getSourceResource().getLocation() : "";
+ String loc = route.getSourceLocation();
+ if (loc == null) {
+ loc = "";
+ }
lines.add(String.format(" %s %s (%s) (source: %s)",
status, id, uri, loc));
}
LOG.info(String.format("Routes reloaded summary (total:%s
started:%s)", total, started));
diff --git
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
index 168ae5a81c6..432f9804ea1 100644
---
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
+++
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
@@ -20,6 +20,7 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -164,16 +165,31 @@ public final class VertxHttpServer {
Route dev = router.route("/q/dev");
dev.method(HttpMethod.GET);
dev.produces("text/plain");
- dev.handler(new Handler<RoutingContext>() {
+ Route devSub = router.route("/q/dev/:id");
+ devSub.method(HttpMethod.GET);
+ devSub.produces("text/plain");
+
+ Handler<RoutingContext> handler = new Handler<RoutingContext>() {
@Override
public void handle(RoutingContext ctx) {
+ String id = ctx.pathParam("id");
+
ctx.response().putHeader("content-type", "text/plain");
DevConsoleRegistry dcr =
context.getExtension(DevConsoleRegistry.class);
if (dcr != null && dcr.isEnabled()) {
StringBuilder sb = new StringBuilder();
- dcr.stream().forEach(c -> {
- if (c.supportMediaType(DevConsole.MediaType.TEXT)) {
+ // sort according to index by given id
+ dcr.stream().sorted((o1, o2) -> {
+ if (id == null) {
+ return 0;
+ }
+ int p1 = id.indexOf(o1.getId());
+ int p2 = id.indexOf(o2.getId());
+ return Integer.compare(p1, p2);
+ }).forEach(c -> {
+ boolean include = id == null || id.contains(c.getId());
+ if (include &&
c.supportMediaType(DevConsole.MediaType.TEXT)) {
String text = (String)
c.call(DevConsole.MediaType.TEXT);
if (text != null) {
sb.append(c.getDisplayName()).append(":");
@@ -192,7 +208,10 @@ public final class VertxHttpServer {
ctx.end("Developer Console is not enabled");
}
}
- });
+ };
+ dev.handler(handler);
+ devSub.handler(handler);
+
phc.addHttpEndpoint("/q/dev", null);
}