Search in sources :

Example 1 with Gauge

use of io.micrometer.core.instrument.Gauge 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 2 with Gauge

use of io.micrometer.core.instrument.Gauge in project micrometer by micrometer-metrics.

the class SimpleMeterRegistryTest method slasOnlyNoPercentileHistogram.

@Issue("#370")
@Test
void slasOnlyNoPercentileHistogram() {
    DistributionSummary summary = DistributionSummary.builder("my.summary").sla(1, 2).register(registry);
    summary.record(1);
    Timer timer = Timer.builder("my.timer").sla(Duration.ofMillis(1)).register(registry);
    timer.record(1, TimeUnit.MILLISECONDS);
    Gauge summaryHist1 = registry.get("my.summary.histogram").tags("le", "1").gauge();
    Gauge summaryHist2 = registry.get("my.summary.histogram").tags("le", "2").gauge();
    Gauge timerHist = registry.get("my.timer.histogram").tags("le", "0.001").gauge();
    assertThat(summaryHist1.value()).isEqualTo(1);
    assertThat(summaryHist2.value()).isEqualTo(1);
    assertThat(timerHist.value()).isEqualTo(1);
    clock.add(SimpleConfig.DEFAULT.step());
    assertThat(summaryHist1.value()).isEqualTo(0);
    assertThat(summaryHist2.value()).isEqualTo(0);
    assertThat(timerHist.value()).isEqualTo(0);
}
Also used : DistributionSummary(io.micrometer.core.instrument.DistributionSummary) Timer(io.micrometer.core.instrument.Timer) Gauge(io.micrometer.core.instrument.Gauge) Issue(io.micrometer.core.Issue) Test(org.junit.jupiter.api.Test)

Example 3 with Gauge

use of io.micrometer.core.instrument.Gauge in project micrometer by micrometer-metrics.

the class ElasticMeterRegistryTest method nullGauge.

@Issue("#497")
@Test
void nullGauge() {
    Gauge g = Gauge.builder("gauge", null, o -> 1).register(registry);
    assertThat(registry.writeGauge(g, 0)).isEmpty();
    TimeGauge tg = TimeGauge.builder("time.gauge", null, TimeUnit.MILLISECONDS, o -> 1).register(registry);
    assertThat(registry.writeGauge(tg, 0)).isEmpty();
}
Also used : Counter(io.micrometer.core.instrument.Counter) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Issue(io.micrometer.core.Issue) Gauge(io.micrometer.core.instrument.Gauge) MockClock(io.micrometer.core.instrument.MockClock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeGauge(io.micrometer.core.instrument.TimeGauge) TimeGauge(io.micrometer.core.instrument.TimeGauge) Gauge(io.micrometer.core.instrument.Gauge) TimeGauge(io.micrometer.core.instrument.TimeGauge) Issue(io.micrometer.core.Issue) Test(org.junit.jupiter.api.Test)

Example 4 with Gauge

use of io.micrometer.core.instrument.Gauge in project micrometer by micrometer-metrics.

the class GaugeTest method collectionSizeGauge.

@Test
@DisplayName("gauges can be directly associated with collection size")
default void collectionSizeGauge(MeterRegistry registry) {
    List<String> list = registry.gaugeCollectionSize("my.gauge", emptyList(), new ArrayList<>());
    list.addAll(Arrays.asList("a", "b"));
    Gauge g = registry.get("my.gauge").gauge();
    assertThat(g.value()).isEqualTo(2);
}
Also used : Gauge(io.micrometer.core.instrument.Gauge) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with Gauge

use of io.micrometer.core.instrument.Gauge in project micrometer by micrometer-metrics.

the class GaugeTest method objectGauge.

@Test
@DisplayName("gauges attached to an object are updated when their values are observed")
default void objectGauge(MeterRegistry registry) {
    List<String> list = registry.gauge("my.gauge", emptyList(), new ArrayList<>(), List::size);
    list.addAll(Arrays.asList("a", "b"));
    Gauge g = registry.get("my.gauge").gauge();
    assertThat(g.value()).isEqualTo(2);
}
Also used : Collections.emptyList(java.util.Collections.emptyList) Gauge(io.micrometer.core.instrument.Gauge) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

Gauge (io.micrometer.core.instrument.Gauge)18 Test (org.junit.jupiter.api.Test)8 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)4 Test (org.junit.Test)4 DisplayName (org.junit.jupiter.api.DisplayName)4 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)3 Issue (io.micrometer.core.Issue)2 Meter (io.micrometer.core.instrument.Meter)2 Match (io.vertx.micrometer.Match)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 LongAdder (java.util.concurrent.atomic.LongAdder)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 Get (com.linecorp.armeria.server.annotation.Get)1 AtlasMeterRegistry (io.micrometer.atlas.AtlasMeterRegistry)1 Counter (io.micrometer.core.instrument.Counter)1 DistributionSummary (io.micrometer.core.instrument.DistributionSummary)1 Measurement (io.micrometer.core.instrument.Measurement)1 MockClock (io.micrometer.core.instrument.MockClock)1 TimeGauge (io.micrometer.core.instrument.TimeGauge)1 Timer (io.micrometer.core.instrument.Timer)1