Class KafkaMetric

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

public final class KafkaMetric extends Object implements Metric
  • Constructor Details

    • KafkaMetric

      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, which could be a Measurable or a Gauge
      Specified by:
      metricValue in interface Metric
      Returns:
      Return the metric value
      Throws:
      IllegalStateException - if the underlying metric is not a Measurable or a Gauge.
    • 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