Prometheus 定时器回调
Prometheus Timer Callback
我目前正在将我们的 Java 后端从 DropWizard 切换到 Prometheus,但我找不到合适的在检测具有如下指标回调的库时替代 DropWizards 计时器:
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 作为替代,但无法手动 setting/updating 定时器。
有没有办法在 Prometheus 中执行此操作,还是我必须将对此库的每次调用都包装到 startTimer()
+ observeDuration()
中?
假设您已经像往常一样将指标 uploadLatency 定义为静态 class 字段并且 aLong
以毫秒为单位,您需要:
uploadLatency.observe(aLong / 1000.0)
我目前正在将我们的 Java 后端从 DropWizard 切换到 Prometheus,但我找不到合适的在检测具有如下指标回调的库时替代 DropWizards 计时器:
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 作为替代,但无法手动 setting/updating 定时器。
有没有办法在 Prometheus 中执行此操作,还是我必须将对此库的每次调用都包装到 startTimer()
+ observeDuration()
中?
假设您已经像往常一样将指标 uploadLatency 定义为静态 class 字段并且 aLong
以毫秒为单位,您需要:
uploadLatency.observe(aLong / 1000.0)