简体   繁体   English

使用千分尺、弹簧靴和普罗米修斯测量每秒请求数

[英]measure requests per second with micrometer, spring boot and prometheus

I'm updating a microservice to spring boot 2 and migrating metrics from dropwizard to micrometer.我正在将微服务更新到 spring boot 2,并将指标从 dropwizard 迁移到 micrometer。 We are using prometheus to store metrics and grafana to display them.我们使用 prometheus 来存储指标并使用 grafana 来显示它们。 I want to measure requests per second to all URLs.我想测量每秒对所有 URL 的请求。 Micrometer documentation states that:千分尺文档指出:

Timers are intended for measuring short-duration latencies, and the frequency of such events.

So timers seem to be the way to do the job:所以计时器似乎是完成这项工作的方式:

                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);

but it doesn't produce any rate per second, instead we have metrics similar to:但它不会产生任何每秒速率,而是我们有类似于以下的指标:

# 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

what would be the proper way to solve this?解决这个问题的正确方法是什么? Should the rate per second be calculated via prometheus queries or returned via spring actuator endpoint?每秒速率应该通过普罗米修斯查询计算还是通过弹簧执行器端点返回?

Prometheus provides a functional query language called PromQL (Prometheus Query Language) that lets the user select and aggregate time series data in real time. Prometheus 提供了一种名为PromQL (Prometheus Query Language)的函数式查询语言,可以让用户实时选择和聚合时间序列数据。 You can use rate() function:您可以使用rate()函数:

The following example expression returns the per-second rate of HTTP requests as measured over the last 5 minutes, per time series in the range vector:以下示例表达式返回过去 5 分钟内测量的 HTTP 请求每秒速率,范围向量中的每个时间序列:

rate(http_requests_total{job="api-server"}[5m])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM