【问题标题】:Prometheus Timer Callback普罗米修斯定时器回调
【发布时间】:2018-02-19 14:07:17
【问题描述】:

我目前正在将我们的 Java 后端从 DropWizard 切换到 Prometheus,但在检测具有指标的库时,我无法找到 DropWizards Timer 的良好替代品回调看起来像这样:

new ImageUploader(
        new MetricsCallback() {
            @Override
            public void timer(long aLong) {
                new MetricRegistry()
               .timer("outbound.image-upload.timer")
               .update(aLong, TimeUnit.MILLISECONDS);
            }
        });

Prometheus 的 DropWizard-adapter 使用 Histogram.Timer 作为替代,但无法手动设置/更新计时器。

有没有办法在 Prometheus 中做到这一点,还是我必须将对这个库的每次调用都包装到 startTimer() + observeDuration() 中?

【问题讨论】:

    标签: java prometheus


    【解决方案1】:

    假设您已经像往常一样将指标 uploadLatency 定义为静态类字段,并且 aLong 以毫秒为单位,您希望:

    uploadLatency.observe(aLong / 1000.0)
    

    【讨论】:

    • 显然我是盲人。谢谢布赖恩!
    猜你喜欢
    • 1970-01-01
    • 2022-01-22
    • 2017-09-03
    • 1970-01-01
    • 2022-10-17
    • 2022-12-02
    • 2022-12-17
    • 2020-01-10
    • 2020-11-12
    相关资源
    最近更新 更多