io.micrometer.core.instrument.distribution.DistributionStatisticConfig Java Examples

The following examples show how to use io.micrometer.core.instrument.distribution.DistributionStatisticConfig. 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: 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 #3
Source File: MeterBuilder.java    From skywalking with Apache License 2.0 6 votes vote down vote up
/**
 * Build the histogram
 * @return return histogram if support
 */
public static Optional<Histogram> buildHistogram(MeterId meterId, boolean supportsAggregablePercentiles,
                                                 DistributionStatisticConfig distributionStatisticConfig,
                                                 boolean useNanoTime) {
    if (!distributionStatisticConfig.isPublishingHistogram()) {
        return Optional.empty();
    }

    final NavigableSet<Double> buckets = distributionStatisticConfig.getHistogramBuckets(supportsAggregablePercentiles);
    final List<Double> steps = buckets.stream().sorted(Double::compare)
        .map(t -> useNanoTime ? TimeUtils.nanosToUnit(t, TimeUnit.MILLISECONDS) : t).collect(Collectors.toList());

    final Histogram.Builder histogramBuilder = MeterFactory.histogram(
        meterId.copyTo(meterId.getName() + "_histogram", MeterId.MeterType.HISTOGRAM)).steps(steps);
    final Double minimumExpectedValueAsDouble = distributionStatisticConfig.getMinimumExpectedValueAsDouble();
    if (minimumExpectedValueAsDouble != null) {
        histogramBuilder.minValue(useNanoTime ?
            TimeUtils.nanosToUnit(minimumExpectedValueAsDouble, TimeUnit.MILLISECONDS) : minimumExpectedValueAsDouble);
    }
    return Optional.of(histogramBuilder.build());
}
 
Example #4
Source File: SkywalkingDistributionSummary.java    From skywalking with Apache License 2.0 6 votes vote down vote up
protected SkywalkingDistributionSummary(Id id, MeterId meterId, SkywalkingConfig config, Clock clock,
                                        DistributionStatisticConfig distributionStatisticConfig, double scale,
                                        boolean supportsAggregablePercentiles) {
    super(id, clock, distributionStatisticConfig, scale, 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, false);
}
 
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: SimpleMeterRegistry.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Override
protected DistributionSummary newDistributionSummary(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, double scale) {
    DistributionStatisticConfig merged = distributionStatisticConfig.merge(DistributionStatisticConfig.builder()
            .expiry(config.step())
            .build());

    DistributionSummary summary;
    switch (config.mode()) {
        case CUMULATIVE:
            summary = new CumulativeDistributionSummary(id, clock, merged, scale, false);
            break;
        case STEP:
        default:
            summary = new StepDistributionSummary(id, clock, merged, scale, config.step().toMillis(), false);
            break;
    }

    HistogramGauges.registerWithCommonFormat(summary, this);

    return summary;
}
 
Example #7
Source File: PropertiesMeterFilter.java    From foremast with Apache License 2.0 6 votes vote down vote up
@Override
public DistributionStatisticConfig configure(Meter.Id id,
                                             DistributionStatisticConfig config) {
    Distribution distribution = this.properties.getDistribution();
    return DistributionStatisticConfig.builder()
            .percentilesHistogram(
                    lookupWithFallbackToAll(distribution.getPercentilesHistogram(), id, null))
            .percentiles(
                    lookupWithFallbackToAll(distribution.getPercentiles(), id, null))
            .sla(convertSla(id.getType(), lookup(distribution.getSla(), id, null)))
            .minimumExpectedValue(convertMeterValue(id.getType(),
                    lookup(distribution.getMinimumExpectedValue(), id, null)))
            .maximumExpectedValue(convertMeterValue(id.getType(),
                    lookup(distribution.getMaximumExpectedValue(), id, null)))
            .build().merge(config);
}
 
Example #8
Source File: PropertiesMeterFilter.java    From foremast with Apache License 2.0 6 votes vote down vote up
@Override
public DistributionStatisticConfig configure(Meter.Id id,
                                             DistributionStatisticConfig config) {
    Distribution distribution = this.properties.getDistribution();
    return DistributionStatisticConfig.builder()
            .percentilesHistogram(
                    lookupWithFallbackToAll(distribution.getPercentilesHistogram(), id, null))
            .percentiles(
                    lookupWithFallbackToAll(distribution.getPercentiles(), id, null))
            .sla(convertSla(id.getType(), lookup(distribution.getSla(), id, null)))
            .minimumExpectedValue(convertMeterValue(id.getType(),
                    lookup(distribution.getMinimumExpectedValue(), id, null)))
            .maximumExpectedValue(convertMeterValue(id.getType(),
                    lookup(distribution.getMaximumExpectedValue(), id, null)))
            .build().merge(config);
}
 
Example #9
Source File: AtlasMeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
protected DistributionStatisticConfig defaultHistogramConfig() {
    return DistributionStatisticConfig.builder()
            .expiry(atlasConfig.step())
            .build()
            .merge(DistributionStatisticConfig.DEFAULT);
}
 
Example #10
Source File: CompareHistogramsWithOtherLibraries.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Setup(Level.Trial)
public void setup() {
    double[] micrometerBuckets =
            Doubles.toArray(PercentileHistogramBuckets.buckets(
                    DistributionStatisticConfig.builder().minimumExpectedValue(0.0).maximumExpectedValue(Double.POSITIVE_INFINITY)
                            .percentilesHistogram(true).build()));
    histogram = io.prometheus.client.Histogram.build("histogram", "A histogram")
            .buckets(micrometerBuckets).create();
}
 
Example #11
Source File: TimerTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
default void recordMax(MeterRegistry registry) {
    Timer timer = registry.timer("my.timer");
    timer.record(10, TimeUnit.MILLISECONDS);
    timer.record(1, TimeUnit.SECONDS);

    clock(registry).add(step()); // for Atlas, which is step rather than ring-buffer based
    assertThat(timer.max(TimeUnit.SECONDS)).isEqualTo(1);
    assertThat(timer.max(TimeUnit.MILLISECONDS)).isEqualTo(1000);

    //noinspection ConstantConditions
    clock(registry).add(Duration.ofMillis(step().toMillis() * DistributionStatisticConfig.DEFAULT.getBufferLength()));
    assertThat(timer.max(TimeUnit.SECONDS)).isEqualTo(0);
}
 
Example #12
Source File: MeterFilterTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void maxExpectedOnSummary() {
    MeterFilter filter = MeterFilter.maxExpected("name", 100.0);
    Meter.Id timer = new Meter.Id("name", Tags.empty(), null, null, Meter.Type.DISTRIBUTION_SUMMARY);

    assertThat(filter.configure(timer, DistributionStatisticConfig.DEFAULT))
            .satisfies(conf -> assertThat(conf.getMaximumExpectedValueAsDouble()).isEqualTo(100));
}
 
Example #13
Source File: MeterFilterTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void maxExpectedOnTimer() {
    MeterFilter filter = MeterFilter.maxExpected("name", Duration.ofNanos(100));
    Meter.Id timer = new Meter.Id("name", Tags.empty(), null, null, Meter.Type.TIMER);

    assertThat(filter.configure(timer, DistributionStatisticConfig.DEFAULT))
            .satisfies(conf -> assertThat(conf.getMaximumExpectedValueAsDouble()).isEqualTo(100));
}
 
Example #14
Source File: MeterFilterTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void minExpectedOnTimer() {
    MeterFilter filter = MeterFilter.minExpected("name", Duration.ofNanos(100));
    Meter.Id timer = new Meter.Id("name", Tags.empty(), null, null, Meter.Type.TIMER);

    assertThat(filter.configure(timer, DistributionStatisticConfig.DEFAULT))
            .satisfies(conf -> assertThat(conf.getMinimumExpectedValueAsDouble()).isEqualTo(100));
}
 
Example #15
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 #16
Source File: WavefrontDistributionSummary.java    From micrometer with Apache License 2.0 5 votes vote down vote up
WavefrontDistributionSummary(Id id, Clock clock,
                             DistributionStatisticConfig distributionStatisticConfig,
                             double scale) {
    super(id, clock, distributionStatisticConfig, scale, false);
    delegate = distributionStatisticConfig.isPublishingHistogram() ?
        new WavefrontHistogramImpl(clock::wallTime) : null;
}
 
Example #17
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 #18
Source File: WavefrontMeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
protected DistributionSummary newDistributionSummary(
        Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, double scale) {
    WavefrontDistributionSummary summary = new WavefrontDistributionSummary(id, clock, distributionStatisticConfig, scale);
    if (!summary.isPublishingHistogram()) {
        HistogramGauges.registerWithCommonFormat(summary, this);
    }
    return summary;
}
 
Example #19
Source File: StatsdDistributionSummary.java    From micrometer with Apache License 2.0 5 votes vote down vote up
StatsdDistributionSummary(Meter.Id id, StatsdLineBuilder lineBuilder, FluxSink<String> sink, Clock clock,
                          DistributionStatisticConfig distributionStatisticConfig, double scale) {
    super(id, clock, distributionStatisticConfig, scale, false);
    this.max = new TimeWindowMax(clock, distributionStatisticConfig);
    this.lineBuilder = lineBuilder;
    this.sink = sink;
}
 
Example #20
Source File: AtlasMeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
protected LongTaskTimer newLongTaskTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig) {
    SpectatorLongTaskTimer ltt = new SpectatorLongTaskTimer(id, com.netflix.spectator.api.patterns.LongTaskTimer.get(registry, spectatorId(id)),
            clock, distributionStatisticConfig);
    registerHistogramGauges(ltt, ltt.getId(), ltt.baseTimeUnit());
    return ltt;
}
 
Example #21
Source File: StatsdMeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
protected LongTaskTimer newLongTaskTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig) {
    StatsdLongTaskTimer ltt = new StatsdLongTaskTimer(id, lineBuilder(id), fluxSink, clock, statsdConfig.publishUnchangedMeters(),
            distributionStatisticConfig, getBaseTimeUnit());
    HistogramGauges.registerWithCommonFormat(ltt, this);
    pollableMeters.put(id, ltt);
    return ltt;
}
 
Example #22
Source File: OpenTSDBMeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
protected DistributionStatisticConfig defaultHistogramConfig() {
    return DistributionStatisticConfig.builder()
            .expiry(config.step())
            .build()
            .merge(DistributionStatisticConfig.DEFAULT);
}
 
Example #23
Source File: MeterFilterTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void minExpectedOnSummary() {
    MeterFilter filter = MeterFilter.minExpected("name", 100.0);
    Meter.Id timer = new Meter.Id("name", Tags.empty(), null, null, Meter.Type.DISTRIBUTION_SUMMARY);

    assertThat(filter.configure(timer, DistributionStatisticConfig.DEFAULT))
            .satisfies(conf -> assertThat(conf.getMinimumExpectedValueAsDouble()).isEqualTo(100));
}
 
Example #24
Source File: MeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
/**
 * Only used by {@link LongTaskTimer#builder(String)}.
 *
 * @param id The identifier for this long task timer.
 * @return A new or existing long task timer.
 */
LongTaskTimer longTaskTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig) {
    return registerMeterIfNecessary(LongTaskTimer.class, id, distributionStatisticConfig, (id2, filteredConfig) -> {
        Meter.Id withUnit = id2.withBaseUnit(getBaseTimeUnitStr());
        return newLongTaskTimer(withUnit, filteredConfig.merge(defaultHistogramConfig()));
    }, NoopLongTaskTimer::new);
}
 
Example #25
Source File: MeterFilter.java    From micrometer with Apache License 2.0 5 votes vote down vote up
/**
 * Set a minimum expected value on any {@link DistributionSummary} whose name begins with the given prefix.
 *
 * @param prefix Apply the minimum only to distribution summaries whose name begins with this prefix.
 * @param min    The minimum expected value of the distribution summary.
 * @return A filter that applies a minimum expected value to a distribution summary.
 * @since 1.4.0
 */
static MeterFilter minExpected(String prefix, double min) {
    return new MeterFilter() {
        @Override
        public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
            if (id.getType() == Meter.Type.DISTRIBUTION_SUMMARY && id.getName().startsWith(prefix)) {
                return DistributionStatisticConfig.builder()
                        .minimumExpectedValue(min)
                        .build()
                        .merge(config);
            }
            return config;
        }
    };
}
 
Example #26
Source File: MeterFilter.java    From micrometer with Apache License 2.0 5 votes vote down vote up
/**
 * Set a minimum expected value on any {@link Timer} whose name begins with the given prefix.
 *
 * @param prefix Apply the minimum only to timers whose name begins with this prefix.
 * @param min    The minimum expected value of the timer.
 * @return A filter that applies a minimum expected value to a timer.
 */
static MeterFilter minExpected(String prefix, Duration min) {
    return new MeterFilter() {
        @Override
        public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
            if (id.getType() == Meter.Type.TIMER && id.getName().startsWith(prefix)) {
                return DistributionStatisticConfig.builder()
                        .minimumExpectedValue((double) min.toNanos())
                        .build()
                        .merge(config);
            }
            return config;
        }
    };
}
 
Example #27
Source File: MeterFilter.java    From micrometer with Apache License 2.0 5 votes vote down vote up
/**
 * Set a maximum expected value on any {@link DistributionSummary} whose name begins with the given prefix.
 *
 * @param prefix Apply the maximum only to distribution summaries whose name begins with this prefix.
 * @param max    The maximum expected value of the distribution summary.
 * @return A filter that applies a maximum expected value to a distribution summary.
 * @since 1.4.0
 */
static MeterFilter maxExpected(String prefix, double max) {
    return new MeterFilter() {
        @Override
        public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
            if (id.getType() == Meter.Type.DISTRIBUTION_SUMMARY && id.getName().startsWith(prefix)) {
                return DistributionStatisticConfig.builder()
                        .maximumExpectedValue(max)
                        .build()
                        .merge(config);
            }
            return config;
        }
    };
}
 
Example #28
Source File: MeterFilter.java    From micrometer with Apache License 2.0 5 votes vote down vote up
/**
 * Set a maximum expected value on any {@link Timer} whose name begins with the given prefix.
 *
 * @param prefix Apply the maximum only to timers whose name begins with this prefix.
 * @param max    The maximum expected value of the timer.
 * @return A filter that applies a maximum expected value to a timer.
 */
static MeterFilter maxExpected(String prefix, Duration max) {
    return new MeterFilter() {
        @Override
        public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
            if (id.getType() == Meter.Type.TIMER && id.getName().startsWith(prefix)) {
                return DistributionStatisticConfig.builder()
                        .maximumExpectedValue((double) max.toNanos())
                        .build()
                        .merge(config);
            }
            return config;
        }
    };
}
 
Example #29
Source File: SimpleMeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
protected DistributionStatisticConfig defaultHistogramConfig() {
    return DistributionStatisticConfig.builder()
            .expiry(config.step())
            .build()
            .merge(DistributionStatisticConfig.DEFAULT);
}
 
Example #30
Source File: MyRegistryCustomizer.java    From summerframework with Apache License 2.0 5 votes vote down vote up
@Override
public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
    if (types.contains(id.getType())) {
        return DistributionStatisticConfig.builder().percentiles(getPercentiles()).build().merge(config);
    }
    return config;
}