35

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

management.endpoint.metrics.enabled=true

However, when i hit

localhost:8080/actuator/metrics 

I get 404.

Whats the solution?

Dachstein
  • 2,752
  • 3
  • 26
  • 42

13 Answers13

78

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

Emir Kuljanin
  • 3,813
  • 1
  • 20
  • 30
senseiwu
  • 4,069
  • 4
  • 19
  • 39
  • 4
    Starting from spring-boot2, now is `management.endpoints.web.exposure.include=*` – fabdouglas Apr 30 '18 at 11:36
  • 18
    In case of yaml configuration you need to quote the wildcard, otherwise it will fail to parse: `management.endpoints.web.exposure.include: '*'` – Timi May 11 '18 at 13:23
  • @Timi I agree, answer is amended – senseiwu Jun 10 '18 at 17:42
  • I wander what is the use of the actuator if so much has been removed or disabled by default. I have the actuator in my project and the only thing useful is the health status and even that is questionable. Something is running or not and if down then the heartbeat disappears. The info url creates an empty json. So why use it at all? – Martijn Hiemstra Dec 22 '18 at 09:23
  • Nothing much is removed. Sensitive endpoints are disabled by default for some good reason – senseiwu Jan 03 '19 at 16:56
  • this makes sense but it annoys me the latest documentation says the opposite https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-endpoints-enabling-endpoints – Chad May 18 '20 at 20:21
19

Add the following line to your application.properties file:

management.endpoints.web.exposure.include=metrics

That's all.

Bonifacio2
  • 2,687
  • 4
  • 30
  • 44
Jeen
  • 281
  • 3
  • 4
10

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

tbo
  • 7,760
  • 6
  • 35
  • 46
  • 2
    When I use this, the /metrics endpoint works, but shows only the keys, not the values. What up??? – djangofan Sep 14 '18 at 02:39
  • 1
    yes this is how it works you then select a metric to display instead of having all metrics displayed in a messy single page, also useful for other apps like prometheus or atlas to read the metrics – tbo Sep 21 '18 at 13:48
7

"*" 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: "*"
Dilan
  • 1,259
  • 5
  • 14
  • 21
6

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=*
Sage Pourpre
  • 6,335
  • 2
  • 21
  • 32
Krish
  • 165
  • 2
  • 3
  • 6
6

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.

disposedtrolley
  • 152
  • 1
  • 6
3

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

dkb
  • 3,238
  • 3
  • 26
  • 41
makson
  • 1,056
  • 3
  • 12
  • 26
  • Only this one worked for me for ```application.properties``` by specifying ```management.endpoints.web.exposure.include=metrics``` – Poli May 28 '21 at 06:34
2

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

Dachstein
  • 2,752
  • 3
  • 26
  • 42
0

The following configuration works for me

server.servlet.context-path=/travel management.endpoints.web.exposure.include=*

Then you need to add context path: http://localhost:8080/travel/actuator/metrics/

Vikki
  • 1,317
  • 1
  • 10
  • 18
0
management:
  endpoints:
    web:
      base-path: "/"
      exposure:
        include: '*'

it should works like that. * means expose all endpoints

Lucifer
  • 1,556
  • 2
  • 15
  • 28
0

As @senseiwu mentioned, Unlike the previous versions, Actuator in spring boot 2 comes with most endpoints disabled. Would we want to enable all of them, we could set

management.endpoints.web.exposure.include=* 

Alternatively, we could list endpoints that should be enabled.

You can easily use hal-browser which is a useful UI, mapped to "/" path by adding following dependencies:

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

In the hal-browser you need to type /actuator to see all endpoints. It has been tested in Spring Boot 2.3.0.M2 and works perfectly. You can learn more in the following links:

Spring REST and HAL Browser

Spring Boot Actuator

0

Adding the below property in application.properties solved the issues for me:

management.health.defaults.enabled=false
KayV
  • 9,560
  • 8
  • 68
  • 111
0

Put here the full config for micrometer. The following one is working fine for me. I use it for ELK stack

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: '*'
Anton
  • 174
  • 1
  • 4
  • 15