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