Class KafkaClientMetrics

java.lang.Object
io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics
All Implemented Interfaces:
MeterBinder, AutoCloseable

@Incubating(since="1.4.0") public class KafkaClientMetrics extends Object
Kafka Client metrics binder. This should be closed on application shutdown to clean up resources.

It is based on the Kafka client's metrics() method returning a Metric map.

Meter names have the following convention: kafka.(metric_group).(metric_name)

Since:
1.4.0
See Also:
  • Constructor Details

    • KafkaClientMetrics

      public KafkaClientMetrics(org.apache.kafka.clients.producer.Producer<?,?> kafkaProducer, Iterable<Tag> tags, ScheduledExecutorService scheduler)
      Kafka Producer metrics binder. The lifecycle of the custom scheduler passed is the responsibility of the caller. It will not be shut down when this instance is closed. A scheduler can be shared among multiple instances of KafkaClientMetrics to reduce resource usage by reducing the number of threads if there will be many instances.
      Parameters:
      kafkaProducer - producer instance to be instrumented
      tags - additional tags
      scheduler - custom scheduler to check and bind metrics
      Since:
      1.14.0
    • KafkaClientMetrics

      public KafkaClientMetrics(org.apache.kafka.clients.producer.Producer<?,?> kafkaProducer, Iterable<Tag> tags, ScheduledExecutorService scheduler, Duration refreshInterval)
      Kafka Producer metrics binder. The lifecycle of the custom scheduler passed is the responsibility of the caller. It will not be shut down when this instance is closed. A scheduler can be shared among multiple instances of KafkaClientMetrics to reduce resource usage by reducing the number of threads if there will be many instances.

      The refresh interval governs how frequently Micrometer should call the Kafka Client's Metrics API to discover new metrics to register and discard old ones since the Kafka Client can add/remove/recreate metrics on-the-fly. Please notice that this is not for fetching values for already registered metrics but for updating the list of registered metrics when the Kafka Client adds/removes/recreates them. It is the responsibility of the caller to choose the right value since this process can be expensive and metrics can appear and disappear without being published if the interval is not chosen appropriately.

      Parameters:
      kafkaProducer - producer instance to be instrumented
      tags - additional tags
      scheduler - custom scheduler to check and bind metrics
      refreshInterval - interval of discovering new/removed/recreated metrics by the Kafka Client
      Since:
      1.16.0
    • KafkaClientMetrics

      public KafkaClientMetrics(org.apache.kafka.clients.producer.Producer<?,?> kafkaProducer, Iterable<Tag> tags)
      Kafka Producer metrics binder
      Parameters:
      kafkaProducer - producer instance to be instrumented
      tags - additional tags
    • KafkaClientMetrics

      public KafkaClientMetrics(org.apache.kafka.clients.producer.Producer<?,?> kafkaProducer)
      Kafka Producer metrics binder
      Parameters:
      kafkaProducer - producer instance to be instrumented
    • KafkaClientMetrics

      public KafkaClientMetrics(org.apache.kafka.clients.consumer.Consumer<?,?> kafkaConsumer, Iterable<Tag> tags, ScheduledExecutorService scheduler)
      Kafka Consumer metrics binder. The lifecycle of the custom scheduler passed is the responsibility of the caller. It will not be shut down when this instance is closed. A scheduler can be shared among multiple instances of KafkaClientMetrics to reduce resource usage by reducing the number of threads if there will be many instances.
      Parameters:
      kafkaConsumer - consumer instance to be instrumented
      tags - additional tags
      scheduler - custom scheduler to check and bind metrics
      Since:
      1.14.0
    • KafkaClientMetrics

      public KafkaClientMetrics(org.apache.kafka.clients.consumer.Consumer<?,?> kafkaConsumer, Iterable<Tag> tags, ScheduledExecutorService scheduler, Duration refreshInterval)
      Kafka Consumer metrics binder. The lifecycle of the custom scheduler passed is the responsibility of the caller. It will not be shut down when this instance is closed. A scheduler can be shared among multiple instances of KafkaClientMetrics to reduce resource usage by reducing the number of threads if there will be many instances.

      The refresh interval governs how frequently Micrometer should call the Kafka Client's Metrics API to discover new metrics to register and discard old ones since the Kafka Client can add/remove/recreate metrics on-the-fly. Please notice that this is not for fetching values for already registered metrics but for updating the list of registered metrics when the Kafka Client adds/removes/recreates them. It is the responsibility of the caller to choose the right value since this process can be expensive and metrics can appear and disappear without being published if the interval is not chosen appropriately.

      Parameters:
      kafkaConsumer - consumer instance to be instrumented
      tags - additional tags
      scheduler - custom scheduler to check and bind metrics
      refreshInterval - interval of discovering new/removed/recreated metrics by the Kafka Client
      Since:
      1.16.0
    • KafkaClientMetrics

      public KafkaClientMetrics(org.apache.kafka.clients.consumer.Consumer<?,?> kafkaConsumer, Iterable<Tag> tags)
      Kafka Consumer metrics binder
      Parameters:
      kafkaConsumer - consumer instance to be instrumented
      tags - additional tags
    • KafkaClientMetrics

      public KafkaClientMetrics(org.apache.kafka.clients.consumer.Consumer<?,?> kafkaConsumer)
      Kafka Consumer metrics binder
      Parameters:
      kafkaConsumer - consumer instance to be instrumented
    • KafkaClientMetrics

      public KafkaClientMetrics(org.apache.kafka.clients.admin.AdminClient adminClient, Iterable<Tag> tags, ScheduledExecutorService scheduler)
      Kafka AdminClient metrics binder. The lifecycle of the custom scheduler passed is the responsibility of the caller. It will not be shut down when this instance is closed. A scheduler can be shared among multiple instances of KafkaClientMetrics to reduce resource usage by reducing the number of threads if there will be many instances.
      Parameters:
      adminClient - instance to be instrumented
      tags - additional tags
      scheduler - custom scheduler to check and bind metrics
      Since:
      1.14.0
    • KafkaClientMetrics

      public KafkaClientMetrics(org.apache.kafka.clients.admin.AdminClient adminClient, Iterable<Tag> tags, ScheduledExecutorService scheduler, Duration refreshInterval)
      Kafka AdminClient metrics binder. The lifecycle of the custom scheduler passed is the responsibility of the caller. It will not be shut down when this instance is closed. A scheduler can be shared among multiple instances of KafkaClientMetrics to reduce resource usage by reducing the number of threads if there will be many instances.

      The refresh interval governs how frequently Micrometer should call the Kafka Client's Metrics API to discover new metrics to register and discard old ones since the Kafka Client can add/remove/recreate metrics on-the-fly. Please notice that this is not for fetching values for already registered metrics but for updating the list of registered metrics when the Kafka Client adds/removes/recreates them. It is the responsibility of the caller to choose the right value since this process can be expensive and metrics can appear and disappear without being published if the interval is not chosen appropriately.

      Parameters:
      adminClient - instance to be instrumented
      tags - additional tags
      scheduler - custom scheduler to check and bind metrics
      refreshInterval - interval of discovering new/removed/recreated metrics by the Kafka Client
      Since:
      1.16.0
    • KafkaClientMetrics

      public KafkaClientMetrics(org.apache.kafka.clients.admin.AdminClient adminClient, Iterable<Tag> tags)
      Kafka AdminClient metrics binder
      Parameters:
      adminClient - instance to be instrumented
      tags - additional tags
    • KafkaClientMetrics

      public KafkaClientMetrics(org.apache.kafka.clients.admin.AdminClient adminClient)
      Kafka AdminClient metrics binder
      Parameters:
      adminClient - instance to be instrumented
  • Method Details