Explore Spring Boot Actuator and the changes introduced in Spring Boot 2.0.
- [Instructor] Spring Boot Actuator is actually one of the most changed artifacts within Spring Boot 2.0. We need to start with understanding what Actuator is and what its uses are. Actuator itself provides insights into your running applications. It provides configuration settings, usually exposed through JMX, but can be also exposed through the web. Actuator allows you to monitor your running application, which, in production, is extremely important, especially in dealing with the microservices architecture.
Now, as I alluded to, some of the biggest changes in Spring Boot 2.0, was actually in Actuator. And that is because Actuator itself has been one of the most popular projects within the original Spring Boot, so there was lots of feedback on ways to improve it. These dramatic changes have made Spring Boot Actuator even more powerful in the 2.0 iteration than it was in the 1.0 iteration. Now, out-of-the-box, you get full web functionality for two very important endpoints.
The first is the health endpoint, which provides status of the application in a running state. It also provides a status of all of the dependencies of your application, like databases or messaging cues. This is especially important for your monitoring endpoints used by your operations team that is monitoring your applications, hopefully 24/7. The next endpoint for the web side that is very useful is the info endpoint, and, in my opinion, it's often underutilized.
This can give you a one stop shop to provide a list of information that your consumers need to know about who to contact and how to contact. It also allows you to embed information into your artifact, such as the git commit, the build status, and several other very important details that can help you troubleshoot your production issues. Now there's also a lot of JMX functionality out-of-the-box, and I'm gonna talk about a few of them. The first is the beans endpoint, which literally provides a listing of all of the beans exposed in your current application context.
The env, or environment listing, give you just that, and that's the state of the entire environment as it exists for your running application. There's a heapdump and a threaddump that provides you with memory dumps. These, obviously, can be very dangerous, so you need to protect a lot of these endpoints, but the value through JMX and through monitoring systems is very hard to underestimate, because anyone who has dealt with anything with operations, these values are critical to keeping the systems up and running healthy.
There's also a mappings endpoint that gives you a listing of all of your web url mappings. Again, this can be very valuable for an operations team in understanding what APIs your application is exposing. And then metrics, which is the big one, and this focuses on micrometer metrics, which allows you to provide a facade on very common metrics endpoints, like Datadog or Prometheus, to name a few. These metrics can be customizable as well as default behavior turned on out-of-the-box.
And we're gonna talk a little bit about the metrics endpoint as we go through this chapter. Now, there are several ways to actually define what is exposed through the Actuator plug-in. The first is, you can set your JMX exposure to either be excluded or included. The same for the web, using these properties in your application.yml or application.properties file. You can then turn each individual endpoint on or off, using the management.endpoint.<id>, such as metrics, .enabled property.
Now, one thing that's hard to underestimate is the value of securing Spring Boot Actuator. Because of the sensitivity of the information contained within it, you must leverage security when you turn on Acutator. Any user that is going to need to access the advanced features of Actuator, or the more sensitive endpoints, that role needs to be provided of endpoint_admin. Now, I really highly urge you, do not leave security out with Actuator. The sensitive endpoints contain enough information, that any bad actor, whether external or, even worse, internal, who gets access to this data can wreck havoc on your system, the system that your application is running on, or any adjacent systems in your infrastructure, so please, please, secure your Actuator endpoints, and never expose them outside your organization, if you can avoid it.
- Creating a Spring Boot application
- Configuring a Spring Boot app
- Leveraging profiles
- Packaging and running Spring Boot web apps
- Building a command-line application
- Using Spring Boot starters: Spring Data, Spring Security, and more
- Extending Spring Boot
- Using Spring Boot Actuator to monitor app health and other metrics