Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prometheus Timer Callback

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()?

like image 890
Ben Avatar asked Nov 19 '25 08:11

Ben


1 Answers

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)
like image 124
brian-brazil Avatar answered Nov 20 '25 20:11

brian-brazil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!