Search in sources :

Example 6 with SimpleMeterRegistry

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

the class TimersTest method shouldIgnoreTimerLabel.

@Test
public void shouldIgnoreTimerLabel() {
    MeterRegistry registry = new SimpleMeterRegistry();
    BackendRegistries.registerMatchers(registry, Collections.singletonList(new Match().setLabel("address").setType(MatchType.REGEX).setValue(".*").setAlias("_")));
    Timers timers = new Timers("my_timer", "", registry, Label.ADDRESS);
    timers.get("addr1").record(5, TimeUnit.MILLISECONDS);
    timers.get("addr1").record(8, TimeUnit.MILLISECONDS);
    timers.get("addr2").record(10, TimeUnit.MILLISECONDS);
    Timer t = registry.find("my_timer").timer();
    assertThat(t.count()).isEqualTo(3);
    assertThat(t.totalTime(TimeUnit.MILLISECONDS)).isEqualTo(23);
    t = registry.find("my_timer").tags("address", "addr1").timer();
    assertThat(t).isNull();
    t = registry.find("my_timer").tags("address", "addr2").timer();
    assertThat(t).isNull();
}
Also used : Timer(io.micrometer.core.instrument.Timer) 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 7 with SimpleMeterRegistry

use of io.micrometer.core.instrument.simple.SimpleMeterRegistry in project tutorials by eugenp.

the class MicrometerAtlasTest method givenCompositeRegistries_whenRecordMeter_thenAllRegistriesRecorded.

@Test
public void givenCompositeRegistries_whenRecordMeter_thenAllRegistriesRecorded() {
    CompositeMeterRegistry compositeRegistry = new CompositeMeterRegistry();
    SimpleMeterRegistry oneSimpleMeter = new SimpleMeterRegistry();
    AtlasMeterRegistry atlasMeterRegistry = new AtlasMeterRegistry(atlasConfig, Clock.SYSTEM);
    compositeRegistry.add(oneSimpleMeter);
    compositeRegistry.add(atlasMeterRegistry);
    compositeRegistry.gauge("baeldung.heat", 90);
    Optional<Gauge> oneGauge = oneSimpleMeter.find("baeldung.heat").gauge();
    assertTrue(oneGauge.isPresent());
    Iterator<Measurement> measurements = oneGauge.get().measure().iterator();
    assertTrue(measurements.hasNext());
    assertThat(measurements.next().getValue(), equalTo(90.00));
    Optional<Gauge> atlasGauge = atlasMeterRegistry.find("baeldung.heat").gauge();
    assertTrue(atlasGauge.isPresent());
    Iterator<Measurement> anotherMeasurements = atlasGauge.get().measure().iterator();
    assertTrue(anotherMeasurements.hasNext());
    assertThat(anotherMeasurements.next().getValue(), equalTo(90.00));
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) AtlasMeterRegistry(io.micrometer.atlas.AtlasMeterRegistry) Measurement(io.micrometer.core.instrument.Measurement) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Gauge(io.micrometer.core.instrument.Gauge) Test(org.junit.Test)

Example 8 with SimpleMeterRegistry

use of io.micrometer.core.instrument.simple.SimpleMeterRegistry in project tutorials by eugenp.

the class MicrometerAtlasTest method givenGauge_whenMeterListSize_thenCurrentSizeMonitored.

@Test
public void givenGauge_whenMeterListSize_thenCurrentSizeMonitored() {
    SimpleMeterRegistry registry = new SimpleMeterRegistry();
    List<String> list = new ArrayList<>(4);
    Gauge gauge = Gauge.builder("cache.size", list, List::size).register(registry);
    assertTrue(gauge.value() == 0.0);
    list.add("1");
    assertTrue(gauge.value() == 1.0);
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ArrayList(java.util.ArrayList) Gauge(io.micrometer.core.instrument.Gauge) Test(org.junit.Test)

Example 9 with SimpleMeterRegistry

use of io.micrometer.core.instrument.simple.SimpleMeterRegistry in project tutorials by eugenp.

the class MicrometerAtlasTest method givenDistributionSummary_whenEnrichWithHistograms_thenDataAggregated.

@Test
public void givenDistributionSummary_whenEnrichWithHistograms_thenDataAggregated() {
    SimpleMeterRegistry registry = new SimpleMeterRegistry();
    DistributionSummary hist = DistributionSummary.builder("summary").histogram(Histogram.linear(0, 10, 5)).register(registry);
    hist.record(3);
    hist.record(8);
    hist.record(20);
    hist.record(40);
    hist.record(13);
    hist.record(26);
    Map<String, Integer> histograms = extractTagValueMap(registry, Type.Counter, 1.0);
    assertThat(histograms, allOf(hasEntry("bucket=0.0", 0), hasEntry("bucket=10.0", 2), hasEntry("bucket=20.0", 2), hasEntry("bucket=30.0", 1), hasEntry("bucket=40.0", 1), hasEntry("bucket=Infinity", 0)));
}
Also used : DistributionSummary(io.micrometer.core.instrument.DistributionSummary) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Test(org.junit.Test)

Example 10 with SimpleMeterRegistry

use of io.micrometer.core.instrument.simple.SimpleMeterRegistry in project tutorials by eugenp.

the class MicrometerAtlasTest method givenLongTimer_whenRunTasks_thenTimerRecorded.

@Test
public void givenLongTimer_whenRunTasks_thenTimerRecorded() {
    SimpleMeterRegistry registry = new SimpleMeterRegistry();
    LongTaskTimer longTaskTimer = LongTaskTimer.builder("3rdPartyService").register(registry);
    long currentTaskId = longTaskTimer.start();
    try {
        TimeUnit.MILLISECONDS.sleep(2);
    } catch (InterruptedException ignored) {
    }
    long timeElapsed = longTaskTimer.stop(currentTaskId);
    assertTrue(timeElapsed / (int) 1e6 == 2);
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) LongTaskTimer(io.micrometer.core.instrument.LongTaskTimer) Test(org.junit.Test)

Aggregations

SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)42 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)20 Test (org.junit.jupiter.api.Test)20 Test (org.junit.Test)18 Match (io.vertx.micrometer.Match)8 Timer (io.micrometer.core.instrument.Timer)6 LongTaskTimer (io.micrometer.core.instrument.LongTaskTimer)5 MockClock (io.micrometer.core.instrument.MockClock)5 Counter (io.micrometer.core.instrument.Counter)4 DistributionSummary (io.micrometer.core.instrument.DistributionSummary)4 Gauge (io.micrometer.core.instrument.Gauge)4 HystrixPropertiesCommandDefault (com.netflix.hystrix.strategy.properties.HystrixPropertiesCommandDefault)2 Issue (io.micrometer.core.Issue)2 Tag (io.micrometer.core.instrument.Tag)2 MeterFilter (io.micrometer.core.instrument.config.MeterFilter)2 CountAtBucket (io.micrometer.core.instrument.distribution.CountAtBucket)2 SimpleConfig (io.micrometer.core.instrument.simple.SimpleConfig)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 LongAdder (java.util.concurrent.atomic.LongAdder)2 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)2