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