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();
}
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));
}
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);
}
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)));
}
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);
}
Aggregations