Search in sources :

Example 6 with ManagementAgent

use of org.apache.camel.spi.ManagementAgent in project camel by apache.

the class AbstractLocalCamelController method resetRouteStats.

public void resetRouteStats(String camelContextName) throws Exception {
    CamelContext context = this.getLocalCamelContext(camelContextName);
    if (context == null) {
        return;
    }
    ManagementAgent agent = context.getManagementStrategy().getManagementAgent();
    if (agent != null) {
        MBeanServer mBeanServer = agent.getMBeanServer();
        // reset route mbeans
        ObjectName query = ObjectName.getInstance(agent.getMBeanObjectDomainName() + ":type=routes,*");
        Set<ObjectName> set = mBeanServer.queryNames(query, null);
        for (ObjectName routeMBean : set) {
            String camelId = (String) mBeanServer.getAttribute(routeMBean, "CamelId");
            if (camelId != null && camelId.equals(context.getName())) {
                mBeanServer.invoke(routeMBean, "reset", new Object[] { true }, new String[] { "boolean" });
            }
        }
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) ManagementAgent(org.apache.camel.spi.ManagementAgent) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 7 with ManagementAgent

use of org.apache.camel.spi.ManagementAgent in project camel by apache.

the class AbstractLocalCamelController method browseInflightExchanges.

@SuppressWarnings("unchecked")
public List<Map<String, Object>> browseInflightExchanges(String camelContextName, String route, int limit, boolean sortByLongestDuration) throws Exception {
    CamelContext context = this.getLocalCamelContext(camelContextName);
    if (context == null) {
        return null;
    }
    List<Map<String, Object>> answer = new ArrayList<Map<String, Object>>();
    ManagementAgent agent = context.getManagementStrategy().getManagementAgent();
    if (agent != null) {
        MBeanServer mBeanServer = agent.getMBeanServer();
        ObjectName on = new ObjectName(agent.getMBeanObjectDomainName() + ":type=services,name=DefaultInflightRepository,context=" + context.getManagementName());
        if (mBeanServer.isRegistered(on)) {
            TabularData list = (TabularData) mBeanServer.invoke(on, "browse", new Object[] { route, limit, sortByLongestDuration }, new String[] { "java.lang.String", "int", "boolean" });
            Collection<CompositeData> values = (Collection<CompositeData>) list.values();
            for (CompositeData data : values) {
                Map<String, Object> row = new LinkedHashMap<String, Object>();
                Object exchangeId = data.get("exchangeId");
                if (exchangeId != null) {
                    row.put("exchangeId", exchangeId);
                }
                Object fromRouteId = data.get("fromRouteId");
                if (fromRouteId != null) {
                    row.put("fromRouteId", fromRouteId);
                }
                Object routeId = data.get("routeId");
                if (routeId != null) {
                    row.put("routeId", routeId);
                }
                Object nodeId = data.get("nodeId");
                if (nodeId != null) {
                    row.put("nodeId", nodeId);
                }
                Object elapsed = data.get("elapsed");
                if (elapsed != null) {
                    row.put("elapsed", elapsed);
                }
                Object duration = data.get("duration");
                if (duration != null) {
                    row.put("duration", duration);
                }
                answer.add(row);
            }
        }
    }
    return answer;
}
Also used : CamelContext(org.apache.camel.CamelContext) ManagementAgent(org.apache.camel.spi.ManagementAgent) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData) LinkedHashMap(java.util.LinkedHashMap) Collection(java.util.Collection) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MBeanServer(javax.management.MBeanServer)

Example 8 with ManagementAgent

use of org.apache.camel.spi.ManagementAgent in project camel by apache.

the class JmxInstrumentationWithConnectorTest method testJmxConfiguration.

public void testJmxConfiguration() throws Exception {
    ManagementAgent agent = getMandatoryBean(DefaultManagementAgent.class, "agent");
    assertNotNull("SpringInstrumentationAgent must be configured for JMX support", agent);
    assertNotNull("MBeanServer must be configured for JMX support", agent.getMBeanServer());
    assertEquals("org.apache.camel.test", agent.getMBeanServer().getDefaultDomain());
}
Also used : ManagementAgent(org.apache.camel.spi.ManagementAgent) DefaultManagementAgent(org.apache.camel.management.DefaultManagementAgent)

Example 9 with ManagementAgent

use of org.apache.camel.spi.ManagementAgent in project camel by apache.

the class JettyHttpComponent method getMbContainer.

public synchronized MBeanContainer getMbContainer() {
    // If null, provide the default implementation.
    if (mbContainer == null) {
        MBeanServer mbs = null;
        final ManagementStrategy mStrategy = this.getCamelContext().getManagementStrategy();
        final ManagementAgent mAgent = mStrategy.getManagementAgent();
        if (mAgent != null) {
            mbs = mAgent.getMBeanServer();
        }
        if (mbs != null) {
            mbContainer = new MBeanContainer(mbs);
            startMbContainer();
        } else {
            LOG.warn("JMX disabled in CamelContext. Jetty JMX extensions will remain disabled.");
        }
    }
    return this.mbContainer;
}
Also used : ManagementAgent(org.apache.camel.spi.ManagementAgent) ManagementStrategy(org.apache.camel.spi.ManagementStrategy) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) MBeanServer(javax.management.MBeanServer)

Example 10 with ManagementAgent

use of org.apache.camel.spi.ManagementAgent in project camel by apache.

the class MetricsRegistryService method doStart.

@Override
protected void doStart() throws Exception {
    if (metricsRegistry == null) {
        Registry camelRegistry = getCamelContext().getRegistry();
        metricsRegistry = camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
        // create a new metricsRegistry by default
        if (metricsRegistry == null) {
            metricsRegistry = new MetricRegistry();
        }
    }
    if (useJmx) {
        ManagementAgent agent = getCamelContext().getManagementStrategy().getManagementAgent();
        if (agent != null) {
            MBeanServer server = agent.getMBeanServer();
            if (server != null) {
                reporter = JmxReporter.forRegistry(metricsRegistry).registerWith(server).inDomain(jmxDomain).build();
                reporter.start();
            }
        } else {
            throw new IllegalStateException("CamelContext has not enabled JMX");
        }
    }
    // json mapper
    this.mapper = new ObjectMapper().registerModule(new MetricsModule(getRateUnit(), getDurationUnit(), false));
    if (getRateUnit() == TimeUnit.SECONDS && getDurationUnit() == TimeUnit.SECONDS) {
        // they both use same units so reuse
        this.secondsMapper = this.mapper;
    } else {
        this.secondsMapper = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false));
    }
}
Also used : ManagementAgent(org.apache.camel.spi.ManagementAgent) MetricRegistry(com.codahale.metrics.MetricRegistry) MetricsModule(com.codahale.metrics.json.MetricsModule) MetricRegistry(com.codahale.metrics.MetricRegistry) Registry(org.apache.camel.spi.Registry) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MBeanServer(javax.management.MBeanServer)

Aggregations

ManagementAgent (org.apache.camel.spi.ManagementAgent)14 MBeanServer (javax.management.MBeanServer)9 CamelContext (org.apache.camel.CamelContext)7 ObjectName (javax.management.ObjectName)6 Test (org.junit.Test)4 MetricRegistry (com.codahale.metrics.MetricRegistry)2 MetricsModule (com.codahale.metrics.json.MetricsModule)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 Registry (org.apache.camel.spi.Registry)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ObjectInstance (javax.management.ObjectInstance)1 CompositeData (javax.management.openmbean.CompositeData)1 TabularData (javax.management.openmbean.TabularData)1 DefaultManagementAgent (org.apache.camel.management.DefaultManagementAgent)1 ManagementStrategy (org.apache.camel.spi.ManagementStrategy)1