微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

千分尺/普罗米修斯如何防止测量值变成NaN?

如何解决千分尺/普罗米修斯如何防止测量值变成NaN?

这是我最终要解决的千分尺缺陷。

同时,您需要将该值保存在映射中,以免垃圾回收。请注意,然后我们如何将量规指向地图,并通过lambda提取值以避免垃圾收集。

public class MonitorService {
    private Map<String, Integer> gaugeCache = new HashMap<>();
    private InfoCollectionService infoService;
    public MonitorService(InfoCollectionService infoService) {
        this.infoService = infoService
    }

    @Scheduled(fixedDelay = 5000)
    public void currentLoggedInUserMonitor() {
        infoService.getLoggedInUser("channel").forEach(channel -> {
            gaugeCache.put(channel.getchannelName(), channel.getgetLoggedInUser());
            Metrics.gauge("LoggedInUsers.Inchannel_" + channel.getchannelName(), gaugeCache, g -> g.get(channel.getchannelName()));
        });
    }
}

我还建议为各种渠道使用标签

Metrics.gauge("loggedInUsers.inChannel", Tag.of("channel",channel.getchannelName()), gaugeCache, g -> g.get(channel.getchannelName()));

解决方法

我正在尝试监视已登录的用户,通过调用api获取已登录的用户信息,这是我使用的代码,

public class MonitorService {
    private InfoCollectionService infoService;
    public MonitorService(InfoCollectionService infoService) {
        this.infoService = infoService
    }

    @Scheduled(fixedDelay = 5000)
    public void currentLoggedInUserMonitor() {
        infoService.getLoggedInUser("channel").forEach(channel -> {
            Metrics.gauge("LoggedInUsers.Inchannel_" + channel.getchannelName(),channel.getgetLoggedInUser());
        });
    }
}

我在Prometheus中看到了值,问题出在几秒钟后,该值变成NaN,我已经读过千分尺用WeakReference(因此收集了垃圾)包装了它们的obj输入,但我不知道如何解决它。如果有人知道如何解决这个问题,那就太好了。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。