首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >夸夸斯普罗米修斯百分位数在长时间更新后仍为零。

问夸夸斯普罗米修斯百分位数在长时间更新后仍为零。
EN

Stack Overflow用户
提问于 2021-10-18 10:35:04
回答 1查看 256关注 0票数 0

我在Quarkus中有一个服务bean MonitoringRegistryServiceImpl实现,用于注册定时器并更新它们(代码如下)。它们只注册一次(在map timerMap中),然后在记录/更新它们的值时重用。

问题是,如果我调用http://localhost:8080/q/metrics来查看百分比度量的当前状态,我只看到零值。

这只会在很长的时间内发生(例如,3小时而不更新度量)。到目前为止,这是我期待的事情,因为有distributionStatisticExpiry(Duration.ofMinutes(5))的百分位数。让我们称之为“价值的自然衰退”:)

但是,如果我要更新度量,然后再次调用http://localhost:8080/q/metrics,那么百分位数上的零值仍然存在,但是相关计数器和最大值被正确更新。

也许我对百分位数的理解还不完整,请提出建议。

注:我使用夸克-千分尺-注册表-普罗米修斯神器。

代码语言:javascript
复制
@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);
        }
    }

}
EN

回答 1

Stack Overflow用户

发布于 2022-04-29 13:15:44

解决方案非常简单,而不是使用Timer.builder()..register()只使用registry.timer()。上面的timerMap也没有必要。在此更改之后,计时器度量没有被归零。

代码语言:javascript
复制
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);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69614607

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档