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" });
}
}
}
}
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;
}
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());
}
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;
}
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));
}
}
Aggregations