Search in sources :

Example 1 with MeterRegistry

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

the class MetricsExamples method setupAndAccessCustomRegistry.

public void setupAndAccessCustomRegistry() {
    Vertx vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions().setInfluxDbOptions(// or VertxPrometheusOptions
    new VertxInfluxDbOptions().setEnabled(true)).setRegistryName("my registry").setEnabled(true)));
    // Later on:
    MeterRegistry registry = BackendRegistries.getNow("my registry");
}
Also used : VertxInfluxDbOptions(io.vertx.micrometer.VertxInfluxDbOptions) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry)

Example 2 with MeterRegistry

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

the class CountersTest method shouldIgnoreCounterLabel.

@Test
public void shouldIgnoreCounterLabel() {
    MeterRegistry registry = new SimpleMeterRegistry();
    BackendRegistries.registerMatchers(registry, Collections.singletonList(new Match().setLabel("address").setType(MatchType.REGEX).setValue(".*").setAlias("_")));
    Counters counters = new Counters("my_counter", "", registry, Label.ADDRESS);
    counters.get("addr1").increment();
    counters.get("addr1").increment();
    counters.get("addr2").increment();
    Counter c = registry.find("my_counter").tags("address", "_").counter();
    assertThat(c.count()).isEqualTo(3d);
    c = registry.find("my_counter").tags("address", "addr1").counter();
    assertThat(c).isNull();
    c = registry.find("my_counter").tags("address", "addr2").counter();
    assertThat(c).isNull();
}
Also used : Counter(io.micrometer.core.instrument.Counter) 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 3 with MeterRegistry

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

the class CountersTest method shouldAliasCounterLabel.

@Test
public void shouldAliasCounterLabel() {
    MeterRegistry registry = new SimpleMeterRegistry();
    BackendRegistries.registerMatchers(registry, Collections.singletonList(new Match().setLabel("address").setType(MatchType.REGEX).setValue("addr1").setAlias("1")));
    Counters counters = new Counters("my_counter", "", registry, Label.ADDRESS);
    counters.get("addr1").increment();
    counters.get("addr1").increment();
    counters.get("addr2").increment();
    Counter c = registry.find("my_counter").tags("address", "1").counter();
    assertThat(c.count()).isEqualTo(2d);
    c = registry.find("my_counter").tags("address", "addr1").counter();
    assertThat(c).isNull();
    c = registry.find("my_counter").tags("address", "addr2").counter();
    assertThat(c.count()).isEqualTo(1d);
}
Also used : Counter(io.micrometer.core.instrument.Counter) 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 4 with MeterRegistry

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

the class GaugesTest method shouldAliasGaugeLabel.

@Test
public void shouldAliasGaugeLabel() {
    MeterRegistry registry = new SimpleMeterRegistry();
    BackendRegistries.registerMatchers(registry, Collections.singletonList(new Match().setLabel("address").setType(MatchType.REGEX).setValue("addr1").setAlias("1")));
    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", "1").gauge();
    assertThat(g.value()).isEqualTo(2d);
    g = registry.find("my_gauge").tags("address", "addr1").gauge();
    assertThat(g).isNull();
    g = registry.find("my_gauge").tags("address", "addr2").gauge();
    assertThat(g.value()).isEqualTo(1d);
}
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 5 with MeterRegistry

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

the class SummariesTest method shouldAliasSummaryLabel.

@Test
public void shouldAliasSummaryLabel() {
    MeterRegistry registry = new SimpleMeterRegistry();
    BackendRegistries.registerMatchers(registry, Collections.singletonList(new Match().setLabel("address").setType(MatchType.REGEX).setValue("addr1").setAlias("1")));
    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", "1").summary();
    assertThat(s.count()).isEqualTo(2);
    assertThat(s.totalAmount()).isEqualTo(13);
    s = registry.find("my_summary").tags("address", "addr1").summary();
    assertThat(s).isNull();
    s = registry.find("my_summary").tags("address", "addr2").summary();
    assertThat(s.count()).isEqualTo(1);
    assertThat(s.totalAmount()).isEqualTo(10);
}
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)

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