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?
To enable Spring Boot actuator endpoints to your Spring Boot application, we need to add the Spring Boot Starter actuator dependency in our build configuration file. Maven users can add the below dependency in your pom. xml file. Gradle users can add the below dependency in your build.
Spring Boot Actuator is not working because the spring boot actuator dependency is incorrect or the actuator isn't configured properly in the application. properties file. If the spring boot starter actuator is not configured, endpoints like health, info, shutdown, refresh, env, and metrics may not work.
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
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
.
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
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)
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.
endpoints.xyz
are deprecated in favor of properties starting with management.xyz
For a full documentation, see official doc and also the migration guide
Add the following line to your application.properties
file:
management.endpoints.web.exposure.include=metrics
That's all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With