use of io.micrometer.core.instrument.Counter in project eventuate-local by eventuate-local.
the class DbLogBasedCdcKafkaPublisher method handleEvent.
@Override
public void handleEvent(EVENT publishedEvent) throws EventuateLocalPublishingException {
Objects.requireNonNull(publishedEvent);
logger.trace("Got record " + publishedEvent.toString());
String aggregateTopic = publishingStrategy.topicFor(publishedEvent);
String json = publishingStrategy.toJson(publishedEvent);
Exception lastException = null;
for (int i = 0; i < 5; i++) {
try {
if (duplicatePublishingDetector.shouldBePublished(publishedEvent.getBinlogFileOffset(), aggregateTopic)) {
producer.send(aggregateTopic, publishingStrategy.partitionKeyFor(publishedEvent), json).get(10, TimeUnit.SECONDS);
publishingStrategy.getCreateTime(publishedEvent).ifPresent(time -> histogramEventAge.ifPresent(x -> x.set(System.currentTimeMillis() - time)));
meterEventsPublished.ifPresent(Counter::increment);
databaseOffsetKafkaStore.save(publishedEvent.getBinlogFileOffset());
} else {
logger.debug("Duplicate event {}", publishedEvent);
meterEventsDuplicates.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 vertx-micrometer-metrics by vert-x3.
the class CountersTest method shouldIgnoreCounterLabel.
@Test
public void shouldIgnoreCounterLabel() {
MeterRegistry registry = new SimpleMeterRegistry();
BackendRegistries.registerMatchers(registry, Collections.singletonList(new Match().setLabel("address").setType(MatchType.REGEX).setValue(".*").setAlias("_")));
Counters counters = new Counters("my_counter", "", registry, Label.ADDRESS);
counters.get("addr1").increment();
counters.get("addr1").increment();
counters.get("addr2").increment();
Counter c = registry.find("my_counter").tags("address", "_").counter();
assertThat(c.count()).isEqualTo(3d);
c = registry.find("my_counter").tags("address", "addr1").counter();
assertThat(c).isNull();
c = registry.find("my_counter").tags("address", "addr2").counter();
assertThat(c).isNull();
}
use of io.micrometer.core.instrument.Counter in project vertx-micrometer-metrics by vert-x3.
the class CountersTest method shouldAliasCounterLabel.
@Test
public void shouldAliasCounterLabel() {
MeterRegistry registry = new SimpleMeterRegistry();
BackendRegistries.registerMatchers(registry, Collections.singletonList(new Match().setLabel("address").setType(MatchType.REGEX).setValue("addr1").setAlias("1")));
Counters counters = new Counters("my_counter", "", registry, Label.ADDRESS);
counters.get("addr1").increment();
counters.get("addr1").increment();
counters.get("addr2").increment();
Counter c = registry.find("my_counter").tags("address", "1").counter();
assertThat(c.count()).isEqualTo(2d);
c = registry.find("my_counter").tags("address", "addr1").counter();
assertThat(c).isNull();
c = registry.find("my_counter").tags("address", "addr2").counter();
assertThat(c.count()).isEqualTo(1d);
}
use of io.micrometer.core.instrument.Counter in project micrometer by micrometer-metrics.
the class CounterSample method main.
public static void main(String[] args) {
MeterRegistry registry = SampleConfig.myMonitoringSystem();
Counter counter = registry.counter("counter", "method", "actual");
AtomicInteger n = new AtomicInteger(0);
registry.more().counter("counter", Tags.of("method", "function"), n);
RandomEngine r = new MersenneTwister64(0);
Normal dist = new Normal(0, 1, r);
Flux.interval(Duration.ofMillis(10)).doOnEach(d -> {
if (dist.nextDouble() + 0.1 > 0) {
counter.increment();
n.incrementAndGet();
}
}).blockLast();
}
use of io.micrometer.core.instrument.Counter in project spring-cloud-netflix by spring-cloud.
the class DefaultCounterFactoryTests method shouldIncrement.
@Test
public void shouldIncrement() throws Exception {
MeterRegistry meterRegistry = mock(MeterRegistry.class);
CounterFactory factory = new DefaultCounterFactory(meterRegistry);
Counter counter = mock(Counter.class);
when(meterRegistry.counter(NAME)).thenReturn(counter);
factory.increment(NAME);
verify(counter).increment();
}
Aggregations