本文整理汇总了Java中io.micrometer.core.instrument.FunctionTimer类的典型用法代码示例。如果您正苦于以下问题:Java FunctionTimer类的具体用法?Java FunctionTimer怎么用?Java FunctionTimer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FunctionTimer类属于io.micrometer.core.instrument包,在下文中一共展示了FunctionTimer类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: publish
import io.micrometer.core.instrument.FunctionTimer; //导入依赖的package包/类
@Override
protected void publish() {
List<Metric> metrics = getMeters().stream()
.flatMap(meter -> {
if (meter instanceof DistributionSummary) {
return getMetrics((DistributionSummary) meter);
} else if (meter instanceof FunctionTimer) {
return getMetrics((FunctionTimer) meter);
} else if (meter instanceof Timer) {
return getMetrics((Timer) meter);
} else {
return getMetrics(meter);
}
})
.collect(Collectors.toList());
this.metricPublisher.publish(metrics);
}
示例2: registerNewMeter
import io.micrometer.core.instrument.FunctionTimer; //导入依赖的package包/类
@Override
FunctionTimer registerNewMeter(MeterRegistry registry) {
final T obj = ref.get();
if (obj == null) {
return null;
}
return FunctionTimer.builder(getId().getName(), obj, countFunction,
totalTimeFunction, totalTimeFunctionUnits)
.tags(getId().getTags())
.description(getId().getDescription())
.baseUnit(getId().getBaseUnit()).register(registry);
}
示例3: main
import io.micrometer.core.instrument.FunctionTimer; //导入依赖的package包/类
public static void main(String[] args) {
MeterRegistry registry = SampleConfig.myMonitoringSystem();
Timer timer = Timer.builder("timer")
.publishPercentileHistogram()
.publishPercentiles(0.5, 0.95, 0.99)
.histogramExpiry(Duration.ofSeconds(10))
.histogramBufferLength(3)
.register(registry);
FunctionTimer.builder("ftimer", timer, Timer::count, t -> t.totalTime(TimeUnit.SECONDS), TimeUnit.SECONDS)
.register(registry);
RandomEngine r = new MersenneTwister64(0);
Normal incomingRequests = new Normal(0, 1, r);
Normal duration = new Normal(250, 50, r);
AtomicInteger latencyForThisSecond = new AtomicInteger(duration.nextInt());
Flux.interval(Duration.ofSeconds(1))
.doOnEach(d -> latencyForThisSecond.set(duration.nextInt()))
.subscribe();
// the potential for an "incoming request" every 10 ms
Flux.interval(Duration.ofMillis(10))
.doOnEach(d -> {
if (incomingRequests.nextDouble() + 0.4 > 0) {
// pretend the request took some amount of time, such that the time is
// distributed normally with a mean of 250ms
timer.record(latencyForThisSecond.get(), TimeUnit.MILLISECONDS);
}
})
.blockLast();
}
示例4: main
import io.micrometer.core.instrument.FunctionTimer; //导入依赖的package包/类
/**
* For Atlas: http://localhost:7101/api/v1/graph?q=name,ftimer,:eq,:dist-avg,name,timer,:eq,:dist-avg,1,:axis&s=e-5m&l=0
*/
public static void main(String[] args) {
MeterRegistry registry = SampleConfig.myMonitoringSystem();
Timer timer = Timer.builder("timer")
.publishPercentiles(0.5, 0.95)
.register(registry);
Object placeholder = new Object();
AtomicLong totalTimeNanos = new AtomicLong(0);
AtomicLong totalCount = new AtomicLong(0);
FunctionTimer.builder("ftimer", placeholder, p -> totalCount.get(), p -> totalTimeNanos.get(), TimeUnit.NANOSECONDS)
.register(registry);
RandomEngine r = new MersenneTwister64(0);
Normal incomingRequests = new Normal(0, 1, r);
Normal duration = new Normal(250, 50, r);
AtomicInteger latencyForThisSecond = new AtomicInteger(duration.nextInt());
Flux.interval(Duration.ofSeconds(1))
.doOnEach(d -> latencyForThisSecond.set(duration.nextInt()))
.subscribe();
// the potential for an "incoming request" every 10 ms
Flux.interval(Duration.ofMillis(10))
.doOnEach(d -> {
if (incomingRequests.nextDouble() + 0.4 > 0) {
// pretend the request took some amount of time, such that the time is
// distributed normally with a mean of 250ms
timer.record(latencyForThisSecond.get(), TimeUnit.MILLISECONDS);
totalCount.incrementAndGet();
totalTimeNanos.addAndGet((long) TimeUtils.millisToUnit(latencyForThisSecond.get(), TimeUnit.NANOSECONDS));
}
})
.blockLast();
}
示例5: getMetrics
import io.micrometer.core.instrument.FunctionTimer; //导入依赖的package包/类
private Stream<Metric> getMetrics(FunctionTimer meter) {
return Stream.of(
toMetric(withStatistic(meter, "count"), meter.count()),
toMetric(withStatistic(meter, "mean"), meter.mean(getBaseTimeUnit())),
toMetric(withStatistic(meter, "totalTime"), meter.totalTime(getBaseTimeUnit()))
);
}
示例6: newNoopMeter
import io.micrometer.core.instrument.FunctionTimer; //导入依赖的package包/类
@Override
FunctionTimer newNoopMeter() {
return new NoopFunctionTimer(getId());
}
示例7: newFunctionTimer
import io.micrometer.core.instrument.FunctionTimer; //导入依赖的package包/类
@Override
protected <T> FunctionTimer newFunctionTimer(Id id, T obj, ToLongFunction<T> countFunction,
ToDoubleFunction<T> totalTimeFunction,
TimeUnit totalTimeFunctionUnits) {
return new NoopFunctionTimer(id);
}