springboot-How to enable all endpoints of acutator in spring boot 1.x and 2.x apps ?
1. The purpose of this post
By default, spring boot 1.x and 2.x apps only enable info and health endpoint of actuator, sometimes, we want to enable all endpoints temporarily. It’s easy, let’s do it.
2. Environments
- SpringBoot 1.x and 2.x
- Java 1.8+
3. The solution
3.1 Add actuator dependency your POM.xml
If springboot find the tomcat connection pool jar file in the classpath, then it would use it as the default connection pool. We must remove it.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Run your springboot app, and visit http://localhost:8080/actuator/metrics, you would get this:
{"timestamp":"2019-05-15T14:39:43.172+0000","status":404,"error":"Not Found","message":"No message available","path":"/actuator/metrics"}%
3.2 Change your application.properties like this
In order to access all endpoints of spring boot actuator, you should add this property to your application.properties:
management.endpoints.web.exposure.exclude=
management.endpoints.web.exposure.include=*
It means that include everything.
3.3 Rerun the code
When visit http://localhost:8080/actuator/metrics we should get this:
{"names":["jvm.memory.max","http.server.requests","process.files.max","jvm.gc.memory.promoted","tomcat.cache.hit","system.load.average.1m","tomcat.cache.access","jvm.memory.used","jvm.gc.max.data.size","jvm.memory.committed","system.cpu.count","logback.events","tomcat.global.sent","jvm.buffer.memory.used","tomcat.sessions.created","jvm.threads.daemon","system.cpu.usage","jvm.gc.memory.allocated","tomcat.global.request.max","tomcat.global.request","tomcat.sessions.expired","jvm.threads.live","jvm.threads.peak","tomcat.global.received","process.uptime","tomcat.sessions.rejected","process.cpu.usage","tomcat.threads.config.max","jvm.classes.loaded","jvm.gc.pause","jvm.classes.unloaded","tomcat.global.error","tomcat.sessions.active.current","tomcat.sessions.alive.max","jvm.gc.live.data.size","jdbc.connections.max","jdbc.connections.min","tomcat.servlet.request.max","tomcat.threads.current","tomcat.servlet.request","process.files.open","jvm.buffer.count","jvm.buffer.total.capacity","tomcat.sessions.active.max","tomcat.threads.busy","process.start.time","tomcat.servlet.error"]}%
4. Conclusion
As you can see, enabling all endpoints of spring boot 1.x and 2.x applications is very easy.