Search in sources :

Example 51 with MeterRegistry

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

the class DataSourcePoolMetricsAutoConfigurationTests method autoConfiguredHikariDataSourceIsInstrumentedWhenUsingDeprecatedDataSourceInitialization.

@Test
@Deprecated
void autoConfiguredHikariDataSourceIsInstrumentedWhenUsingDeprecatedDataSourceInitialization() {
    this.contextRunner.withPropertyValues("spring.datasource.schema:db/create-custom-schema.sql").withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class)).run((context) -> {
        context.getBean(DataSource.class).getConnection();
        MeterRegistry registry = context.getBean(MeterRegistry.class);
        registry.get("hikaricp.connections").meter();
    });
}
Also used : DelegatingDataSource(org.springframework.jdbc.datasource.DelegatingDataSource) HikariDataSource(com.zaxxer.hikari.HikariDataSource) DataSource(javax.sql.DataSource) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 52 with MeterRegistry

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

the class CacheMetricsAutoConfigurationTests method cacheInstrumentationCanBeDisabled.

@Test
void cacheInstrumentationCanBeDisabled() {
    this.contextRunner.withPropertyValues("management.metrics.enable.cache=false", "spring.cache.type=caffeine", "spring.cache.cache-names=cache1").run((context) -> {
        MeterRegistry registry = context.getBean(MeterRegistry.class);
        assertThat(registry.find("cache.requests").tags("name", "cache1").tags("cacheManager", "cacheManager").meter()).isNull();
    });
}
Also used : MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 53 with MeterRegistry

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

the class CacheMetricsAutoConfigurationTests method autoConfiguredNonSupportedCacheManagerIsIgnored.

@Test
void autoConfiguredNonSupportedCacheManagerIsIgnored() {
    this.contextRunner.withPropertyValues("spring.cache.type=simple", "spring.cache.cache-names=cache1,cache2").run((context) -> {
        MeterRegistry registry = context.getBean(MeterRegistry.class);
        assertThat(registry.find("cache.gets").tags("name", "cache1").tags("cacheManager", "cacheManager").meter()).isNull();
        assertThat(registry.find("cache.gets").tags("name", "cache2").tags("cacheManager", "cacheManager").meter()).isNull();
    });
}
Also used : MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 54 with MeterRegistry

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

the class MetricsAutoConfigurationIntegrationTests method emptyCompositeIsCreatedWhenNoMeterRegistriesAreAutoConfigured.

@Test
void emptyCompositeIsCreatedWhenNoMeterRegistriesAreAutoConfigured() {
    new ApplicationContextRunner().with(MetricsRun.limitedTo()).run((context) -> {
        MeterRegistry registry = context.getBean(MeterRegistry.class);
        assertThat(registry).isInstanceOf(CompositeMeterRegistry.class);
        assertThat(((CompositeMeterRegistry) registry).getRegistries()).isEmpty();
    });
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) GraphiteMeterRegistry(io.micrometer.graphite.GraphiteMeterRegistry) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) JmxMeterRegistry(io.micrometer.jmx.JmxMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 55 with MeterRegistry

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

the class MetricsAutoConfigurationIntegrationTests method propertyBasedCommonTagsIsAutoConfigured.

@Test
void propertyBasedCommonTagsIsAutoConfigured() {
    this.contextRunner.withPropertyValues("management.metrics.tags.region=test", "management.metrics.tags.origin=local").run((context) -> {
        MeterRegistry registry = context.getBean(MeterRegistry.class);
        registry.counter("my.counter", "env", "qa");
        assertThat(registry.find("my.counter").tags("env", "qa").tags("region", "test").tags("origin", "local").counter()).isNotNull();
    });
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) GraphiteMeterRegistry(io.micrometer.graphite.GraphiteMeterRegistry) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) JmxMeterRegistry(io.micrometer.jmx.JmxMeterRegistry) 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