【发布时间】:2018-07-08 06:50:20
【问题描述】:
在我设置的 Spring Boot App (2.0.0.M7) application.properties 中
management.endpoint.metrics.enabled=true
但是,当我击中时
localhost:8080/actuator/metrics
我得到 404。
解决办法是什么?
【问题讨论】:
标签: spring-boot spring-boot-actuator
在我设置的 Spring Boot App (2.0.0.M7) application.properties 中
management.endpoint.metrics.enabled=true
但是,当我击中时
localhost:8080/actuator/metrics
我得到 404。
解决办法是什么?
【问题讨论】:
标签: spring-boot spring-boot-actuator
我想用更多信息来增强 OP 的答案,因为我在最终偶然发现这个解决方案之前有点挣扎,而且似乎对 Spring Boot 2 对执行器行为的更改有很多困惑
没有改变的地方
您需要包含对 spring-boot-starter-actuator 的依赖项
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
如果你想通过HTTP访问执行器端点,你还需要添加一个依赖到spring-boot-starter-web
所以你的 pom 依赖项如下所示
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
Spring Boot 2 中引入的更改
/health、/metrics 等端点不再在默认根上下文中可用。从现在开始,它们可以在
http://{host}:{port}/actuator。
此外,您的应用程序的所有其他端点是否以其他一些上下文(例如/hello)开头并不重要——执行器在/actuator 上可用,而不在/hello/actuator 上可用。
来自/actuator 端点的响应默认启用HATEOAS。在 Spring Boot 2 之前,这种情况只有 if HATEOAS is on the classpath and explicitly enabled in application.yml
要通过 HTTP 使执行器端点可用,它需要同时启用和公开。
默认情况下:
只有 /health 和 /info 端点被公开,无论您的应用程序中是否存在和配置 Spring Security。
除了/shutdown 之外的所有端点都已启用(尽管只有/health 和/info 被公开)
如果您想公开所有端点(并不总是一个好主意),您可以通过将management.endpoints.web.exposure.include=* 添加到application.properties 来实现。如果您使用 yml-configurations,请不要忘记引用通配符。
endpoints.xyz 开头的旧属性,取而代之的是以management.xyz 开头的属性有关完整文档,请参阅 official doc 和 migration guide
【讨论】:
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.include: '*'
将以下行添加到您的 application.properties 文件中:
management.endpoints.web.exposure.include=metrics
就是这样。
【讨论】:
management.endpoints.web.exposure.include=* 为我工作
对我有用的是以下(以 YAML 格式)与 Spring Boot 2 版本一起使用:
management:
endpoints:
web:
exposure:
include: info, health, metrics
metrics:
export:
atlas:
enabled: false
也可以找到具体的文档here
【讨论】:
您需要在application.properties 文件中添加以下道具。在添加以下道具之前,我遇到了同样的问题。
management.endpoints.beans.enabled=false
management.endpoints.web.exposure.include=*
【讨论】:
“*”在YAML中有特殊含义,所以如果要包含(或排除)所有端点,请务必加上引号,如下例所示:
management:
endpoints:
web:
exposure:
include: "*"
【讨论】:
从 Spring Boot 1.5.15 升级到 2.1.4 时遇到同样的问题
需要修改我pom.xml中Spring Boot执行器的原始依赖来自:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
到:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
注意artifactId 中添加了单词starter。
【讨论】:
enabled 和 exposed 有什么区别?谢谢!
根据micrometer docs .Spring Boot 2.0.x 通过 Spring Boot Actuator 支持开箱即用的千分尺。
默认情况下禁用端点 metric,这与 Spring Boot 2 的试金石测试一致,即任何可能暴露应用程序敏感数据的端点都应默认禁用。可以通过设置启用:
management.endpoints.web.exposure.include:指标
导航到/actuator/metrics 会显示可用计量器名称的列表。
要访问它们,请使用以下内容: http://localhost:8080/actuator/metrics/jvm.memory.used
【讨论】:
application.properties 通过指定 management.endpoints.web.exposure.include=metrics
好的,我找到了解决方案。我在 application.properties 中添加了另一行
management.endpoints.web.expose=*
但是,保护执行器的 endoints 很重要
在这里阅读: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-monitoring.html
【讨论】:
以下配置对我有用
server.servlet.context-path=/travel management.endpoints.web.exposure.include=*
然后你需要添加上下文路径: http://localhost:8080/travel/actuator/metrics/
【讨论】:
management:
endpoints:
web:
base-path: "/"
exposure:
include: '*'
它应该像那样工作。 * 表示暴露所有端点
【讨论】:
正如@senseiwu 提到的,与以前的版本不同,spring boot 2 中的 Actuator 禁用了大多数端点。 我们是否要启用所有这些,我们可以设置
management.endpoints.web.exposure.include=*
或者,我们可以列出应该启用的端点。
您可以轻松使用 hal-browser 这是一个有用的 UI,通过添加以下依赖项映射到“/”路径:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
</dependency>
在 hal 浏览器中,您需要输入 /actuator 才能查看所有端点。 它已经在 Spring Boot 2.3.0.M2 中进行了测试,并且运行良好。 您可以通过以下链接了解更多信息:
【讨论】:
在 application.properties 中添加以下属性为我解决了问题:
management.health.defaults.enabled=false
【讨论】:
将千分尺的完整配置放在这里。以下一个对我来说工作正常。我将它用于 ELK 堆栈
management:
metrics:
enable:
jvm: true
all: true
export:
elastic:
enables: true
step: 10s
index: micrometer-${spring.application.name}
host: http://localhost:9200
simple:
enabled: true
distribution:
percentiles-histogram:
http:
server:
requests: true
sla:
http:
server:
requests: 100ms, 400ms, 500ms, 2000ms
percentiles:
http:
server:
requests: 0.5, 0.9, 0.95, 0.99
endpoint:
metrics:
enabled: true
endpoints:
web:
exposure:
include: '*'
【讨论】:
在application.properties 中设置management.endpoints.web.exposure.include=metrics 以通过HTTP 公开/actuator/metrics。
参考:https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html
参考:https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.endpoints
Actuator 端点让您可以监控您的应用程序并与之交互。 Spring Boot 包含许多内置端点,并允许您添加自己的端点。例如,健康端点提供基本的应用健康信息。
每个单独的端点都可以是enabled 或disabled 和exposed(可远程访问)HTTP 或JMX。当端点被启用和公开时,它被认为是可用的。 内置端点只有在它们可用时才会被自动配置。大多数应用程序选择通过 HTTP 公开,其中端点的 ID 以及 /actuator 的前缀被映射到 URL。例如,默认情况下,健康端点映射到 /actuator/health。
默认情况下,除了关闭之外的所有端点都启用。
【讨论】: