You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/12/14 14:12:12 UTC

[camel] branch main updated: CAMEL-17332: camel-management - Dump stats with source location/line number

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 c1ab057  CAMEL-17332: camel-management - Dump stats with source location/line number
c1ab057 is described below

commit c1ab0573ae2d2fdcbf693e780d43de07981540ec
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Dec 14 15:11:24 2021 +0100

    CAMEL-17332: camel-management - Dump stats with source location/line number
---
 .../management/mbean/ManagedCamelContext.java      | 28 +++++++++++++++-------
 .../camel/management/mbean/ManagedRoute.java       | 19 +++++++++++----
 2 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java b/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
index 6dabc6d..9ed0a37 100644
--- a/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
+++ b/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
@@ -524,6 +524,10 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti
                         = context.getManagementStrategy().getManagementAgent().newProxyClient(on, ManagedRouteMBean.class);
                 sb.append("    <routeStat")
                         .append(String.format(" id=\"%s\" state=\"%s\"", route.getRouteId(), route.getState()));
+                if (route.getSourceLocation() != null) {
+                    sb.append(String.format(" sourceLocation=\"%s\"", route.getSourceLocation()));
+                }
+
                 // use substring as we only want the attributes
                 stat = route.dumpStatsAsXml(fullStats);
                 sb.append(" exchangesInflight=\"").append(route.getExchangesInflight()).append("\"");
@@ -533,10 +537,12 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti
                 if (includeProcessors) {
                     sb.append("      <processorStats>\n");
                     for (ManagedProcessorMBean processor : processors) {
+                        int line = processor.getSourceLineNumber() != null ? processor.getSourceLineNumber() : -1;
                         // the processor must belong to this route
                         if (route.getRouteId().equals(processor.getRouteId())) {
-                            sb.append("        <processorStat").append(String.format(" id=\"%s\" index=\"%s\" state=\"%s\"",
-                                    processor.getProcessorId(), processor.getIndex(), processor.getState()));
+                            sb.append("        <processorStat")
+                                    .append(String.format(" id=\"%s\" index=\"%s\" state=\"%s\" sourceLineNumber=\"%s\"",
+                                            processor.getProcessorId(), processor.getIndex(), processor.getState(), line));
                             // use substring as we only want the attributes
                             stat = processor.dumpStatsAsXml(fullStats);
                             sb.append(" exchangesInflight=\"").append(processor.getExchangesInflight()).append("\"");
@@ -590,6 +596,10 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti
                         = context.getManagementStrategy().getManagementAgent().newProxyClient(on, ManagedRouteMBean.class);
                 sb.append("    <routeStat")
                         .append(String.format(" id=\"%s\" state=\"%s\"", route.getRouteId(), route.getState()));
+                if (route.getSourceLocation() != null) {
+                    sb.append(String.format(" sourceLocation=\"%s\"", route.getSourceLocation()));
+                }
+
                 // use substring as we only want the attributes
                 stat = route.dumpStatsAsXml(fullStats);
                 sb.append(" exchangesInflight=\"").append(route.getExchangesInflight()).append("\"");
@@ -597,14 +607,16 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti
 
                 // add steps details if needed
                 sb.append("      <stepStats>\n");
-                for (ManagedProcessorMBean processor : steps) {
+                for (ManagedProcessorMBean step : steps) {
                     // the step must belong to this route
-                    if (route.getRouteId().equals(processor.getRouteId())) {
-                        sb.append("        <stepStat").append(String.format(" id=\"%s\" index=\"%s\" state=\"%s\"",
-                                processor.getProcessorId(), processor.getIndex(), processor.getState()));
+                    if (route.getRouteId().equals(step.getRouteId())) {
+                        int line = step.getSourceLineNumber() != null ? step.getSourceLineNumber() : -1;
+                        sb.append("        <stepStat")
+                                .append(String.format(" id=\"%s\" index=\"%s\" state=\"%s\" sourceLineNumber=\"%s\"",
+                                        step.getProcessorId(), step.getIndex(), step.getState(), line));
                         // use substring as we only want the attributes
-                        stat = processor.dumpStatsAsXml(fullStats);
-                        sb.append(" exchangesInflight=\"").append(processor.getExchangesInflight()).append("\"");
+                        stat = step.dumpStatsAsXml(fullStats);
+                        sb.append(" exchangesInflight=\"").append(step.getExchangesInflight()).append("\"");
                         sb.append(" ").append(stat, 7, stat.length()).append("\n");
                     }
                     sb.append("      </stepStats>\n");
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 c022566..b53524c 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
@@ -452,8 +452,10 @@ public class ManagedRoute extends ManagedPerformanceCounter implements TimerList
 
                 // and now add the sorted list of processors to the xml output
                 for (ManagedProcessorMBean processor : mps) {
-                    sb.append("    <processorStat").append(String.format(" id=\"%s\" index=\"%s\" state=\"%s\"",
-                            processor.getProcessorId(), processor.getIndex(), processor.getState()));
+                    int line = processor.getSourceLineNumber() != null ? processor.getSourceLineNumber() : -1;
+                    sb.append("    <processorStat")
+                            .append(String.format(" id=\"%s\" index=\"%s\" state=\"%s\" sourceLineNumber=\"%s\"",
+                                    processor.getProcessorId(), processor.getIndex(), processor.getState(), line));
                     // do we have an accumulated time then append that
                     Long accTime = accumulatedTimes.get(processor.getProcessorId());
                     if (accTime != null) {
@@ -476,6 +478,9 @@ public class ManagedRoute extends ManagedPerformanceCounter implements TimerList
         StringBuilder answer = new StringBuilder();
         answer.append("<routeStat").append(String.format(" id=\"%s\"", route.getId()))
                 .append(String.format(" state=\"%s\"", getState()));
+        if (sourceLocation != null) {
+            answer.append(String.format(" sourceLocation=\"%s\"", getSourceLocation()));
+        }
         // use substring as we only want the attributes
         String stat = dumpStatsAsXml(fullStats);
         answer.append(" exchangesInflight=\"").append(getInflightExchanges()).append("\"");
@@ -528,8 +533,11 @@ public class ManagedRoute extends ManagedPerformanceCounter implements TimerList
 
             // and now add the sorted list of steps to the xml output
             for (ManagedStepMBean step : mps) {
-                sb.append("    <stepStat").append(String.format(" id=\"%s\" index=\"%s\" state=\"%s\"", step.getProcessorId(),
-                        step.getIndex(), step.getState()));
+                int line = step.getSourceLineNumber() != null ? step.getSourceLineNumber() : -1;
+                sb.append("    <stepStat")
+                        .append(String.format(" id=\"%s\" index=\"%s\" state=\"%s\" sourceLineNumber=\"%s\"",
+                                step.getProcessorId(),
+                                step.getIndex(), step.getState(), line));
                 // use substring as we only want the attributes
                 sb.append(" ").append(step.dumpStatsAsXml(fullStats).substring(7)).append("\n");
             }
@@ -539,6 +547,9 @@ public class ManagedRoute extends ManagedPerformanceCounter implements TimerList
         StringBuilder answer = new StringBuilder();
         answer.append("<routeStat").append(String.format(" id=\"%s\"", route.getId()))
                 .append(String.format(" state=\"%s\"", getState()));
+        if (sourceLocation != null) {
+            answer.append(String.format(" sourceLocation=\"%s\"", getSourceLocation()));
+        }
         // use substring as we only want the attributes
         String stat = dumpStatsAsXml(fullStats);
         answer.append(" exchangesInflight=\"").append(getInflightExchanges()).append("\"");