Search in sources :

Example 6 with Collector

use of io.prometheus.client.Collector in project micrometer by micrometer-metrics.

the class PrometheusMeterRegistry method newFunctionTimer.

@Override
protected <T> FunctionTimer newFunctionTimer(Meter.Id id, T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnits) {
    MicrometerCollector collector = collectorByName(id);
    FunctionTimer ft = new CumulativeFunctionTimer<>(id, obj, countFunction, totalTimeFunction, totalTimeFunctionUnits, getBaseTimeUnit());
    List<String> tagValues = tagValues(id);
    collector.add((conventionName, tagKeys) -> Stream.of(new MicrometerCollector.Family(Collector.Type.SUMMARY, conventionName, Stream.of(new Collector.MetricFamilySamples.Sample(conventionName + "_count", tagKeys, tagValues, ft.count()), new Collector.MetricFamilySamples.Sample(conventionName + "_sum", tagKeys, tagValues, ft.totalTime(TimeUnit.SECONDS))))));
    return ft;
}
Also used : Collector(io.prometheus.client.Collector) CumulativeFunctionTimer(io.micrometer.core.instrument.cumulative.CumulativeFunctionTimer) CumulativeFunctionTimer(io.micrometer.core.instrument.cumulative.CumulativeFunctionTimer)

Aggregations

Collector (io.prometheus.client.Collector)6 CountAtBucket (io.micrometer.core.instrument.distribution.CountAtBucket)2 ValueAtPercentile (io.micrometer.core.instrument.distribution.ValueAtPercentile)2 LinkedList (java.util.LinkedList)2 Stream (java.util.stream.Stream)2 CumulativeFunctionCounter (io.micrometer.core.instrument.cumulative.CumulativeFunctionCounter)1 CumulativeFunctionTimer (io.micrometer.core.instrument.cumulative.CumulativeFunctionTimer)1 DefaultGauge (io.micrometer.core.instrument.internal.DefaultGauge)1 DefaultLongTaskTimer (io.micrometer.core.instrument.internal.DefaultLongTaskTimer)1