Class KafkaMetric

java.lang.Object
org.apache.kafka.common.metrics.KafkaMetric
All Implemented Interfaces:
Metric

@Public public final class KafkaMetric extends Object implements Metric
  • Constructor Details

    • KafkaMetric

      @SuppressKafkaInternalApiUsage("KIP-1265: ctor leaks internal Time for test injection \u2014 pending KIP review to promote Time or refactor") public KafkaMetric(Object lock, MetricName metricName, MetricValueProvider<?> valueProvider, MetricConfig config, org.apache.kafka.common.utils.Time time)
      Create a metric to monitor an object that implements MetricValueProvider.
      Parameters:
      lock - The lock used to prevent race condition
      metricName - The name of the metric
      valueProvider - The metric value provider associated with this metric
      config - The configuration of the metric
      time - The time instance to use with the metrics
  • Method Details

    • config

      public MetricConfig config()
      Get the configuration of this metric. This is supposed to be used by server only.
      Returns:
      Return the config of this metric
    • metricName

      public MetricName metricName()
      Get the metric name
      Specified by:
      metricName in interface Metric
      Returns:
      Return the name of this metric
    • metricValue

      public Object metricValue()
      Take the metric and return the value via MetricValueProvider.value(MetricConfig, long).
      Specified by:
      metricValue in interface Metric
      Returns:
      Return the metric value
    • isMeasurable

      public boolean isMeasurable()
      The method determines if the metric value provider is of type Measurable.
      Returns:
      true if the metric value provider is of type Measurable, false otherwise.
    • measurable

      public Measurable measurable()
      Get the underlying metric provider, which should be a Measurable
      Returns:
      Return the metric provider
      Throws:
      IllegalStateException - if the underlying metric is not a Measurable.
    • config

      public void config(MetricConfig config)
      Set the metric config. This is supposed to be used by server only.
      Parameters:
      config - configuration for this metrics
    • toString

      public String toString()
      Returns a human-readable representation of this metric.

      The metricValueProvider is represented by its class name rather than its full toString() to avoid dumping internal stat state (e.g. SampledStat's samples list) into logs, which could be verbose and is rarely useful for identifying which metric changed.

      Overrides:
      toString in class Object