2

想象一下这是我的http://localhost:8080/actuator输出:

{
"_links": {
    "self": {
        "href": "http://localhost:8080/actuator",
        "templated": false
    },
    "health": {
        "href": "http://localhost:8080/actuator/health",
        "templated": false
    },
    "prometheus": {
        "href": "http://localhost:8080/actuator/prometheus",
        "templated": false
    },
    "httptrace": {
        "href": "http://localhost:8080/actuator/httptrace",
        "templated": false
    }
}
}

现在我已经将我的 prometheus 环境连接到/actuator/prometheus并且工作正常。我还希望 prometheus 读取我的 httptrace,所以我也添加/actuator/httptrace到我的 prometheus 配置中。但是,这不起作用。httptrace端点上的格式是json,prometheus中的格式是yaml,我想我需要prometheus yaml中的httptrace。Prometheus 吃 yaml 就好了,json 没那么多。

如何将我的 httptrace 从我的 Spring Boot 项目传递给 actuator/prometheus?最后,我的目标是获取 grafana 中每个请求的 timeTaken 值。

4

1 回答 1

1

Spring's HttpTraceRepository exposes the recent traces on an endpoint but not in prometheus as percentiles. So I can suggest two paths:

  1. You implement your own HttpTraceRepository that wraps the one your using (default is InMemory....) and then override the method to fire off some custom Timer from [io.micrometer.core] with the timing (https://micrometer.io/docs/concepts#_timers) which will get aggregated as percentiles if you also enable via https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.metrics.customizing.per-meter-properties

In the end my goal is to get the timeTaken value for every request in grafana.

  1. Just use http_server_requests_seconds_* that are captured per endpoint (not request)

http_server_requests_seconds_count
is the total number of requests your application received at this endpoint

http_server_requests_seconds_sum
is the sum of the the duration of every request your application received at this endpoint

and this great post explains how to use it in prometheus, https://tomgregory.com/spring-boot-default-metrics/

于 2021-11-05T19:09:12.623 回答