Search in sources :

Example 1 with MetricRegistry

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);
    }
}
Also used : Message(org.apache.camel.Message) MetricRegistry(com.codahale.metrics.MetricRegistry)

Example 2 with MetricRegistry

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;
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry)

Example 3 with MetricRegistry

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));
    }
}
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)

Example 4 with MetricRegistry

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"));
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) Test(org.junit.Test)

Example 5 with MetricRegistry

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();
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) Test(org.junit.Test)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)505 Test (org.junit.Test)177 Before (org.junit.Before)61 Test (org.junit.jupiter.api.Test)45 VerifiableProperties (com.github.ambry.config.VerifiableProperties)42 ArrayList (java.util.ArrayList)33 Counter (com.codahale.metrics.Counter)30 File (java.io.File)29 Properties (java.util.Properties)28 List (java.util.List)23 Metric (com.codahale.metrics.Metric)22 Map (java.util.Map)22 IOException (java.io.IOException)21 HashMap (java.util.HashMap)20 Size (com.github.joschi.jadconfig.util.Size)17 CountDownLatch (java.util.concurrent.CountDownLatch)17 TimeUnit (java.util.concurrent.TimeUnit)17 Timer (com.codahale.metrics.Timer)15 DefaultTaggedMetricRegistry (com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry)15 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)15