use of io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics in project hono by eclipse.
the class MicrometerKafkaClientMetricsSupport method registerKafkaProducer.
@Override
public void registerKafkaProducer(final Producer<?, ?> producer) {
Objects.requireNonNull(producer);
if (producerMetricsEnabled && !producerMetricsMap.containsKey(producer)) {
final KafkaClientMetrics kafkaClientMetrics = new KafkaClientMetrics(producer);
if (producerMetricsMap.putIfAbsent(producer, kafkaClientMetrics) == null) {
kafkaClientMetrics.bindTo(meterRegistry);
LOG.debug("registered producer ({} producers total)", producerMetricsMap.size());
}
}
}
use of io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics in project hono by eclipse.
the class MicrometerKafkaClientMetricsSupport method registerKafkaConsumer.
@Override
public void registerKafkaConsumer(final Consumer<?, ?> consumer) {
Objects.requireNonNull(consumer);
if (consumerMetricsEnabled && !consumerMetricsMap.containsKey(consumer)) {
final KafkaClientMetrics kafkaClientMetrics = new KafkaClientMetrics(consumer);
if (consumerMetricsMap.putIfAbsent(consumer, kafkaClientMetrics) == null) {
kafkaClientMetrics.bindTo(meterRegistry);
LOG.debug("registered consumer ({} consumers total)", consumerMetricsMap.size());
}
}
}
use of io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics in project kestra by kestra-io.
the class KafkaAdminService method of.
public AdminClient of() {
if (this.adminClient == null) {
Properties properties = new Properties();
properties.putAll(clientConfig.getProperties());
properties.put(CommonClientConfigs.CLIENT_ID_CONFIG, "default");
adminClient = AdminClient.create(properties);
if (metricsEnabled) {
kafkaClientMetrics = new KafkaClientMetrics(adminClient, List.of(Tag.of("client_type", "admin"), Tag.of("client_class_id", (String) properties.get(CommonClientConfigs.CLIENT_ID_CONFIG))));
metricRegistry.bind(kafkaClientMetrics);
}
}
return adminClient;
}
use of io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics in project quarkus by quarkusio.
the class KafkaEventObserverTest method testAllKafkaClientMetricsClosed.
@Test
void testAllKafkaClientMetricsClosed() {
KafkaEventObserver sut = new KafkaEventObserver();
KafkaClientMetrics firstClientMetrics = Mockito.mock(KafkaClientMetrics.class);
KafkaClientMetrics secondClientMetrics = Mockito.mock(KafkaClientMetrics.class);
sut.clientMetrics.put(firstClientMetrics, firstClientMetrics);
sut.clientMetrics.put(secondClientMetrics, secondClientMetrics);
sut.onStop(new ShutdownEvent());
Mockito.verify(firstClientMetrics).close();
Mockito.verify(secondClientMetrics).close();
}
use of io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics in project quarkus by quarkusio.
the class KafkaEventObserver method consumerCreated.
/**
* Manage bind/close of KafkaClientMetrics for the specified Consumer.
* If the consumer has not been seen before, it will be bound to the
* Micrometer registry and instrumented using a Kafka MeterBinder.
* If the consumer has been seen before, the MeterBinder will be closed.
*
* @param consumer Observed Kafka Consumer
*/
public synchronized void consumerCreated(@Observes Consumer<?, ?> consumer) {
KafkaClientMetrics metrics = clientMetrics.remove(consumer);
if (metrics == null) {
metrics = new KafkaClientMetrics(consumer);
try {
metrics.bindTo(registry);
clientMetrics.put(consumer, metrics);
} catch (Throwable t) {
log.warnf(t, "Unable to register metrics for Kafka consumer %s", consumer);
tryToClose(metrics);
}
} else {
tryToClose(metrics);
}
}
Aggregations