Thanks, Raymond!  That did it.  I think perhaps the documentation available
to the AIs results in them proposing approaches that don't work, but I
don't have enough knowledge to know why what they propose doesn't work...
Anyway, thanks again.  PluginHelper helps.

On Mon, Apr 28, 2025 at 11:16 AM ski n <raymondmees...@gmail.com> wrote:

> Hi,
>
> I get stats like this:
>
> ManagedCamelContext managed =
>
> context.getCamelContextExtension().getContextPlugin(ManagedCamelContext.class);
> ManagedRouteMBean route = managed.getManagedRoute(routeId);
>
> totalMessages = route.getExchangesTotal();
> completedMessages = route.getExchangesCompleted();
> failedMessages = route.getExchangesFailed();
> inflightMessages = route.getExchangesInflight();
>
> Hope this helps.
>
> Raymond
>
> On Mon, Apr 28, 2025 at 6:40 PM Mitch Trachtenberg <mjt...@gmail.com>
> wrote:
>
> > I am using Apache Camel 4.10.0 with Spring Boot. I'm able to retrieve
> route
> > statistics via jconsole and via a prometheus endpoint, but not by the
> > managed bean functions.  I've tried a variety of approaches.  My pom
> > includes camel-management at 4.10.0 and camel-micrometer-starter and
> > micrometer-registry-prometheus.  Any and all suggestions welcome, and if
> > this is a known issue please let me know.
> >
> > This call, which is basically from ChatGPT and Gemini after some back and
> > forth insisting that certain proposed methods were not present in 4.10,
> > always returns zero. Please forgive my added System.out.printlns:
> >     public long getCompletedExchanges(Route r) {
> >         try {
> >              ManagementStrategy managementStrategy =
> > camelContext.getManagementStrategy();
> >             ManagementObjectStrategy objectStrategy =
> > managementStrategy.getManagementObjectStrategy();
> >    System.out.println(managementStrategy);
> >    System.out.println(objectStrategy);
> >             ManagedRouteMBean routeMBean = (ManagedRouteMBean)
> > objectStrategy.getManagedObjectForRoute(camelContext, r);
> >    System.out.println(routeMBean);
> >    System.out.println(routeMBean.getExchangesTotal());
> >             if (routeMBean != null) {
> >                  return routeMBean.getExchangesTotal();
> >             } else {
> >                 return -1;
> >             }
> >         } catch (Exception e) {
> >             e.printStackTrace();
> >             return -1;
> >         }
> >     }
> > Stdout gets:
> > org.apache.camel.management.JmxManagementStrategy@7f68ba0
> > org.apache.camel.management.DefaultManagementObjectStrategy@42f4153a
> > org.apache.camel.management.mbean.ManagedSuspendableRoute@765776bf
> > 0
> >
> > My /actuator/prometheus shows:
> >
> >
> >
> camel_exchanges_total{camelContext="MyCamel",eventType="context",kind="CamelRoute",routeId="",}
> > 68.0
> >
> >
> camel_exchanges_total{camelContext="MyCamel",eventType="route",kind="CamelRoute",routeId="log-routename-every-two-seconds",}
> > 68.0
> >
> > Jconsole also shows the count(s) properly.
> >
> > I call the method immediately prior to stopping a route about to be
> > stopped, and the route is successfully stopped after the function returns
> > 0:
> > LOG.warn("In stopRoute via /routes/.../stop");
> >
> >
> LOG.warn(String.valueOf(ris.getCompletedExchanges(camelContext.getRoute(routeId))));
> >         try {
> >             camelContext.getRouteController().stopRoute(routeId);
> >
> > Relevant parts of my application's yaml configuration:
> >
> > management:
> >   endpoints:
> >     web:
> >       exposure:
> >         include:
> >           - "prometheus"
> >           - "camelroutes"
> >           - "metrics"
> >     metrics:
> >       enabled: true
> > camel:
> >   main:
> >     routes-builder-loader-ignore-loading-error: false
> >   management:
> >     enabled: true
> >     jmxAgent: true
> >     jmx:
> >       statistic-enabled: true
> >       statistics-enabled: true
> > #  micrometer:
> > #    enabled: false #true
> > #    route-metrics: false #true
> >
>

Reply via email to