我正在将微服务更新为Spring Boot 2,并将指标从dropwizard迁移到千分尺。我们正在使用Prometheus存储指标,并使用grafana显示它们。我想每秒衡量对所有URL的请求。千分尺文档指出:
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
什么是解决此问题的正确方法?每秒的速率应该通过普罗米修斯查询来计算还是通过弹簧执行器端点返回?