Spring Boot 2 - 执行器指标端点不起作用 [英] Spring Boot 2 - Actuator Metrics Endpoint not working

查看:55
本文介绍了Spring Boot 2 - 执行器指标端点不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我设置的 Spring Boot App (2.0.0.M7) application.properties 中

In my Spring Boot App (2.0.0.M7) application.properties I set

management.endpoint.metrics.enabled=true

但是,当我点击

localhost:8080/actuator/metrics 

我得到 404.

解决办法是什么?

推荐答案

我想用更多信息来增强 OP 的答案,因为我在最终偶然发现这个解决方案之前挣扎了一点,而且似乎有很多关于更改的困惑Spring Boot 2 的执行器行为

I would like to enhance the OP's answer with more information as I struggled a bit before finally stumbling upon this solution and there seem to be lots of confusion about changes to actuator behavior with Spring Boot 2

什么没有改变

您需要包含对 spring-boot-starter-actuator 的依赖

You need to include a dependency to spring-boot-starter-actuator

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
</dependencies>

如果你想通过 HTTP 访问执行器端点,你还需要添加一个依赖到 spring-boot-starter-web

If you want to access actuator endpoints via HTTP, you also need to add a dependency to spring-boot-starter-web

因此您的 pom 依赖项将如下所示

So your pom dependencies will look like below

    <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 中引入的变化

  1. /health/metrics 等端点在默认根上下文中不再可用.从现在开始,它们可以在http://{host}:{port}/actuator.此外,您的应用程序的所有其他端点是否以其他上下文(例如 /hello)开头都没有关系——执行器在 /actuator 处可用,而在 处不可用/你好/执行器.

  1. Endpoints like /health, /metrics etc. are no longer available at the default root context. They are available from now on at http://{host}:{port}/actuator. Also, it doesn't matter whether your application's all other endpoints begin with some other context such as /hello -- actuator is available at /actuator and not at /hello/actuator.

来自 /actuator 端点的响应默认启用 HATEOAS.在 Spring Boot 2 之前,只有 如果 HATEOAS 在类路径上并且在 application.yml

Response from /actuator endpoint is by default HATEOAS enabled. Prior to Spring Boot 2, this was the case only if HATEOAS is on the classpath and explicitly enabled in application.yml

要使执行器端点通过 HTTP 可用,它需要启用和公开.

To make an actuator endpoint available via HTTP, it needs to be both enabled and exposed.

默认:

  • 仅暴露 /health/info 端点,而不管您的应用程序中是否存在和配置 Spring Security.

  • only the /health and /info endpoints are exposed, regardless of Spring Security being present and configured in your application.

除了 /shutdown 之外的所有端点都被启用(虽然只有 /health/info 被暴露)

all endpoints but /shutdown are enabled (though only /health and /info are exposed)

如果您想公开所有端点(这并不总是一个好主意),您可以通过将 management.endpoints.web.exposure.include=* 添加到 来实现>application.properties.如果您使用 yml-configurations,请不要忘记引用通配符.

If you want to expose all of the endpoints (not always a good idea), you may do so by adding management.endpoints.web.exposure.include=* to application.properties. Don't forget to quote the wildcard if you're using yml-configurations.

有关完整文档,请参阅 官方文档 以及 迁移指南

For a full documentation, see official doc and also the migration guide

这篇关于Spring Boot 2 - 执行器指标端点不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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