Spring Boot actuators

The previous sections explored most of the Spring Boot features required to develop a microservice. In this section, some of the production-ready operational aspects of Spring Boot will be explored.

Spring Boot actuators provide an excellent out-of-the-box mechanism to monitor and manage Spring Boot applications in production:

Note

The full source code of this example is available as the chapter2.bootactuator project in the code files of this book.

  1. Create another Spring Starter Project and name it chapter2.bootactuator. This time, select Web and Actuators under Ops. Similar to the chapter2.bootrest project, add a GreeterController endpoint with the greet method.
  2. Start the application as Spring Boot app.
  3. Point the browser to localhost:8080/actuator. This will open the HAL browser. Then, review the Links section.

    A number of links are available under the Links section. These are automatically exposed by the Spring Boot actuator:

    Spring Boot actuators

Some of the important links are listed as follows:

  • dump: This performs a thread dump and displays the result
  • mappings: This lists all the HTTP request mappings
  • info: This displays information about the application
  • health: This displays the application's health conditions
  • autoconfig: This displays the autoconfiguration report
  • metrics: This shows different metrics collected from the application

Monitoring using JConsole

Alternately, we can use the JMX console to see the Spring Boot information. Connect to the remote Spring Boot instance from JConsole. The Boot information will be shown as follows:

Monitoring using JConsole

Monitoring using SSH

Spring Boot provides remote access to the Boot application using SSH. The following command connects to the Spring Boot application from a terminal window:

$ ssh -p 2000 user@localhost

The password can be customized by adding the shell.auth.simple.user.password property in the application.properties file. The updated application.properties file will look similar to the following:

shell.auth.simple.user.password=admin

When connected with the preceding command, similar actuator information can be accessed. Here is an example of the metrics information accessed through the CLI:

  • help: This lists out all the options available
  • dashboard: This is one interesting feature that shows a lot of system-level information
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.56.28