Search in sources :

Example 1 with Id

use of io.micrometer.core.instrument.Meter.Id 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 2 with Id

use of io.micrometer.core.instrument.Meter.Id in project micrometer by micrometer-metrics.

the class MeterRegistry method newTimeGauge.

/**
 * 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 id;
        }

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

        @Override
        public TimeUnit baseTimeUnit() {
            return getBaseTimeUnit();
        }
    };
}
Also used : Id(io.micrometer.core.instrument.Meter.Id)

Aggregations

Id (io.micrometer.core.instrument.Meter.Id)2 MeterFilter (io.micrometer.core.instrument.config.MeterFilter)1 DistributionStatisticConfig (io.micrometer.core.instrument.distribution.DistributionStatisticConfig)1