【问题标题】:How to import actuator httptrace in actuator prometheus? (actuator, spring boot, grafana)如何在执行器prometheus中导入执行器httptrace? (执行器、弹簧靴、grafana)
【发布时间】:2020-08-01 07:40:43
【问题描述】:

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

{
"_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,所以我还在我的 prometheus 配置中添加了 /actuator/httptrace。但是,这不起作用。 httptrace端点is in json上的格式和prometheusis in yaml中的格式,我想我需要prometheus yaml中的httptrace。 Prometheus 吃 yaml 就好了,json 没那么多。

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

【问题讨论】:

  • Prometheus 正在摄取 open metrics 格式,yaml 和 json 都不起作用。此外,Prometheus 是一个时间序列数据库,它并非旨在跟踪每个请求,而是通过使用直方图或摘要来获得一些指标。
  • 是的,我是这么想的,谢谢迈克尔。我希望有一些简单的方法可以将 json 数据转换为开放指标格式,但我认为这是不可能的。至于 B 计划,我将使用 micrometer 创建我自己的自定义指标,这些指标将添加到 prometheus 端点。使用 AOP @Around 注释,我可以对控制器函数计​​时,以了解它花了多长时间。这将是更多的工作,但它是可行的。
  • @scre_www 你有什么方法可以在 grafana 中为 httptrace 绘制图表吗?

标签: spring-boot prometheus micrometer actuator http-trace


【解决方案1】:

Spring 的 HttpTraceRepository 在端点上公开最近的跟踪,但在 prometheus 中不公开百分位数。所以我可以建议两条路径:

  1. 您实现自己的HttpTraceRepository 来包装您正在使用的HttpTraceRepository(默认为InMemory ....),然后覆盖该方法以触发来自[io.micrometer.core] 的一些自定义Timer 定时( https://micrometer.io/docs/concepts#_timers) 如果您还通过 https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.metrics.customizing.per-meter-properties 启用,它将被聚合为百分位数

最后,我的目标是获取 grafana 中每个请求的 timeTaken 值。

  1. 只需使用每个端点捕获的 http_server_requests_seconds_*(不是请求)

http_server_requests_seconds_count
是您的应用程序在此端点收到的请求总数

http_server_requests_seconds_sum
是您的应用程序在此端点收到的每个请求的持续时间的总和

这篇很棒的帖子解释了如何在 prometheus 中使用它,https://tomgregory.com/spring-boot-default-metrics/

【讨论】:

    猜你喜欢
    • 2018-02-14
    • 2017-09-08
    • 2017-07-29
    • 2017-07-06
    • 2021-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-31
    相关资源
    最近更新 更多