Micrometer gauge metric update value slowly?

1.7k views Asked by At

I'm using micrometer gauge metric to monitor Http_max_response_time in Vertx service. (configure metric with Prometheus).

When testing, I send a request with timeout 3 seconds at 13:15:16 and the gauge metric return right value about Http_max_response_time (3s). But after that request, there is not any request with timeout 3 seconds send to server, the gauge metric still return Http_max_response_time = 3 second until 13:17:51, and then it updates new value Http_max_response_time to less than 3s. I think it need update more frequently.

My questions here:

  1. How long the gauge metric update new value OR how long it keeps current value?
  2. Which logic that the gauge metric Http_max_response_time execute? Does it just update a global value and return it when there is an observation?

If my question is not clear, please comment and I will show detail more. Thank in advance,

1

There are 1 answers

0
Alex On

Updated:

Vertx-micrometer-metrics use a Timer metric for response time, and using a TimeWindowMax to update highest value.

Max for basic Timer implementations such as CumulativeTimer, StepTimer is a time window max (TimeWindowMax). It means that its value is the maximum value during a time window. If no new values are recorded for the time window length, the max will be reset to 0 as a new time window starts. Time window size will be the step size of the meter registry unless expiry in DistributionStatisticConfig is set to other value explicitly. The reason why a time window max is used is to capture max latency in a subsequent interval after heavy resource pressure triggers the latency and prevents metrics from being published.

So we can change default expiry configuration in DistributionStatisticConfig to smaller value as you want.

Here my code to change TimeWindowMax of metrics which contain responseTime to 2 seconds:

registry.config().meterFilter(
            new MeterFilter() {
                @Override
                public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
                    if(id.getName().contains("responseTime")) {
                        return DistributionStatisticConfig.builder()
                                .expiry(Duration.ofSeconds(5))
                                .build()
                                .merge(config);
                    }
                    return config;
                }
            });

And It worked.