Search in sources :

Example 1 with KafkaClientMetrics

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());
        }
    }
}
Also used : KafkaClientMetrics(io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics)

Example 2 with KafkaClientMetrics

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());
        }
    }
}
Also used : KafkaClientMetrics(io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics)

Example 3 with KafkaClientMetrics

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;
}
Also used : KafkaClientMetrics(io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics)

Example 4 with KafkaClientMetrics

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();
}
Also used : ShutdownEvent(io.quarkus.runtime.ShutdownEvent) KafkaClientMetrics(io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics) Test(org.junit.jupiter.api.Test)

Example 5 with KafkaClientMetrics

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);
    }
}
Also used : KafkaClientMetrics(io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics)

Aggregations

KafkaClientMetrics (io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics)6 ShutdownEvent (io.quarkus.runtime.ShutdownEvent)1 Test (org.junit.jupiter.api.Test)1