io.micrometer.core.instrument.distribution.pause.PauseDetector Java Examples

The following examples show how to use io.micrometer.core.instrument.distribution.pause.PauseDetector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SkywalkingTimer.java    From skywalking with Apache License 2.0 6 votes vote down vote up
protected SkywalkingTimer(Id id, MeterId meterId, SkywalkingConfig config, Clock clock,
                          DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector,
                          TimeUnit baseTimeUnit, boolean supportsAggregablePercentiles) {
    super(id, clock, distributionStatisticConfig, pauseDetector, baseTimeUnit, supportsAggregablePercentiles);

    // meter base name
    String baseName = meterId.getName();

    this.counter = MeterBuilder.buildCounter(meterId.copyTo(baseName + "_count", MeterId.MeterType.COUNTER), config);
    this.sum = MeterBuilder.buildCounter(meterId.copyTo(baseName + "_sum", MeterId.MeterType.COUNTER), config);
    this.maxAdder = new DoubleAccumulator((a, b) -> a > b ? a : b, 0.000);
    this.max = MeterFactory.gauge(meterId.copyTo(baseName + "_max", MeterId.MeterType.GAUGE),
        () -> maxAdder.doubleValue()).build();

    this.histogram = MeterBuilder.buildHistogram(meterId, supportsAggregablePercentiles, distributionStatisticConfig, true);
}
 
Example #2
Source File: AbstractTimer.java    From micrometer with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new timer.
 *
 * @param id                            The timer's name and tags.
 * @param clock                         The clock used to measure latency.
 * @param distributionStatisticConfig   Configuration determining which distribution statistics are sent.
 * @param pauseDetector                 Compensation for coordinated omission.
 * @param baseTimeUnit                  The time scale of this timer.
 * @param supportsAggregablePercentiles Indicates whether the registry supports percentile approximations from histograms.
 */
protected AbstractTimer(Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig,
                        PauseDetector pauseDetector, TimeUnit baseTimeUnit, boolean supportsAggregablePercentiles) {
    super(id);
    this.clock = clock;
    this.baseTimeUnit = baseTimeUnit;

    initPauseDetector(pauseDetector);

    if (distributionStatisticConfig.isPublishingPercentiles()) {
        // hdr-based histogram
        this.histogram = new TimeWindowPercentileHistogram(clock, distributionStatisticConfig, supportsAggregablePercentiles);
    } else if (distributionStatisticConfig.isPublishingHistogram()) {
        // fixed boundary histograms, which have a slightly better memory footprint
        // when we don't need Micrometer-computed percentiles
        this.histogram = new TimeWindowFixedBoundaryHistogram(clock, distributionStatisticConfig, supportsAggregablePercentiles);
    } else {
        // noop histogram
        this.histogram = NoopHistogram.INSTANCE;
    }
}
 
Example #3
Source File: AbstractTimer.java    From micrometer with Apache License 2.0 6 votes vote down vote up
private void initPauseDetector(PauseDetector pauseDetectorType) {
        pauseDetector = pauseDetectorCache.computeIfAbsent(pauseDetectorType, detector -> {
            if (detector instanceof ClockDriftPauseDetector) {
                ClockDriftPauseDetector clockDriftPauseDetector = (ClockDriftPauseDetector) detector;
                return new SimplePauseDetector(clockDriftPauseDetector.getSleepInterval().toNanos(),
                        clockDriftPauseDetector.getPauseThreshold().toNanos(), 1, false);
            }
            return null;
        });

        if (pauseDetector instanceof SimplePauseDetector) {
            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);
                    }
                }
            });
        }
    }
 
Example #4
Source File: StepTimerTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Issue("#1814")
@Test
void meanShouldWorkIfTotalTimeNotCalled() {
    Duration stepDuration = Duration.ofMillis(10);
    MockClock clock = new MockClock();
    StepTimer timer = new StepTimer(
            mock(Meter.Id.class),
            clock,
            DistributionStatisticConfig.builder().expiry(stepDuration).bufferLength(2).build(),
            mock(PauseDetector.class),
            TimeUnit.MILLISECONDS,
            stepDuration.toMillis(),
            false
    );

    clock.add(stepDuration);
    assertThat(timer.mean(TimeUnit.MILLISECONDS)).isEqualTo(0.0);

    clock.add(Duration.ofMillis(1));
    timer.record(Duration.ofMillis(50));
    timer.record(Duration.ofMillis(100));

    clock.add(stepDuration);
    assertThat(timer.mean(TimeUnit.MILLISECONDS)).isEqualTo(75.0);
}
 
Example #5
Source File: SimpleMeterRegistry.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Override
protected Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector) {
    DistributionStatisticConfig merged = distributionStatisticConfig.merge(DistributionStatisticConfig.builder()
            .expiry(config.step())
            .build());

    Timer timer;
    switch (config.mode()) {
        case CUMULATIVE:
            timer = new CumulativeTimer(id, clock, merged, pauseDetector, getBaseTimeUnit(), false);
            break;
        case STEP:
        default:
            timer = new StepTimer(id, clock, merged, pauseDetector, getBaseTimeUnit(), config.step().toMillis(), false);
            break;
    }

    HistogramGauges.registerWithCommonFormat(timer, this);

    return timer;
}
 
Example #6
Source File: DefaultDestinationPublishingMeterRegistry.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@Override
protected Timer newTimer(Id id,
		DistributionStatisticConfig distributionStatisticConfig,
		PauseDetector pauseDetector) {
	return new StepTimer(id, this.clock, distributionStatisticConfig, pauseDetector,
			getBaseTimeUnit(), this.metricsPublisherConfig.step().toMillis(), false);
}
 
Example #7
Source File: PrometheusMeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
protected io.micrometer.core.instrument.Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector) {
    PrometheusTimer timer = new PrometheusTimer(id, clock, distributionStatisticConfig, pauseDetector, prometheusConfig.histogramFlavor());
    applyToCollector(id, (collector) ->
            addDistributionStatisticSamples(distributionStatisticConfig, collector, timer, tagValues(id), false));
    return timer;
}
 
Example #8
Source File: PrometheusTimer.java    From micrometer with Apache License 2.0 5 votes vote down vote up
PrometheusTimer(Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector, HistogramFlavor histogramFlavor) {
    super(id, clock,
            DistributionStatisticConfig.builder()
                    .percentilesHistogram(false)
                    .serviceLevelObjectives()
                    .build()
                    .merge(distributionStatisticConfig),
            pauseDetector, TimeUnit.SECONDS, false);

    this.histogramFlavor = histogramFlavor;
    this.max = new TimeWindowMax(clock, distributionStatisticConfig);

    if (distributionStatisticConfig.isPublishingHistogram()) {
        switch (histogramFlavor) {
            case Prometheus:
                histogram = new TimeWindowFixedBoundaryHistogram(clock, DistributionStatisticConfig.builder()
                        .expiry(Duration.ofDays(1825)) // effectively never roll over
                        .bufferLength(1)
                        .build()
                        .merge(distributionStatisticConfig), true);
                break;
            case VictoriaMetrics:
                histogram = new FixedBoundaryVictoriaMetricsHistogram();
                break;
            default:
                histogram = null;
                break;
        }
    } else {
        histogram = null;
    }
}
 
Example #9
Source File: StatsdMeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
protected Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, PauseDetector
        pauseDetector) {

    // Adds an infinity bucket for SLO violation calculation
    if (distributionStatisticConfig.getServiceLevelObjectiveBoundaries() != null) {
        distributionStatisticConfig = addInfBucket(distributionStatisticConfig);
    }

    Timer timer = new StatsdTimer(id, lineBuilder(id), fluxSink, clock, distributionStatisticConfig, pauseDetector, getBaseTimeUnit(),
            statsdConfig.step().toMillis());
    HistogramGauges.registerWithCommonFormat(timer, this);
    return timer;
}
 
Example #10
Source File: StatsdTimer.java    From micrometer with Apache License 2.0 5 votes vote down vote up
StatsdTimer(Id id, StatsdLineBuilder lineBuilder, FluxSink<String> sink, Clock clock,
            DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector, TimeUnit baseTimeUnit, long stepMillis) {
    super(id, clock, distributionStatisticConfig, pauseDetector, baseTimeUnit, false);
    this.max = new StepDouble(clock, stepMillis);
    this.lineBuilder = lineBuilder;
    this.sink = sink;
}
 
Example #11
Source File: WavefrontMeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
protected Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig,
                         PauseDetector pauseDetector) {
    WavefrontTimer timer = new WavefrontTimer(id, clock, distributionStatisticConfig, pauseDetector, getBaseTimeUnit());
    if (!timer.isPublishingHistogram()) {
        HistogramGauges.registerWithCommonFormat(timer, this);
    }
    return timer;
}
 
Example #12
Source File: OpenTSDBTimer.java    From micrometer with Apache License 2.0 5 votes vote down vote up
OpenTSDBTimer(Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector,
              @Nullable OpenTSDBFlavor flavor) {
    super(id, clock,
            DistributionStatisticConfig.builder()
                    .percentilesHistogram(false)
                    .serviceLevelObjectives()
                    .build()
                    .merge(distributionStatisticConfig),
            pauseDetector, TimeUnit.SECONDS, false);

    this.max = new TimeWindowMax(clock, distributionStatisticConfig);

    if (distributionStatisticConfig.isPublishingHistogram()) {
        if (flavor == null) {
            histogram = new TimeWindowFixedBoundaryHistogram(clock, DistributionStatisticConfig.builder()
                    .expiry(Duration.ofDays(1825)) // effectively never roll over
                    .bufferLength(1)
                    .build()
                    .merge(distributionStatisticConfig), true);
        }
        else if (OpenTSDBFlavor.VictoriaMetrics.equals(flavor)) {
            histogram = new FixedBoundaryVictoriaMetricsHistogram();
        } else {
            histogram = null;
        }
    } else {
        histogram = null;
    }
}
 
Example #13
Source File: TimedAspectTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
protected Timer newTimer(@NonNull Id id,
                         @NonNull DistributionStatisticConfig distributionStatisticConfig,
                         @NonNull PauseDetector pauseDetector) {
    throw new RuntimeException();
}
 
Example #14
Source File: CumulativeTimer.java    From micrometer with Apache License 2.0 5 votes vote down vote up
public CumulativeTimer(Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig,
                       PauseDetector pauseDetector, TimeUnit baseTimeUnit, boolean supportsAggregablePercentiles) {
    super(id, clock, distributionStatisticConfig, pauseDetector, baseTimeUnit, supportsAggregablePercentiles);
    this.count = new AtomicLong();
    this.total = new AtomicLong();
    this.max = new TimeWindowMax(clock, distributionStatisticConfig);
}
 
Example #15
Source File: StepMeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
protected Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector) {
    Timer timer = new StepTimer(id, clock, distributionStatisticConfig, pauseDetector, getBaseTimeUnit(),
        this.config.step().toMillis(), false);
    HistogramGauges.registerWithCommonFormat(timer, this);
    return timer;
}
 
Example #16
Source File: SpectatorTimer.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public SpectatorTimer(Id id, Timer timer, Clock clock, DistributionStatisticConfig statsConf, PauseDetector pauseDetector, TimeUnit baseTimeUnit) {
    super(id, clock, statsConf, pauseDetector, baseTimeUnit, false);
    this.timer = timer;
}
 
Example #17
Source File: DropwizardMeterRegistry.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
protected Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector) {
    DropwizardTimer timer = new DropwizardTimer(id, registry.timer(hierarchicalName(id)), clock, distributionStatisticConfig, pauseDetector);
    HistogramGauges.registerWithCommonFormat(timer, this);
    return timer;
}
 
Example #18
Source File: SkywalkingMeterRegistry.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Override
protected Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector) {
    final MeterId meterId = convertId(id);
    return new SkywalkingTimer(id, meterId, config, clock, distributionStatisticConfig, pauseDetector, TimeUnit.MILLISECONDS, true);
}
 
Example #19
Source File: DropwizardTimer.java    From micrometer with Apache License 2.0 4 votes vote down vote up
DropwizardTimer(Id id, Timer impl, Clock clock, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector) {
    super(id, clock, distributionStatisticConfig, pauseDetector, TimeUnit.MILLISECONDS, false);
    this.impl = impl;
    this.max = new TimeWindowMax(clock, distributionStatisticConfig);
}
 
Example #20
Source File: NoopMeterRegistry.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
protected Timer newTimer(Id id, DistributionStatisticConfig histogramConfig, PauseDetector pauseDetector) {
    return new NoopTimer(id);
}
 
Example #21
Source File: NoopMeterRegistry.java    From dolphin-platform with Apache License 2.0 4 votes vote down vote up
@Override
protected Timer newTimer(final Meter.Id id, final DistributionStatisticConfig distributionStatisticConfig, final PauseDetector pauseDetector) {
    return new NoopTimer(id);
}
 
Example #22
Source File: StackdriverMeterRegistry.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
protected Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector) {
    return new StepTimer(id, clock, distributionStatisticConfig, pauseDetector, getBaseTimeUnit(),
            this.config.step().toMillis(), true);
}
 
Example #23
Source File: CumulativeTimer.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public CumulativeTimer(Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig,
                       PauseDetector pauseDetector, TimeUnit baseTimeUnit) {
    this(id, clock, distributionStatisticConfig, pauseDetector, baseTimeUnit, false);
}
 
Example #24
Source File: LoggingMeterRegistry.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
protected Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector) {
    return new StepTimer(id, clock, distributionStatisticConfig, pauseDetector, getBaseTimeUnit(),
            this.config.step().toMillis(), false);
}
 
Example #25
Source File: MeterRegistry.java    From micrometer with Apache License 2.0 4 votes vote down vote up
/**
 * @return The pause detector that is currently in effect.
 */
public PauseDetector pauseDetector() {
    return pauseDetector;
}
 
Example #26
Source File: WavefrontTimer.java    From micrometer with Apache License 2.0 4 votes vote down vote up
WavefrontTimer(Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig,
               PauseDetector pauseDetector, TimeUnit baseTimeUnit) {
    super(id, clock, distributionStatisticConfig, pauseDetector, baseTimeUnit, false);
    delegate = distributionStatisticConfig.isPublishingHistogram() ?
        new WavefrontHistogramImpl(clock::wallTime) : null;
}
 
Example #27
Source File: OpenTSDBMeterRegistry.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
protected Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector) {
    return new OpenTSDBTimer(id, clock, distributionStatisticConfig, pauseDetector, config.flavor());
}
 
Example #28
Source File: CompositeMeterRegistry.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
protected Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector) {
    return new CompositeTimer(id, clock, distributionStatisticConfig, pauseDetector);
}
 
Example #29
Source File: CompositeTimer.java    From micrometer with Apache License 2.0 4 votes vote down vote up
CompositeTimer(Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector) {
    super(id);
    this.clock = clock;
    this.distributionStatisticConfig = distributionStatisticConfig;
    this.pauseDetector = pauseDetector;
}
 
Example #30
Source File: StepTimer.java    From micrometer with Apache License 2.0 3 votes vote down vote up
/**
 * Create a new {@code StepTimer}.
 *
 * @param id                            ID
 * @param clock                         clock
 * @param distributionStatisticConfig   distribution statistic configuration
 * @param pauseDetector                 pause detector
 * @param baseTimeUnit                  base time unit
 * @param stepDurationMillis                    step in milliseconds
 * @param supportsAggregablePercentiles whether it supports aggregable percentiles
 */
public StepTimer(final Id id, final Clock clock, final DistributionStatisticConfig distributionStatisticConfig,
    final PauseDetector pauseDetector, final TimeUnit baseTimeUnit, final long stepDurationMillis,
    final boolean supportsAggregablePercentiles
) {
    super(id, clock, distributionStatisticConfig, pauseDetector, baseTimeUnit, supportsAggregablePercentiles);
    countTotal = new StepTuple2<>(clock, stepDurationMillis, 0L, 0L, count::sumThenReset, total::sumThenReset);
    max = new TimeWindowMax(clock, distributionStatisticConfig);
}