Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Micrometer and Prometheus Timer as Rate

According to Micrometer's documentation https://micrometer.io/docs/concepts#_server_side, the framework (Micrometer) should handle converting the timer metric to a rate from absolute amount

The below code simulates a dummy timer:

@Service
public class AppService {
    private Timer timer = Metrics.timer("foobar");

    public String test() {
        timer.record(() -> {
            try {
                Thread.sleep((long) (Math.random() * 1000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        return "foo";
    }
}

However in Prometheus I see only monotonically increasing metrics foobar_seconds_sum and foobar_seconds_count instead of seeing them as rates

enter image description here

Perhaps I misunderstood or overlooked something in the documentation?

like image 538
echen Avatar asked May 20 '18 01:05

echen


1 Answers

This is how a Prometheus Summary works, you can calculate the average event size with:

  rate(foobar_seconds_sum[5m])
/
  rate(foobar_seconds_count[5m])

With Prometheus client libraries are dumb, and should leave more complex math to Prometheus.

like image 188
brian-brazil Avatar answered Sep 18 '22 18:09

brian-brazil