@Override
    public Object metricValue() {
        long now = time.milliseconds();
        synchronized (this.lock) {
            if (isMeasurable())
                return ((Measurable) metricValueProvider).measure(config, now);
            else if (this.metricValueProvider instanceof Gauge)
                return ((Gauge<?>) metricValueProvider).value(config, now);
            else
                throw new IllegalStateException("Not a valid metric: " + this.metricValueProvider.getClass());
        }
    }
Take the metric and return the value, which could be a {@link Measurable} or a {@link Gauge}
@return Return the metric value
@throws IllegalStateException if the underlying metric is not a {@link Measurable} or a {@link Gauge}.
clients/src/main/java/org/apache/kafka/common/metrics/KafkaMetric.java