Listing Camel Routes using JMX and Groovy

The following groovy script can be used to list all Camel routes on a running servicemix. Per route it will display state of the route, and some statistics.

import javax.management.*
import javax.management.remote.*
import javax.lang.management.*

def serverUrl = 'service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root'

def env = [(JMXConnector.CREDENTIALS): ["smx","smx"] as String[]]
def jmxUrl = new JMXServiceURL(serverUrl)
def connect = JMXConnectorFactory.connect(jmxUrl,env) 
def server = connect.MBeanServerConnection

def query = new ObjectName('org.apache.camel:type=routes,*')
def routes = server.queryNames(query,null)
printf "%-30s, %-10s, %7s, %7s, %7s, %7s, %7s, %7s, %7sn", "RouteId", "State", "Ex comp", "Ex Fail", "Ex Tot", "Last T", "Max T", "Mean T", "Total T"
printf "%-30s, %-10s, %7s, %7s, %7s, %7s, %7s, %7s, %7sn", "-------", "-----", "-------", "-------", "------", "------", "-----", "------", "-------"
routes.each { route ->
    def routeBean = new GroovyMBean(server,route)
    printf "%-30s, %-10s, %7s, %7s, %7s, %7s, %7s, %7s, %7sn", 
        routeBean.RouteId, routeBean.State,
        routeBean.ExchangesCompleted, routeBean.ExchangesFailed, routeBean.ExchangesTotal,
        routeBean.LastProcessingTime, routeBean.MaxProcessingTime, routeBean.MeanProcessingTime, routeBean.TotalProcessingTime
}             
blog comments powered by Disqus