Search in sources :

Example 11 with Counter

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);
}
Also used : Counter(io.micrometer.core.instrument.Counter) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Test(org.junit.Test)

Example 12 with Counter

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);
}
Also used : Counter(io.micrometer.core.instrument.Counter) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Test(org.junit.Test)

Aggregations

Counter (io.micrometer.core.instrument.Counter)12 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)5 Test (org.junit.Test)5 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)4 Test (org.junit.jupiter.api.Test)3 CdcKafkaPublisher (io.eventuate.local.common.CdcKafkaPublisher)2 PublishingStrategy (io.eventuate.local.common.PublishingStrategy)2 EventuateLocalPublishingException (io.eventuate.local.common.exception.EventuateLocalPublishingException)2 SampleConfig (io.micrometer.core.samples.utils.SampleConfig)2 Match (io.vertx.micrometer.Match)2 Duration (java.time.Duration)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Flux (reactor.core.publisher.Flux)2 Normal (cern.jet.random.Normal)1 MersenneTwister64 (cern.jet.random.engine.MersenneTwister64)1 RandomEngine (cern.jet.random.engine.RandomEngine)1