Actuator/metrics 端点不包括 http.server.requests [英] Actuator /metrics endpoint does not include http.server.requests

查看:188
本文介绍了Actuator/metrics 端点不包括 http.server.requests的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据弹簧靴执行器的文档

According to the documentation of the spring boot actuator

自动配置启用由 Spring MVC 处理的请求的检测.当 management.metrics.web.server.auto-time-requests 为 true 时,对所有请求都会进行此检测.或者,当设置为 false 时,您可以通过添加 @Timed

还有
默认情况下,指标生成的名称为 http.server.requests

当我访问/metrics 端点时,我得到

When I access the /metrics endpoint I am getting

{
  "mem": 405105,
  "mem.free": 150352,
  "processors": 8,
  "instance.uptime": 440055,
  "uptime": 455888,
  "systemload.average": 1.904296875,
  "heap.committed": 315392,
  "heap.init": 262144,
  "heap.used": 164015,
  "heap": 4194304,
  "nonheap.committed": 92800,
  "nonheap.init": 4992,
  "nonheap.used": 89714,
  "nonheap": 0,
  "threads.peak": 64,
  "threads.daemon": 43,
  "threads.totalStarted": 95,
  "threads": 46,
  "classes": 12459,
  "classes.loaded": 12459,
  "classes.unloaded": 0,
  "gc.g1_young_generation.count": 12,
  "gc.g1_young_generation.time": 127,
  "gc.g1_old_generation.count": 0,
  "gc.g1_old_generation.time": 0,
  "httpsessions.max": -1,
  "httpsessions.active": 0,
  "datasource.primary.active": 0,
  "datasource.primary.usage": 0.0,
  "gauge.response.example.users": 2.0,
  "counter.status.200.example.users": 5
}

所以 http.server.requests 不存在.counter.status.200.example 类型显示通过我的应用程序的请求,但它们按端点分开.我需要整个应用程序的整体.我试过禁用 management.metrics.web.server.auto-time-requests 并将 @Timed 添加到端点,但效果不佳.结果和上面一样.

So the http.server.requests is not there. The counter.status.200.example kind of shows the requests that go through my application but they are separated per endpoint. I need an overall for the whole application. I've tried disabling the management.metrics.web.server.auto-time-requests and adding @Timed to the endpoints, but that did not work as well. The result was the same as the one above.

有谁知道我如何显示对应用程序提出的总体请求?提前致谢.

Does anyone know how I can show the overall requests that are made to the application? Thank you in advance.

*编辑

当我添加compile('io.micrometer:micrometer-registry-prometheus:latest.release')我收到以下错误

when I add compile('io.micrometer:micrometer-registry-prometheus:latest.release') I get the following error

Parameter 0 of method prometheusEndpointFix in PrometheusEndpointConfiguration required a bean of type 'PrometheusEndpoint' that could not be found.

即使@Bean 在那里..

Even though the @Bean is there..

@Configuration
class PrometheusEndpointConfiguration {

  @Bean
  public PrometheusEndpoint prometheusEndpoint() {
    return new PrometheusEndpoint(CollectorRegistry.defaultRegistry);
  }
...
}

推荐答案

当通过 micrometer-spring-legacy 在 Spring Boot 1.5 中使用 Micrometer 时,旧"/metricsSpring Boot 1.5 Actuator 框架中的端点不会被 Micrometer 替代.在 Spring Boot 1.5 应用程序中,旧的执行器指标实现和 Micrometer 彼此完全独立.

When using Micrometer with Spring Boot 1.5 via micrometer-spring-legacy the "old" /metrics endpoint from the Spring Boot 1.5 Actuator framework will not get replaced with the Micrometer one. In a Spring Boot 1.5 application, the old actuator metrics implementation and Micrometer live totally independant next to each other.

目前,我所知道的在这种情况下轻松可视化 Micrometer 收集的指标的唯一方法是使用 Micrometers Prometheus 后端,通过在 micrometer-spring-legacy 之外添加 micrometer-registry-prometheus.默认情况下,这将公开 /prometheus 端点并以 Prometheus 公开格式公开指标.

Currently, the only way I know off for easily visualizing the Micrometer collected metrics in this scenario is using Micrometers Prometheus backend by including micrometer-registry-prometheus additionally to micrometer-spring-legacy. This will - by default - expose the /prometheus endpoint and expose the metrics in the Prometheus exposition format.

当然,您也可以推出自己的端点实现,它模仿 Spring Boot 2 /actuator/metrics 端点,该端点查询 MeterRegistry 并可视化所有包含的指标.但即便如此,这也应该仅用于调试事物,而不是永久读取此端点并将该数据保存在指标存储中的某处.普罗米修斯展示格式已经为那个确切的用例开发"了.(而且它的可读性很强,因此可以作为第一眼的入口点,以防您不抓取这些指标.)

Of course, you could also roll your own endpoint implementation which mimics the Spring Boot 2 /actuator/metrics endpoint which queries the MeterRegistry and visualizes all contained metrics. But even then, this should be merely used for debugging things instead of permanently reading this endpoint and persisting that data somewhere in a metrics store. The Prometheus exposition format has been "developed" for that exact usecase. (And it's quite readable, so can serve as a first look entrypoint in case you are not scraping these metrics.)

这篇关于Actuator/metrics 端点不包括 http.server.requests的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆