Search in sources :

Example 1 with DistributionStatisticConfig

use of io.micrometer.core.instrument.distribution.DistributionStatisticConfig in project micrometer by micrometer-metrics.

the class MeterRegistryTest method histogramConfigTransformingMeterFilter.

@Test
void histogramConfigTransformingMeterFilter() {
    MeterRegistry registry = new SimpleMeterRegistry() {

        @Override
        protected Timer newTimer(@Nonnull Meter.Id id, DistributionStatisticConfig histogramConfig, PauseDetector pauseDetector) {
            assertThat(histogramConfig.isPublishingHistogram()).isTrue();
            return super.newTimer(id, histogramConfig, pauseDetector);
        }
    };
    registry.config().meterFilter(new MeterFilter() {

        @Override
        public DistributionStatisticConfig configure(Meter.Id mappedId, DistributionStatisticConfig config) {
            return DistributionStatisticConfig.builder().percentiles(0.95).percentilesHistogram(true).build().merge(config);
        }
    });
    registry.timer("my.timer");
}
Also used : MeterFilter(io.micrometer.core.instrument.config.MeterFilter) Nonnull(javax.annotation.Nonnull) PauseDetector(io.micrometer.core.instrument.distribution.pause.PauseDetector) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) DistributionStatisticConfig(io.micrometer.core.instrument.distribution.DistributionStatisticConfig) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Test(org.junit.jupiter.api.Test)

Example 2 with DistributionStatisticConfig

use of io.micrometer.core.instrument.distribution.DistributionStatisticConfig in project micrometer by micrometer-metrics.

the class TimedAspectTest method serviceIsTimedWithHistogram.

@Test
public void serviceIsTimedWithHistogram() {
    // given...
    // ... we are waiting for a metric to be created with a histogram
    AtomicReference<DistributionStatisticConfig> myConfig = new AtomicReference<>();
    registry.config().meterFilter(new MeterFilter() {

        @Override
        public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
            if (id.getName().equals("something")) {
                myConfig.set(config);
            }
            return config;
        }
    });
    // when...
    // ... the service is being called
    service.timeWithHistogram();
    // then...
    assertThat(myConfig.get()).as("the metric has been created").isNotNull();
    assertThat(myConfig.get().isPublishingHistogram()).as("the metric has a histogram").isTrue();
}
Also used : MeterFilter(io.micrometer.core.instrument.config.MeterFilter) Meter(io.micrometer.core.instrument.Meter) AtomicReference(java.util.concurrent.atomic.AtomicReference) DistributionStatisticConfig(io.micrometer.core.instrument.distribution.DistributionStatisticConfig) Test(org.junit.Test)

Example 3 with DistributionStatisticConfig

use of io.micrometer.core.instrument.distribution.DistributionStatisticConfig in project micrometer by micrometer-metrics.

the class MeterRegistry method registerMeterIfNecessary.

private <M extends Meter> M registerMeterIfNecessary(Class<M> meterClass, Meter.Id id, @Nullable DistributionStatisticConfig config, BiFunction<Meter.Id, DistributionStatisticConfig, Meter> builder, Function<Meter.Id, M> noopBuilder) {
    Meter.Id mappedId = id;
    for (MeterFilter filter : filters) {
        mappedId = filter.map(mappedId);
    }
    if (!accept(id)) {
        // noinspection unchecked
        return noopBuilder.apply(id);
    }
    if (config != null) {
        for (MeterFilter filter : filters) {
            DistributionStatisticConfig filteredConfig = filter.configure(mappedId, config);
            if (filteredConfig != null) {
                config = filteredConfig;
            }
        }
    }
    Meter m = getOrCreateMeter(config, builder, mappedId, noopBuilder);
    if (!meterClass.isInstance(m)) {
        throw new IllegalArgumentException("There is already a registered meter of a different type with the same name");
    }
    // noinspection unchecked
    return (M) m;
}
Also used : MeterFilter(io.micrometer.core.instrument.config.MeterFilter) Id(io.micrometer.core.instrument.Meter.Id) DistributionStatisticConfig(io.micrometer.core.instrument.distribution.DistributionStatisticConfig)

Example 4 with DistributionStatisticConfig

use of io.micrometer.core.instrument.distribution.DistributionStatisticConfig in project micrometer by micrometer-metrics.

the class SimpleMeterRegistry method newDistributionSummary.

@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, false);
            break;
    }
    HistogramGauges.registerWithCommonFormat(summary, this);
    return summary;
}
Also used : StepDistributionSummary(io.micrometer.core.instrument.step.StepDistributionSummary) StepDistributionSummary(io.micrometer.core.instrument.step.StepDistributionSummary) DistributionStatisticConfig(io.micrometer.core.instrument.distribution.DistributionStatisticConfig)

Example 5 with DistributionStatisticConfig

use of io.micrometer.core.instrument.distribution.DistributionStatisticConfig in project micrometer by micrometer-metrics.

the class SimpleMeterRegistry method newTimer.

@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(), false);
            break;
    }
    HistogramGauges.registerWithCommonFormat(timer, this);
    return timer;
}
Also used : StepTimer(io.micrometer.core.instrument.step.StepTimer) DefaultLongTaskTimer(io.micrometer.core.instrument.internal.DefaultLongTaskTimer) StepTimer(io.micrometer.core.instrument.step.StepTimer) DistributionStatisticConfig(io.micrometer.core.instrument.distribution.DistributionStatisticConfig)

Aggregations

DistributionStatisticConfig (io.micrometer.core.instrument.distribution.DistributionStatisticConfig)5 MeterFilter (io.micrometer.core.instrument.config.MeterFilter)3 Meter (io.micrometer.core.instrument.Meter)1 Id (io.micrometer.core.instrument.Meter.Id)1 PauseDetector (io.micrometer.core.instrument.distribution.pause.PauseDetector)1 DefaultLongTaskTimer (io.micrometer.core.instrument.internal.DefaultLongTaskTimer)1 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 StepDistributionSummary (io.micrometer.core.instrument.step.StepDistributionSummary)1 StepTimer (io.micrometer.core.instrument.step.StepTimer)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Nonnull (javax.annotation.Nonnull)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1