Search in sources :

Example 6 with Counter

use of io.micrometer.core.instrument.Counter in project eventuate-local by eventuate-local.

the class PollingCdcKafkaPublisher method handleEvent.

@Override
public void handleEvent(EVENT event) throws EventuateLocalPublishingException {
    logger.trace("Got record " + event.toString());
    String aggregateTopic = publishingStrategy.topicFor(event);
    String json = publishingStrategy.toJson(event);
    Exception lastException = null;
    for (int i = 0; i < 5; i++) {
        try {
            producer.send(aggregateTopic, publishingStrategy.partitionKeyFor(event), json).get(10, TimeUnit.SECONDS);
            publishingStrategy.getCreateTime(event).ifPresent(time -> histogramEventAge.ifPresent(x -> x.set(System.currentTimeMillis() - time)));
            meterEventsPublished.ifPresent(Counter::increment);
            return;
        } catch (Exception e) {
            logger.warn("error publishing to " + aggregateTopic, e);
            meterEventsRetries.ifPresent(Counter::increment);
            lastException = e;
            try {
                Thread.sleep((int) Math.pow(2, i) * 1000);
            } catch (InterruptedException ie) {
                throw new RuntimeException(ie);
            }
        }
    }
    throw new EventuateLocalPublishingException("error publishing to " + aggregateTopic, lastException);
}
Also used : EventuateLocalPublishingException(io.eventuate.local.common.exception.EventuateLocalPublishingException) Counter(io.micrometer.core.instrument.Counter) TimeUnit(java.util.concurrent.TimeUnit) Logger(org.slf4j.Logger) CdcKafkaPublisher(io.eventuate.local.common.CdcKafkaPublisher) PublishingStrategy(io.eventuate.local.common.PublishingStrategy) LoggerFactory(org.slf4j.LoggerFactory) EventuateLocalPublishingException(io.eventuate.local.common.exception.EventuateLocalPublishingException) Counter(io.micrometer.core.instrument.Counter) EventuateLocalPublishingException(io.eventuate.local.common.exception.EventuateLocalPublishingException)

Example 7 with Counter

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

the class FunctionCounterSample method main.

public static void main(String[] args) {
    MeterRegistry registry = SampleConfig.myMonitoringSystem();
    AtomicInteger n = new AtomicInteger(0);
    FunctionCounter.builder("my.fcounter", n, AtomicInteger::get).baseUnit("happiness").description("A counter derived from a monotonically increasing value").register(registry);
    Counter counter = Counter.builder("my.counter").baseUnit("happiness").description("A normal counter").register(registry);
    Flux.interval(Duration.ofMillis(10)).doOnEach(i -> {
        n.incrementAndGet();
        counter.increment();
    }).blockLast();
}
Also used : Counter(io.micrometer.core.instrument.Counter) Flux(reactor.core.publisher.Flux) SampleConfig(io.micrometer.core.samples.utils.SampleConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Duration(java.time.Duration) FunctionCounter(io.micrometer.core.instrument.FunctionCounter) Counter(io.micrometer.core.instrument.Counter) FunctionCounter(io.micrometer.core.instrument.FunctionCounter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 8 with Counter

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

the class CounterTest method incrementAmount.

@Test
@DisplayName("increment by a non-negative amount")
default void incrementAmount(MeterRegistry registry) {
    Counter c = registry.counter("myCounter");
    c.increment(2);
    c.increment(0);
    clock(registry).add(step());
    assertEquals(2L, c.count());
}
Also used : Counter(io.micrometer.core.instrument.Counter) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 9 with Counter

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

the class CounterTest method increment.

@DisplayName("multiple increments are maintained")
@Test
default void increment(MeterRegistry registry) {
    Counter c = registry.counter("myCounter");
    c.increment();
    clock(registry).add(step());
    assertThat(c.count()).isEqualTo(1.0, offset(1e-12));
    c.increment();
    c.increment();
    clock(registry).add(step());
    // in the case of a step aggregating system will be 2, otherwise 3
    assertThat(c.count()).isGreaterThanOrEqualTo(2.0);
}
Also used : Counter(io.micrometer.core.instrument.Counter) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 10 with Counter

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

the class ElasticMeterRegistryTest method wholeCountIsReportedWithDecimal.

@Issue("#498")
@Test
void wholeCountIsReportedWithDecimal() {
    Counter c = Counter.builder("counter").register(registry);
    c.increment(10);
    assertThat(registry.writeCounter(c, 0)).containsExactly("{\"index\":{\"_index\":\"metrics-1970-01\",\"_type\":\"doc\"}}\n" + "{\"@timestamp\":\"1970-01-01T00:00:00Z\",\"name\":\"counter\",\"type\":\"counter\",\"count\":0.0}");
}
Also used : Counter(io.micrometer.core.instrument.Counter) Issue(io.micrometer.core.Issue) Test(org.junit.jupiter.api.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