use of com.codahale.metrics.MetricRegistry in project camel by apache.
the class AbstractMetricsProducer method process.
@Override
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
String defaultMetricsName = getEndpoint().getMetricsName();
String finalMetricsName = getMetricsName(in, defaultMetricsName);
MetricRegistry registry = getEndpoint().getRegistry();
try {
doProcess(exchange, getEndpoint(), registry, finalMetricsName);
} catch (Exception e) {
exchange.setException(e);
} finally {
clearMetricsHeaders(in);
}
}
use of com.codahale.metrics.MetricRegistry in project camel by apache.
the class MetricsComponent method getOrCreateMetricRegistry.
MetricRegistry getOrCreateMetricRegistry(Registry camelRegistry, String registryName) {
LOG.debug("Looking up MetricRegistry from Camel Registry for name \"{}\"", registryName);
MetricRegistry result = getMetricRegistryFromCamelRegistry(camelRegistry, registryName);
if (result == null) {
LOG.debug("MetricRegistry not found from Camel Registry for name \"{}\"", registryName);
LOG.info("Creating new default MetricRegistry");
result = createMetricRegistry();
}
return result;
}
use of com.codahale.metrics.MetricRegistry in project camel by apache.
the class MetricsMessageHistoryService 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));
}
}
use of com.codahale.metrics.MetricRegistry in project camel by apache.
the class SpringMetricsMessageHistoryTest method testMetricsHistory.
@Test
public void testMetricsHistory() throws Exception {
getMockEndpoint("mock:foo").expectedMessageCount(5);
getMockEndpoint("mock:bar").expectedMessageCount(5);
getMockEndpoint("mock:baz").expectedMessageCount(5);
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
template.sendBody("seda:foo", "Hello " + i);
} else {
template.sendBody("seda:bar", "Hello " + i);
}
}
assertMockEndpointsSatisfied();
// there should be 3 names
MetricRegistry registry = context.getRegistry().findByType(MetricRegistry.class).iterator().next();
assertEquals(3, registry.getNames().size());
// get the message history service
MetricsMessageHistoryService service = context.hasService(MetricsMessageHistoryService.class);
assertNotNull(service);
String json = service.dumpStatisticsAsJson();
assertNotNull(json);
log.info(json);
assertTrue(json.contains("foo.history"));
assertTrue(json.contains("bar.history"));
assertTrue(json.contains("baz.history"));
}
use of com.codahale.metrics.MetricRegistry in project camel by apache.
the class MetricsComponentTest method testGetOrCreateMetricRegistryFoundInCamelRegistry.
@Test
public void testGetOrCreateMetricRegistryFoundInCamelRegistry() throws Exception {
when(camelRegistry.lookupByNameAndType("name", MetricRegistry.class)).thenReturn(metricRegistry);
MetricRegistry result = component.getOrCreateMetricRegistry(camelRegistry, "name");
assertThat(result, is(metricRegistry));
inOrder.verify(camelRegistry, times(1)).lookupByNameAndType("name", MetricRegistry.class);
inOrder.verifyNoMoreInteractions();
}
Aggregations