我目前正在将我的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适配器使用 Histogram.Timer 作为替代,但无法手动设置/更新计时器。
有没有办法在Prometheus中执行此操作,或者我是否必须将对此库的每次调用都包装到startTimer()
+ observeDuration()
?
答案 0 :(得分:0)
假设您已经像往常一样将度量uploadLatency定义为静态类字段,并且aLong
以毫秒为单位,您希望:
uploadLatency.observe(aLong / 1000.0)