Class MetricUtil

java.lang.Object
org.apache.flink.connector.kafka.MetricUtil

@Internal public class MetricUtil extends Object
Collection of methods to interact with Kafka's client metric system.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.apache.kafka.common.Metric
    getKafkaMetric(Map<org.apache.kafka.common.MetricName,? extends org.apache.kafka.common.Metric> metrics, String metricGroup, String metricName)
    Tries to find the Kafka Metric in the provided metrics.
    static org.apache.kafka.common.Metric
    getKafkaMetric(Map<org.apache.kafka.common.MetricName,? extends org.apache.kafka.common.Metric> metrics, java.util.function.Predicate<Map.Entry<org.apache.kafka.common.MetricName,? extends org.apache.kafka.common.Metric>> filter)
    Tries to find the Kafka Metric in the provided metrics matching a given filter.
    static void
    sync(org.apache.kafka.common.Metric from, org.apache.flink.metrics.Counter to)
    Ensures that the counter has the same value as the given Kafka metric.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MetricUtil

      public MetricUtil()
  • Method Details

    • getKafkaMetric

      public static org.apache.kafka.common.Metric getKafkaMetric(Map<org.apache.kafka.common.MetricName,? extends org.apache.kafka.common.Metric> metrics, String metricGroup, String metricName)
      Tries to find the Kafka Metric in the provided metrics.
      Returns:
      Metric which exposes continuous updates
      Throws:
      IllegalStateException - if the metric is not part of the provided metrics
    • getKafkaMetric

      public static org.apache.kafka.common.Metric getKafkaMetric(Map<org.apache.kafka.common.MetricName,? extends org.apache.kafka.common.Metric> metrics, java.util.function.Predicate<Map.Entry<org.apache.kafka.common.MetricName,? extends org.apache.kafka.common.Metric>> filter)
      Tries to find the Kafka Metric in the provided metrics matching a given filter.
      Returns:
      Metric which exposes continuous updates
      Throws:
      IllegalStateException - if no metric matches the given filter
    • sync

      public static void sync(org.apache.kafka.common.Metric from, org.apache.flink.metrics.Counter to)
      Ensures that the counter has the same value as the given Kafka metric.

      Do not use this method for every record because Metric.metricValue() is an expensive operation.

      Parameters:
      from - Kafka's Metric to query
      to - Counter to write the value to