I'm currently switching our Java backend from DropWizard to Prometheus and I'm having trouble finding a good substitute for DropWizards Timer while instrumenting a library which has a metrics callback looking like this:
new ImageUploader(
new MetricsCallback() {
@Override
public void timer(long aLong) {
new MetricRegistry()
.timer("outbound.image-upload.timer")
.update(aLong, TimeUnit.MILLISECONDS);
}
});
Prometheus' DropWizard-adapter uses Histogram.Timer as substitute, but there is no way of setting/updating the timer manually.
Is there a way to do this in Prometheus, or do I have to wrap every call to this libray into startTimer() + observeDuration()?
Assuming you have already defined your metric uploadLatency as a static class field as usual and aLong is in milliseconds, you want:
uploadLatency.observe(aLong / 1000.0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With