我在Quarkus中有一个服务bean MonitoringRegistryServiceImpl实现,用于注册定时器并更新它们(代码如下)。它们只注册一次(在map timerMap中),然后在记录/更新它们的值时重用。
问题是,如果我调用http://localhost:8080/q/metrics来查看百分比度量的当前状态,我只看到零值。
这只会在很长的时间内发生(例如,3小时而不更新度量)。到目前为止,这是我期待的事情,因为有distributionStatisticExpiry(Duration.ofMinutes(5))的百分位数。让我们称之为“价值的自然衰退”:)
但是,如果我要更新度量,然后再次调用http://localhost:8080/q/metrics,那么百分位数上的零值仍然存在,但是相关计数器和最大值被正确更新。
也许我对百分位数的理解还不完整,请提出建议。
注:我使用夸克-千分尺-注册表-普罗米修斯神器。
@JBossLog
@ApplicationScoped
public class MonitoringRegistryServiceImpl implements MonitoringRegistryService {
private static final double[] PERCENTILES = { 0.5, 0.75, 0.95, 0.99 };
private Map<String, Timer> timerMap = new ConcurrentHashMap<>();
@Inject
MeterRegistry registry;
@Override
public <T> void updateTimer(String timerName, String[] tags,
Duration duration) {
String key = timerName + "_" + String.join(".", tags);
Timer timer = timerMap.get(key);
if (timer != null) {
log.debug("Key found:" + key);
timer.record(duration);
} else {
log.debug("Key not found:" + key);
Timer newTimer = Timer.builder(timerName).tags(newTags).publishPercentiles(PERCENTILES)
.distributionStatisticExpiry(Duration.ofMinutes(5))
.register(registry);
timerMap.put(key, newTimer);
newTimer.record(duration);
}
}
}发布于 2022-04-29 13:15:44
解决方案非常简单,而不是使用Timer.builder()..register()只使用registry.timer()。上面的timerMap也没有必要。在此更改之后,计时器度量没有被归零。
Timer timer = registry.timer(timerName, tags);
if (duration != null) {
timer.record(duration);
} else {
log.error("Time duration was equal to null for a metric with a timerName:" + timerName);
}https://stackoverflow.com/questions/69614607
复制相似问题