我正在将一个微服务更新到Spring Boot 2并将度量从Dropwizard迁移到Micrometer。我们使用Prometheus存储度量数据,并使用Grafana显示它们。我想要测量所有URL的每秒请求数。Micrometer文档指出:
Timers are intended for measuring short-duration latencies, and the frequency of such events.
所以计时器似乎是完成任务的方法:
Timer.Sample sample = log ? Timer.start(registry)
//...code which executes request...
List<Tag> tags = Arrays.asList(
Tag.of("status", status),
Tag.of("uri", uri),
Tag.of("method", request.getMethod()));
Timer timer = Timer.builder(TIMER_REST)
.tags(tags)
.publishPercentiles(0.95, 0.99)
.distributionStatisticExpiry(Duration.ofSeconds(30))
.register(registry);
sample.stop(timer);
但它不会产生每秒的速率,而是我们使用类似以下的指标:
# TYPE timer_rest_seconds summary
timer_rest_seconds{method="GET",status="200",uri="/test",quantile="0.95",} 0.620756992
timer_rest_seconds{method="GET",status="200",uri="/test",quantile="0.99",} 0.620756992
timer_rest_seconds_count{method="GET",status="200",uri="/test",} 7.0
timer_rest_seconds_sum{method="GET",status="200",uri="/test",} 3.656080641
# HELP timer_rest_seconds_max
# TYPE timer_rest_seconds_max gauge
timer_rest_seconds_max{method="GET",status="200",uri="/test",} 0.605290436
应该怎样正确地解决这个问题?速率每秒应该通过Prometheus查询计算,还是通过Spring Actuator端点返回?