Spring Boot 2 - Actuator Metrics Endpoint not working

*爱你&永不变心* 提交于 2019-11-28 20:32:59
senseiwu

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

What hasn't changed

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>

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

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>

Changes introduced in Spring Boot 2

  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.

  2. 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

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

    By default:

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

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

  4. 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.

  5. Old properties starting with endpoints.xyz are deprecated in favor of properties starting with management.xyz

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

What worked for me is the following (in YAML format) working with spring boot 2 release:

management:
  endpoints:
    web:
      exposure:
        include: info, health, metrics
  metrics:
    export:
      atlas:
        enabled: false

also specific documentation can be found here

Jeen

Add the following line to your application.properties file:

management.endpoints.web.exposure.include=metrics

That's all.

Krish

You need to add the below props in your application.properties file. I had the same issue until I added the below props.

management.endpoints.beans.enabled=false
management.endpoints.web.exposure.include=*

"*" has a special meaning in YAML, so be sure to add quotes if you want to include (or exclude) all endpoints, as shown in the following example:

management:
  endpoints:
    web:
      exposure:
        include: "*"

Okay i found the solution. I have added another line in application.properties

management.endpoints.web.expose=*

However, securing the actuator endoints is important

Read here: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-monitoring.html

makson

According micrometer docs .Spring Boot 2.0.x supports Micrometer out of the box via Spring Boot Actuator.
The endpoint metric is disabled by default, in line with Spring Boot 2’s litmus test that any endpoint that potentially exposes sensitive data about an application should be disabled by default. It can be enabled by setting:

management.endpoints.web.exposure.include: metrics

Navigating to /actuator/metrics displays a list of available meter names.

To access them, use something like this: http://localhost:8080/actuator/metrics/jvm.memory.used

Had the same issue upgrading from Spring Boot 1.5.15 to 2.1.4

Needed to modify the original dependency for the Spring Boot actuator in my pom.xml from:

<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>

notice the addition of the word starter in the artifactId.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!