在我的Spring Boot App(2.0.0.M7)的application.properties文件中,我设置了
management.endpoint.metrics.enabled=true
然而,当我击打时
localhost:8080/actuator/metrics
我收到了404错误。
有什么解决方案吗?
在我的Spring Boot App(2.0.0.M7)的application.properties文件中,我设置了
management.endpoint.metrics.enabled=true
然而,当我击打时
localhost:8080/actuator/metrics
我收到了404错误。
有什么解决方案吗?
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<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都可以在/actuator
而不是/hello/actuator
上使用。
/actuator
终端节点的响应默认情况下启用了HATEOAS。在Spring Boot 2之前,只有在application.yml
中明确启用如果HATEOAS在类路径上并显式启用时才会这样做。
要通过HTTP公开actuator终端节点,它需要同时启用和公开。
默认情况下:
仅公开/health
和/info
终端节点,无论Spring Security是否存在并在应用程序中进行配置。
启用所有终端节点,但/shutdown
除外(尽管仅公开/health
和/info
)
如果要公开所有终端节点(并不总是一个好主意),可以通过在application.properties
中添加management.endpoints.web.exposure.include=*
来实现。如果使用yml配置,请不要忘记引用通配符。
endpoints.xyz
开头的旧属性已弃用,取而代之的是以management.xyz
开头的属性请在您的 application.properties
文件中添加以下行:
management.endpoints.web.exposure.include=metrics
就这些。
management.endpoints.web.exposure.include=*
对我也有效。 - Vladyslav Nikolaiev以下是适用于Spring Boot 2版本的操作(YAML格式):
management:
endpoints:
web:
exposure:
include: info, health, metrics
metrics:
export:
atlas:
enabled: false
同时也可以在这里找到具体的文档。
我遇到了从Spring Boot 1.5.15升级到2.1.4的同样问题。
需要修改在我的pom.xml
中的Spring Boot actuator的原始依赖项,从:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
to:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
artifactId
中加入了单词starter
。application.properties
文件中添加以下属性。直到我添加了以下属性,我才解决了同样的问题。management.endpoints.beans.enabled=false
management.endpoints.web.exposure.include=*
management:
endpoints:
web:
exposure:
include: "*"
导航到management.endpoints.web.exposure.include:metrics
/actuator/metrics
会显示可用计量器名称列表。management.endpoints.web.exposure.include=metrics
来设置application.properties
。 - Poli好的,我找到了解决方法。我在application.properties文件中添加了另一行。
management.endpoints.web.expose=*
在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包括许多内置端点,并允许您添加自己的端点。例如,health端点提供基本的应用程序健康信息。
每个单独的端点都可以启用
或禁用
并在HTTP
或JMX
上公开
(远程访问)。只有当端点同时启用和公开时,才被认为是可用的。 内置端点仅在可用时才会自动配置。大多数应用程序选择通过HTTP公开,其中端点的ID以及/actuator前缀映射到URL。例如,默认情况下,health端点映射到/actuator/health。
默认情况下,除了关闭之外的所有端点都是启用的。
management.health.defaults.enabled=false
management.endpoints.web.exposure.include=*
。 - fdauganmanagement.endpoints.web.exposure.include: '*'
。 - Timi