@Override
    public double measure(MetricConfig config, long currentTimestampMs) {
        if (lastRecordedTimestampMs < 0) {
            // Return the default value if no recordings have been captured.
            return defaultRatio;
        } else {
            // We measure the ratio over the
            double intervalDurationMs = Math.max(lastRecordedTimestampMs - intervalStartTimestampMs, 0);
            final double ratio;
            if (intervalDurationMs == 0) {
                ratio = defaultRatio;
            } else if (totalRecordedDurationMs > intervalDurationMs) {
                ratio = 1.0;
            } else {
                ratio = totalRecordedDurationMs / intervalDurationMs;
            }

            // The next interval begins at the
            intervalStartTimestampMs = lastRecordedTimestampMs;
            totalRecordedDurationMs = 0;
            return ratio;
        }
    }
Maintains an approximate ratio of the duration of a specific event
over all time. For example, this can be used to compute the ratio of
time that a thread is busy or idle. The value is approximate since the
measurement and recording intervals may not be aligned.

Note that the duration of the event is assumed to be small relative to
the interval of measurement.
raft/src/main/java/org/apache/kafka/raft/internals/TimeRatio.java