use of io.micrometer.core.instrument.Counter in project tutorials by eugenp.
the class MicrometerAtlasTest method givenGlobalRegistry_whenIncrementAnywhere_thenCounted.
@Test
public void givenGlobalRegistry_whenIncrementAnywhere_thenCounted() {
class CountedObject {
private CountedObject() {
Metrics.counter("objects.instance").increment(1.0);
}
}
Metrics.addRegistry(new SimpleMeterRegistry());
Metrics.counter("objects.instance").increment();
new CountedObject();
Optional<Counter> counterOptional = Metrics.globalRegistry.find("objects.instance").counter();
assertTrue(counterOptional.isPresent());
assertTrue(counterOptional.get().count() == 2.0);
}
use of io.micrometer.core.instrument.Counter in project tutorials by eugenp.
the class MicrometerAtlasTest method givenCounter_whenIncrement_thenValueChanged.
@Test
public void givenCounter_whenIncrement_thenValueChanged() {
SimpleMeterRegistry registry = new SimpleMeterRegistry();
Counter counter = Counter.builder("objects.instance").description("indicates instance count of the object").tags("dev", "performance").register(registry);
counter.increment(2.0);
assertTrue(counter.count() == 2);
counter.increment(-1);
assertTrue(counter.count() == 2);
}
Aggregations