Search in sources :

Example 1 with TimeCappedMovingAverageIntervalEstimator

use of org.LatencyUtils.TimeCappedMovingAverageIntervalEstimator in project micrometer by micrometer-metrics.

the class AbstractTimer method initPauseDetector.

private void initPauseDetector(PauseDetector pauseDetectorType) {
    org.LatencyUtils.PauseDetector pauseDetector = requireNonNull(pauseDetectorCache.computeIfAbsent(pauseDetectorType, detector -> {
        if (detector instanceof ClockDriftPauseDetector) {
            ClockDriftPauseDetector clockDriftPauseDetector = (ClockDriftPauseDetector) detector;
            return new SimplePauseDetector(clockDriftPauseDetector.getSleepInterval().toNanos(), clockDriftPauseDetector.getPauseThreshold().toNanos(), 1, false);
        } else if (detector instanceof NoPauseDetector) {
            return new NoopPauseDetector();
        }
        return new NoopPauseDetector();
    }));
    this.intervalEstimator = new TimeCappedMovingAverageIntervalEstimator(128, 10000000000L, pauseDetector);
    pauseDetector.addListener((pauseLength, pauseEndTime) -> {
        // System.out.println("Pause of length " + (pauseLength / 1e6) + "ms, end time " + pauseEndTime);
        if (intervalEstimator != null) {
            long estimatedInterval = intervalEstimator.getEstimatedInterval(pauseEndTime);
            long observedLatencyMinbar = pauseLength - estimatedInterval;
            if (observedLatencyMinbar >= estimatedInterval) {
                recordValueWithExpectedInterval(observedLatencyMinbar, estimatedInterval);
            }
        }
    });
}
Also used : Nullable(io.micrometer.core.lang.Nullable) PauseDetector(io.micrometer.core.instrument.distribution.pause.PauseDetector) io.micrometer.core.instrument.distribution(io.micrometer.core.instrument.distribution) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TimeCappedMovingAverageIntervalEstimator(org.LatencyUtils.TimeCappedMovingAverageIntervalEstimator) IntervalEstimator(org.LatencyUtils.IntervalEstimator) Callable(java.util.concurrent.Callable) ClockDriftPauseDetector(io.micrometer.core.instrument.distribution.pause.ClockDriftPauseDetector) Supplier(java.util.function.Supplier) SimplePauseDetector(org.LatencyUtils.SimplePauseDetector) TimeUnit(java.util.concurrent.TimeUnit) MeterEquivalence(io.micrometer.core.instrument.util.MeterEquivalence) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) NoPauseDetector(io.micrometer.core.instrument.distribution.pause.NoPauseDetector) TimeCappedMovingAverageIntervalEstimator(org.LatencyUtils.TimeCappedMovingAverageIntervalEstimator) NoPauseDetector(io.micrometer.core.instrument.distribution.pause.NoPauseDetector) ClockDriftPauseDetector(io.micrometer.core.instrument.distribution.pause.ClockDriftPauseDetector) SimplePauseDetector(org.LatencyUtils.SimplePauseDetector)

Aggregations

io.micrometer.core.instrument.distribution (io.micrometer.core.instrument.distribution)1 ClockDriftPauseDetector (io.micrometer.core.instrument.distribution.pause.ClockDriftPauseDetector)1 NoPauseDetector (io.micrometer.core.instrument.distribution.pause.NoPauseDetector)1 PauseDetector (io.micrometer.core.instrument.distribution.pause.PauseDetector)1 MeterEquivalence (io.micrometer.core.instrument.util.MeterEquivalence)1 Nullable (io.micrometer.core.lang.Nullable)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Callable (java.util.concurrent.Callable)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TimeUnit (java.util.concurrent.TimeUnit)1 Supplier (java.util.function.Supplier)1 IntervalEstimator (org.LatencyUtils.IntervalEstimator)1 SimplePauseDetector (org.LatencyUtils.SimplePauseDetector)1 TimeCappedMovingAverageIntervalEstimator (org.LatencyUtils.TimeCappedMovingAverageIntervalEstimator)1