Search in sources :

Example 36 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project vertx-micrometer-metrics by vert-x3.

the class GaugesTest method shouldIgnoreGaugeLabel.

@Test
public void shouldIgnoreGaugeLabel() {
    MeterRegistry registry = new SimpleMeterRegistry();
    BackendRegistries.registerMatchers(registry, Collections.singletonList(new Match().setLabel("address").setType(MatchType.REGEX).setValue(".*").setAlias("_")));
    Gauges<LongAdder> gauges = new Gauges<>("my_gauge", "", LongAdder::new, LongAdder::doubleValue, registry, Label.ADDRESS);
    gauges.get("addr1").increment();
    gauges.get("addr1").increment();
    gauges.get("addr2").increment();
    Gauge g = registry.find("my_gauge").tags("address", "_").gauge();
    assertThat(g.value()).isEqualTo(3d);
    g = registry.find("my_gauge").tags("address", "addr1").gauge();
    assertThat(g).isNull();
    g = registry.find("my_gauge").tags("address", "addr2").gauge();
    assertThat(g).isNull();
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Match(io.vertx.micrometer.Match) Gauge(io.micrometer.core.instrument.Gauge) Test(org.junit.Test)

Example 37 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project vertx-micrometer-metrics by vert-x3.

the class SummariesTest method shouldIgnoreSummaryLabel.

@Test
public void shouldIgnoreSummaryLabel() {
    MeterRegistry registry = new SimpleMeterRegistry();
    BackendRegistries.registerMatchers(registry, Collections.singletonList(new Match().setLabel("address").setType(MatchType.REGEX).setValue(".*").setAlias("_")));
    Summaries summaries = new Summaries("my_summary", "", registry, Label.ADDRESS);
    summaries.get("addr1").record(5);
    summaries.get("addr1").record(8);
    summaries.get("addr2").record(10);
    DistributionSummary s = registry.find("my_summary").tags("address", "_").summary();
    assertThat(s.count()).isEqualTo(3);
    assertThat(s.totalAmount()).isEqualTo(23);
    s = registry.find("my_summary").tags("address", "addr1").summary();
    assertThat(s).isNull();
    s = registry.find("my_summary").tags("address", "addr2").summary();
    assertThat(s).isNull();
}
Also used : DistributionSummary(io.micrometer.core.instrument.DistributionSummary) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Match(io.vertx.micrometer.Match) Test(org.junit.Test)

Example 38 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 39 with MeterRegistry

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

the class BulkheadMetrics method bindTo.

@Override
public void bindTo(MeterRegistry registry) {
    for (Bulkhead bulkhead : bulkheads) {
        final String name = bulkhead.getName();
        Gauge.builder(getName(prefix, name, AVAILABLE_CONCURRENT_CALLS), bulkhead, (cb) -> cb.getMetrics().getAvailableConcurrentCalls()).register(registry);
    }
}
Also used : BulkheadRegistry(io.github.resilience4j.bulkhead.BulkheadRegistry) Gauge(io.micrometer.core.instrument.Gauge) DEFAULT_PREFIX(io.github.resilience4j.bulkhead.utils.MetricNames.DEFAULT_PREFIX) MetricUtils.getName(io.github.resilience4j.micrometer.MetricUtils.getName) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Objects.requireNonNull(java.util.Objects.requireNonNull) Bulkhead(io.github.resilience4j.bulkhead.Bulkhead) MeterBinder(io.micrometer.core.instrument.binder.MeterBinder) AVAILABLE_CONCURRENT_CALLS(io.github.resilience4j.bulkhead.utils.MetricNames.AVAILABLE_CONCURRENT_CALLS) Bulkhead(io.github.resilience4j.bulkhead.Bulkhead)

Example 40 with MeterRegistry

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

the class CircuitBreakerMetrics method bindTo.

@Override
public void bindTo(MeterRegistry registry) {
    for (CircuitBreaker circuitBreaker : circuitBreakers) {
        final String name = circuitBreaker.getName();
        Gauge.builder(getName(prefix, name, STATE), circuitBreaker, (cb) -> cb.getState().getOrder()).register(registry);
        Gauge.builder(getName(prefix, name, BUFFERED_MAX), circuitBreaker, (cb) -> cb.getMetrics().getMaxNumberOfBufferedCalls()).register(registry);
        Gauge.builder(getName(prefix, name, BUFFERED), circuitBreaker, (cb) -> cb.getMetrics().getNumberOfBufferedCalls()).register(registry);
        Gauge.builder(getName(prefix, name, FAILED), circuitBreaker, (cb) -> cb.getMetrics().getNumberOfFailedCalls()).register(registry);
        Gauge.builder(getName(prefix, name, NOT_PERMITTED), circuitBreaker, (cb) -> cb.getMetrics().getNumberOfNotPermittedCalls()).register(registry);
        Gauge.builder(getName(prefix, name, SUCCESSFUL), circuitBreaker, (cb) -> cb.getMetrics().getNumberOfSuccessfulCalls()).register(registry);
    }
}
Also used : CircuitBreaker(io.github.resilience4j.circuitbreaker.CircuitBreaker) Gauge(io.micrometer.core.instrument.Gauge) MetricUtils.getName(io.github.resilience4j.micrometer.MetricUtils.getName) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Objects.requireNonNull(java.util.Objects.requireNonNull) MeterBinder(io.micrometer.core.instrument.binder.MeterBinder) CircuitBreakerRegistry(io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry) MetricNames(io.github.resilience4j.circuitbreaker.utils.MetricNames) CircuitBreaker(io.github.resilience4j.circuitbreaker.CircuitBreaker)

Aggregations

MeterRegistry (io.micrometer.core.instrument.MeterRegistry)42 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)21 Test (org.junit.jupiter.api.Test)12 Test (org.junit.Test)10 Timer (io.micrometer.core.instrument.Timer)9 Duration (java.time.Duration)9 SampleConfig (io.micrometer.core.samples.utils.SampleConfig)8 Match (io.vertx.micrometer.Match)8 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 Flux (reactor.core.publisher.Flux)6 Counter (io.micrometer.core.instrument.Counter)5 MetricUtils.getName (io.github.resilience4j.micrometer.MetricUtils.getName)4 MeterBinder (io.micrometer.core.instrument.binder.MeterBinder)4 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)4 Objects.requireNonNull (java.util.Objects.requireNonNull)4 TimeUnit (java.util.concurrent.TimeUnit)4