Search in sources :

Example 11 with Meter

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

the class ConnectionPoolMetricsAutoConfigurationTests method allConnectionPoolsCanBeInstrumented.

@Test
void allConnectionPoolsCanBeInstrumented() {
    this.contextRunner.withUserConfiguration(TwoConnectionPoolsConfiguration.class).run((context) -> {
        MeterRegistry registry = context.getBean(MeterRegistry.class);
        assertThat(registry.find("r2dbc.pool.acquired").gauges()).extracting(Meter::getId).extracting((id) -> id.getTag("name")).containsExactlyInAnyOrder("firstPool", "secondPool");
    });
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) AutoConfigurations(org.springframework.boot.autoconfigure.AutoConfigurations) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MetricsRun(org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun) H2ConnectionOption(io.r2dbc.h2.H2ConnectionOption) ConnectionPoolConfiguration(io.r2dbc.pool.ConnectionPoolConfiguration) Meter(io.micrometer.core.instrument.Meter) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) UUID(java.util.UUID) ConnectionPool(io.r2dbc.pool.ConnectionPool) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) H2ConnectionFactory(io.r2dbc.h2.H2ConnectionFactory) R2dbcAutoConfiguration(org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) CloseableConnectionFactory(io.r2dbc.h2.CloseableConnectionFactory) Meter(io.micrometer.core.instrument.Meter) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 12 with Meter

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

the class RepositoryMetricsAutoConfigurationTests method timerWorksWithTimedAnnotationsWhenAutoTimeRequestsIsFalse.

@Test
void timerWorksWithTimedAnnotationsWhenAutoTimeRequestsIsFalse() {
    this.contextRunner.withPropertyValues("management.metrics.data.repository.autotime.enabled=false").run((context) -> {
        MeterRegistry registry = getInitializedMeterRegistry(context, ExampleAnnotatedRepository.class);
        Collection<Meter> meters = registry.get("spring.data.repository.invocations").meters();
        assertThat(meters).hasSize(1);
        Meter meter = meters.iterator().next();
        assertThat(meter.getId().getTag("method")).isEqualTo("count");
    });
}
Also used : Meter(io.micrometer.core.instrument.Meter) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 13 with Meter

use of io.micrometer.core.instrument.Meter in project open-kilda by telstra.

the class PushToStreamMeterRegistry method pushMeters.

/**
 * Push the current values of registered meters to the specified stream.
 */
public void pushMeters(OutputCollector collector, String streamId) {
    try {
        List<Datapoint> datapoints = new ArrayList<>();
        for (Meter meter : getMeters()) {
            datapoints.addAll(meter.match(this::writeGauge, this::writeCounter, this::writeTimer, this::writeSummary, this::writeLongTaskTimer, this::writeTimeGauge, this::writeFunctionCounter, this::writeFunctionTimer, this::writeCustomMeter));
        }
        String payload = Utils.MAPPER.writeValueAsString(new DatapointEntries(datapoints));
        log.debug("Pushing datapoint(s) {}", payload);
        collector.emit(streamId, Collections.singletonList(payload));
    } catch (Exception ex) {
        log.warn("Failed to send metrics", ex);
    }
}
Also used : Datapoint(org.openkilda.messaging.info.Datapoint) Meter(io.micrometer.core.instrument.Meter) DefaultMeter(io.micrometer.core.instrument.internal.DefaultMeter) ArrayList(java.util.ArrayList) DatapointEntries(org.openkilda.messaging.info.DatapointEntries)

Example 14 with Meter

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

the class BulkheadMetricsTest method shouldRegisterMetrics.

@Test
public void shouldRegisterMetrics() {
    BulkheadRegistry bulkheadRegistry = BulkheadRegistry.ofDefaults();
    bulkheadRegistry.bulkhead("testName");
    BulkheadMetrics bulkheadMetrics = BulkheadMetrics.ofBulkheadRegistry(bulkheadRegistry);
    bulkheadMetrics.bindTo(meterRegistry);
    final List<String> metricNames = meterRegistry.getMeters().stream().map(Meter::getId).map(Meter.Id::getName).collect(Collectors.toList());
    final List<String> expectedMetrics = newArrayList("resilience4j.bulkhead.testName.available_concurrent_calls");
    assertThat(metricNames).hasSameElementsAs(expectedMetrics);
}
Also used : Meter(io.micrometer.core.instrument.Meter) BulkheadRegistry(io.github.resilience4j.bulkhead.BulkheadRegistry) Test(org.junit.Test)

Example 15 with Meter

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

the class RetryMetricsTest method shouldRegisterMetrics.

@Test
public void shouldRegisterMetrics() {
    RetryRegistry retryRegistry = RetryRegistry.ofDefaults();
    retryRegistry.retry("testName");
    RetryMetrics retryMetrics = RetryMetrics.ofRetryRegistry(retryRegistry);
    retryMetrics.bindTo(meterRegistry);
    final List<String> metricNames = meterRegistry.getMeters().stream().map(Meter::getId).map(Meter.Id::getName).collect(Collectors.toList());
    final List<String> expectedMetrics = newArrayList("resilience4j.retry.testName.successful_calls_with_retry", "resilience4j.retry.testName.failed_calls_with_retry", "resilience4j.retry.testName.successful_calls_without_retry", "resilience4j.retry.testName.failed_calls_without_retry");
    assertThat(metricNames).hasSameElementsAs(expectedMetrics);
}
Also used : Meter(io.micrometer.core.instrument.Meter) RetryRegistry(io.github.resilience4j.retry.RetryRegistry) Test(org.junit.Test)

Aggregations

Meter (io.micrometer.core.instrument.Meter)16 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)6 Test (org.junit.Test)5 Test (org.junit.jupiter.api.Test)5 ArrayList (java.util.ArrayList)4 Gauge (io.micrometer.core.instrument.Gauge)3 DefaultMeter (io.micrometer.core.instrument.internal.DefaultMeter)3 Collections (java.util.Collections)3 DistributionSummary (io.micrometer.core.instrument.DistributionSummary)2 FunctionTimer (io.micrometer.core.instrument.FunctionTimer)2 LongTaskTimer (io.micrometer.core.instrument.LongTaskTimer)2 Timer (io.micrometer.core.instrument.Timer)2 DefaultLongTaskTimer (io.micrometer.core.instrument.internal.DefaultLongTaskTimer)2 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 TimeUnit (java.util.concurrent.TimeUnit)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1