Search in sources :

Example 81 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project spring-integration by spring-projects.

the class MicrometerMetricsTests method testSend.

@Test
public void testSend() {
    GenericMessage<String> message = new GenericMessage<>("foo");
    this.channel.send(message);
    try {
        this.channel.send(this.source.receive());
        fail("Expected exception");
    } catch (MessagingException e) {
        assertThat(e.getCause().getMessage()).isEqualTo("testErrorCount");
    }
    this.channel2.send(message);
    this.queue.send(message);
    this.queue.send(message);
    this.queue.receive();
    this.badPoll.send(message);
    try {
        this.badPoll.receive();
        fail("Expected exception");
    } catch (RuntimeException e) {
        assertThat(e.getMessage()).isEqualTo("badPoll");
    }
    nullChannel.send(message);
    MeterRegistry registry = this.meterRegistry;
    assertThat(registry.get("spring.integration.channels").gauge().value()).isEqualTo(6);
    assertThat(registry.get("spring.integration.handlers").gauge().value()).isEqualTo(3);
    assertThat(registry.get("spring.integration.sources").gauge().value()).isEqualTo(1);
    assertThat(registry.get("spring.integration.receive").tag("name", "source").tag("result", "success").counter().count()).isEqualTo(1);
    assertThat(registry.get("spring.integration.receive").tag("name", "badPoll").tag("result", "failure").counter().count()).isEqualTo(1);
    assertThat(registry.get("spring.integration.send").tag("name", "eipBean.handler").tag("result", "success").timer().count()).isEqualTo(1);
    assertThat(registry.get("spring.integration.send").tag("name", "eipMethod.handler").tag("result", "success").timer().count()).isEqualTo(1);
    assertThat(registry.get("spring.integration.send").tag("name", "channel").tag("result", "success").timer().count()).isEqualTo(1);
    assertThat(registry.get("spring.integration.send").tag("name", "channel").tag("result", "failure").timer().count()).isEqualTo(1);
    assertThat(registry.get("spring.integration.send").tag("name", "eipMethod.handler").tag("result", "failure").timer().count()).isEqualTo(1);
    assertThat(registry.get("spring.integration.receive").tag("name", "queue").tag("result", "success").counter().count()).isEqualTo(1);
    assertThat(registry.get("spring.integration.send").tag("name", "nullChannel").tag("result", "success").timer().count()).isEqualTo(1);
    BeanDefinitionRegistry beanFactory = (BeanDefinitionRegistry) this.context.getBeanFactory();
    beanFactory.registerBeanDefinition("newChannel", BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class).getRawBeanDefinition());
    DirectChannel newChannel = this.context.getBean("newChannel", DirectChannel.class);
    newChannel.setBeanName("newChannel");
    newChannel.subscribe(m -> {
    });
    newChannel.send(new GenericMessage<>("foo"));
    assertThat(registry.get("spring.integration.send").tag("name", "newChannel").tag("result", "success").timer().count()).isEqualTo(1);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessagingException(org.springframework.messaging.MessagingException) DirectChannel(org.springframework.integration.channel.DirectChannel) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.Test)

Example 82 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project pravega by pravega.

the class StatsProviderTest method testStatsProviderStartWithoutExporting.

@Test
public void testStatsProviderStartWithoutExporting() {
    MetricsConfig appConfig = MetricsConfig.builder().with(MetricsConfig.ENABLE_STATISTICS, true).with(MetricsConfig.ENABLE_STATSD_REPORTER, true).with(MetricsConfig.ENABLE_INFLUXDB_REPORTER, true).build();
    @Cleanup CompositeMeterRegistry localRegistry = new CompositeMeterRegistry();
    @Cleanup StatsProvider statsProvider = new StatsProviderImpl(appConfig, localRegistry);
    statsProvider.startWithoutExporting();
    for (MeterRegistry registry : localRegistry.getRegistries()) {
        assertTrue(registry instanceof SimpleMeterRegistry);
        assertFalse(registry instanceof InfluxMeterRegistry);
        assertFalse(registry instanceof StatsdMeterRegistry);
    }
    statsProvider.close();
    assertTrue(0 == localRegistry.getRegistries().size());
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) StatsdMeterRegistry(io.micrometer.statsd.StatsdMeterRegistry) Cleanup(lombok.Cleanup) InfluxMeterRegistry(io.micrometer.influx.InfluxMeterRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) StatsdMeterRegistry(io.micrometer.statsd.StatsdMeterRegistry) InfluxMeterRegistry(io.micrometer.influx.InfluxMeterRegistry) Test(org.junit.Test)

Example 83 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project pravega by pravega.

the class StatsProviderImpl method close.

@Synchronized
@Override
public void close() {
    this.prometheusRegistry = null;
    for (MeterRegistry registry : new ArrayList<MeterRegistry>(metrics.getRegistries())) {
        registry.close();
        metrics.remove(registry);
    }
}
Also used : ArrayList(java.util.ArrayList) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) InfluxMeterRegistry(io.micrometer.influx.InfluxMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) StatsdMeterRegistry(io.micrometer.statsd.StatsdMeterRegistry) Synchronized(lombok.Synchronized)

Example 84 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project pravega by pravega.

the class StatsProviderImpl method startWithoutExporting.

@Synchronized
@Override
public void startWithoutExporting() {
    this.prometheusRegistry = null;
    for (MeterRegistry registry : new ArrayList<MeterRegistry>(metrics.getRegistries())) {
        metrics.remove(registry);
    }
    Metrics.addRegistry(new SimpleMeterRegistry());
    init();
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ArrayList(java.util.ArrayList) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) InfluxMeterRegistry(io.micrometer.influx.InfluxMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) StatsdMeterRegistry(io.micrometer.statsd.StatsdMeterRegistry) Synchronized(lombok.Synchronized)

Example 85 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project spring-boot by spring-projects.

the class RestTemplateMetricsConfigurationTests method afterMaxUrisReachedFurtherUrisAreDenied.

@Test
void afterMaxUrisReachedFurtherUrisAreDenied(CapturedOutput output) {
    this.contextRunner.withPropertyValues("management.metrics.web.client.max-uri-tags=2").run((context) -> {
        MeterRegistry registry = getInitializedMeterRegistry(context);
        assertThat(registry.get("http.client.requests").meters()).hasSize(2);
        assertThat(output).contains("Reached the maximum number of URI tags for 'http.client.requests'.").contains("Are you using 'uriVariables'?");
    });
}
Also used : MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Aggregations

MeterRegistry (io.micrometer.core.instrument.MeterRegistry)136 Test (org.junit.jupiter.api.Test)83 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)60 CompositeMeterRegistry (io.micrometer.core.instrument.composite.CompositeMeterRegistry)17 Timer (io.micrometer.core.instrument.Timer)15 Test (org.junit.Test)15 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)12 Duration (java.time.Duration)11 ApplicationContextRunner (org.springframework.boot.test.context.runner.ApplicationContextRunner)10 HikariDataSource (com.zaxxer.hikari.HikariDataSource)9 DataSource (javax.sql.DataSource)9 DelegatingDataSource (org.springframework.jdbc.datasource.DelegatingDataSource)9 SampleConfig (io.micrometer.core.samples.utils.SampleConfig)8 Match (io.vertx.micrometer.Match)8 FunctionCounter (io.micrometer.core.instrument.FunctionCounter)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Normal (cern.jet.random.Normal)6 MersenneTwister64 (cern.jet.random.engine.MersenneTwister64)6 RandomEngine (cern.jet.random.engine.RandomEngine)6 Gauge (io.micrometer.core.instrument.Gauge)6