io.micrometer.core.instrument.Meter.Id Java Examples

The following examples show how to use io.micrometer.core.instrument.Meter.Id. 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: MeterRegistry.java    From micrometer with Apache License 2.0 6 votes vote down vote up
/**
 * Build a new time gauge to be added to the registry. This is guaranteed to only be called if the time gauge doesn't already exist.
 *
 * @param id                The id that uniquely identifies the time gauge.
 * @param obj               The state object from which the value function derives a measurement.
 * @param valueFunctionUnit The base unit of time returned by the value function.
 * @param valueFunction     A function returning a time value that can go up or down.
 * @param <T>               The type of the object upon which the value function derives a measurement.
 * @return A new time gauge.
 */
protected <T> TimeGauge newTimeGauge(Meter.Id id, @Nullable T obj, TimeUnit valueFunctionUnit, ToDoubleFunction<T> valueFunction) {
    Meter.Id withUnit = id.withBaseUnit(getBaseTimeUnitStr());
    Gauge gauge = newGauge(withUnit, obj, obj2 -> TimeUtils.convert(valueFunction.applyAsDouble(obj2), valueFunctionUnit, getBaseTimeUnit()));

    return new TimeGauge() {
        @Override
        public Id getId() {
            return withUnit;
        }

        @Override
        public double value() {
            return gauge.value();
        }

        @Override
        public TimeUnit baseTimeUnit() {
            return getBaseTimeUnit();
        }
    };
}
 
Example #2
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 #3
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 #4
Source File: MeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
/**
 * @param mappedId The id of the meter to remove
 * @return The removed meter, or null if no meter matched the provided id.
 * @since 1.1.0
 */
@Incubating(since = "1.1.0")
@Nullable
public Meter remove(Meter.Id mappedId) {
    Meter m = meterMap.get(mappedId);

    if (m != null) {
        synchronized (meterMapLock) {
            m = meterMap.remove(mappedId);
            if (m != null) {
                Set<Id> synthetics = syntheticAssociations.remove(mappedId);
                if (synthetics != null) {
                    for (Id synthetic : synthetics) {
                        remove(synthetic);
                    }
                }

                for (Consumer<Meter> onRemove : meterRemovedListeners) {
                    onRemove.accept(m);
                }

                return m;
            }
        }
    }

    return null;
}
 
Example #5
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 #6
Source File: OnlyOnceLoggingDenyMeterFilter.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
public MeterFilterReply accept(Id id) {
    if (logger.isWarnEnabled() && this.alreadyWarned.compareAndSet(false, true)) {
        logger.warn(this.message.get());
    }
    return MeterFilterReply.DENY;
}
 
Example #7
Source File: PercentilePrecisionMeterConfigurationFilter.java    From kayenta with Apache License 2.0 5 votes vote down vote up
public DistributionStatisticConfig configure(Id id, DistributionStatisticConfig config) {
  DistributionStatisticConfig statisticConfig =
      DistributionStatisticConfig.builder()
          .percentilePrecision(this.metricsConfigurationProperties.getPercentilePrecision())
          .expiry(this.metricsConfigurationProperties.getExpiry())
          .build();
  return statisticConfig.merge(config);
}
 
Example #8
Source File: PropertiesMeterFilter.java    From foremast with Apache License 2.0 5 votes vote down vote up
private <T> T doLookup(Map<String, T> values, Id id, Supplier<T> defaultValue) {
    String name = id.getName();
    while (StringUtils.hasLength(name)) {
        T result = values.get(name);
        if (result != null) {
            return result;
        }
        int lastDot = name.lastIndexOf('.');
        name = (lastDot != -1) ? name.substring(0, lastDot) : "";
    }

    return defaultValue.get();
}
 
Example #9
Source File: MeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
private <M extends Meter> M registerMeterIfNecessary(Class<M> meterClass, Meter.Id id,
                                                     @Nullable DistributionStatisticConfig config, BiFunction<Meter.Id, DistributionStatisticConfig, M> builder,
                                                     Function<Meter.Id, M> noopBuilder) {
    Id mappedId = getMappedId(id);
    Meter m = getOrCreateMeter(config, builder, id, mappedId, noopBuilder);

    if (!meterClass.isInstance(m)) {
        throw new IllegalArgumentException("There is already a registered meter of a different type with the same name");
    }
    return meterClass.cast(m);
}
 
Example #10
Source File: MeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
private Id getMappedId(Id id) {
    if (id.syntheticAssociation() != null) {
        return id;
    }
    Id mappedId = id;
    for (MeterFilter filter : filters) {
        mappedId = filter.map(mappedId);
    }
    return mappedId;
}
 
Example #11
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 #12
Source File: DefaultDestinationPublishingMeterRegistry.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@Override
protected <T> FunctionTimer newFunctionTimer(Id id, T obj,
		ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction,
		TimeUnit totalTimeFunctionUnits) {
	return new StepFunctionTimer<T>(id, this.clock,
			this.metricsPublisherConfig.step().toMillis(), obj, countFunction,
			totalTimeFunction, totalTimeFunctionUnits, getBaseTimeUnit());
}
 
Example #13
Source File: PropertiesMeterFilter.java    From foremast with Apache License 2.0 5 votes vote down vote up
private <T> T doLookup(Map<String, T> values, Id id, Supplier<T> defaultValue) {
    String name = id.getName();
    while (StringUtils.hasLength(name)) {
        T result = values.get(name);
        if (result != null) {
            return result;
        }
        int lastDot = name.lastIndexOf('.');
        name = (lastDot != -1) ? name.substring(0, lastDot) : "";
    }

    return defaultValue.get();
}
 
Example #14
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 #15
Source File: MeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
private boolean accept(Meter.Id id) {
    for (MeterFilter filter : filters) {
        MeterFilterReply reply = filter.accept(id);
        if (reply == MeterFilterReply.DENY) {
            return false;
        } else if (reply == MeterFilterReply.ACCEPT) {
            return true;
        }
    }
    return true;
}
 
Example #16
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 #17
Source File: DefaultDestinationPublishingMeterRegistry.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@Override
protected <T> Gauge newGauge(Meter.Id id, T obj, ToDoubleFunction<T> f) {
	return new DefaultGauge<>(id, obj, f);
}
 
Example #18
Source File: DefaultDestinationPublishingMeterRegistry.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@Override
protected Counter newCounter(Meter.Id id) {
	return new StepCounter(id, this.clock,
			this.metricsPublisherConfig.step().toMillis());
}
 
Example #19
Source File: DefaultDestinationPublishingMeterRegistry.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@Override
protected LongTaskTimer newLongTaskTimer(Meter.Id id) {
	return new DefaultLongTaskTimer(id, this.clock);
}
 
Example #20
Source File: DefaultDestinationPublishingMeterRegistry.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@Override
protected <T> FunctionCounter newFunctionCounter(Id id, T obj,
		ToDoubleFunction<T> valueFunction) {
	return new StepFunctionCounter<T>(id, this.clock,
			this.metricsPublisherConfig.step().toMillis(), obj, valueFunction);
}
 
Example #21
Source File: NoopMeterRegistry.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
protected LongTaskTimer newLongTaskTimer(Id id) {
    return new NoopLongTaskTimer(id);
}
 
Example #22
Source File: DefaultDestinationPublishingMeterRegistry.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@Override
protected Meter newMeter(Id id, Type type, Iterable<Measurement> measurements) {
	return new DefaultMeter(id, type, measurements);
}
 
Example #23
Source File: DefaultDestinationPublishingMeterRegistry.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@Override
protected DistributionSummary newDistributionSummary(Id id,
		DistributionStatisticConfig distributionStatisticConfig, double scale) {
	return new StepDistributionSummary(id, this.clock, distributionStatisticConfig,
			scale, this.metricsPublisherConfig.step().toMillis(), false);
}
 
Example #24
Source File: NoopMeterRegistry.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
protected <T> FunctionCounter newFunctionCounter(Id id, T obj, ToDoubleFunction<T> f) {
    return new NoopFunctionCounter(id);
}
 
Example #25
Source File: StatsLoggerImpl.java    From pravega with Apache License 2.0 4 votes vote down vote up
GaugeImpl(String statName, Supplier<Number> valueSupplier, String... tagPairs) {
    io.micrometer.core.instrument.Tags tags = io.micrometer.core.instrument.Tags.of(tagPairs);
    this.id = new Id(statName, tags, null, null, io.micrometer.core.instrument.Meter.Type.GAUGE);
    this.supplierReference.set(valueSupplier);
    metrics.gauge(statName, tags, this.supplierReference, obj -> obj.get().get().doubleValue());
}
 
Example #26
Source File: NullStatsLogger.java    From pravega with Apache License 2.0 4 votes vote down vote up
@Override
public Id getId() {
    return NULL_ID;
}
 
Example #27
Source File: NullStatsLogger.java    From pravega with Apache License 2.0 4 votes vote down vote up
@Override
public Id getId() {
    return NULL_ID;
}
 
Example #28
Source File: NullStatsLogger.java    From pravega with Apache License 2.0 4 votes vote down vote up
@Override
public Id getId() {
    return NULL_ID;
}
 
Example #29
Source File: NullStatsLogger.java    From pravega with Apache License 2.0 4 votes vote down vote up
@Override
public Id getId() {
    return NULL_ID;
}
 
Example #30
Source File: TimedAspectTest.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
protected LongTaskTimer newLongTaskTimer(@Nonnull Id id, @Nonnull DistributionStatisticConfig distributionStatisticConfig) {
    throw new RuntimeException();
}