我想检查数据库命中(多个数据库)和请求处理的延迟。 Timer.Sample
或 Timer.record
哪个更好?
我正在使用以 Prometheus 为基础的 Micrometer。
最佳答案
当计算出事件持续时间时,使用 Timer.record。
default void record(Duration duration)
当您想要传递 Sample 以确定发布指标的时间点时,您通常会使用 Timer.Sample,而不必在完全相同的位置。您还可以更精细地控制使用 Timer 对象发布的内容。 这是一个两步过程。
在事件开始之前创建一个样本以返回样本对象
static Sample start(Clock clock) {..}
停止示例并在 Activity 完成时使用 Sample.stop 推送指标
public long stop(Timer timer) {..}
例如 TimedAspect -
Timer.Sample sample = Timer.start(registry);
try {
return pjp.proceed();
} finally {
sample.stop(Timer.builder(timed.value())
.description(timed.description().isEmpty() ? null : timed.description())
.tags(timed.extraTags())
.tags(tagsBasedOnJoinpoint.apply(pjp))
.publishPercentileHistogram(timed.histogram())
.publishPercentiles(timed.percentiles().length == 0 ? null : timed.percentiles())
.register(registry));
}
关于java - Micrometer Timer.start/stop 和 Timer.record 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57249114/