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