Monitoring the server

We mentioned earlier that monitoring is quite important to understanding how an application performs in the wild. Fortunately, Spring has actuator, which is a library that can be easily attached to an existing Spring Boot application by adding the following dependency:

compile("org.springframework.boot:spring-boot-starter-actuator")

Spring Boot Actuator provides a bunch of endpoints that are ready to be consumed and provide useful information about the application. Let's review some of them in the following table:

Endpoint

Brief Description

/health

This provides brief information about the application status and its main dependencies, such as databases or messaging systems.

/autoconfig

This provides information about the auto-configuration provided for the app by the Spring Framework. Remember that Spring prefers convention over configuration, so you'll find tons of default values here.

/beans

This shows the list of Spring beans configured as a part of the application context.

/dump

This performs a thread dump at the exact moment that the endpoint is requested.

/env

This lists all of the variables configured in the server. Values provided as a part of .properties/.yml files and arguments provided to run the application are listed, as well.

/metrics

This shows some metrics around the available endpoints exposed in the app.

/trace This gives information regarding the last 100 (by default) requests, including details about the requests and responses.

 

If you are interested in a complete list of the endpoints available by default, I encourage you to visit https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html.

All of the preceding endpoints can mainly be configured with three parameters:

  • id: This is the endpoint identification
  • sensitive: This indicates whether or not Spring Actuator should enforce security
  • enabled: This indicates whether or not the Spring Actuator endpoints are available

If you want to configure the endpoints, you have to use the following entries as a part of your configuration (.properties/.yml) file:

endpoints.endpoint_name.property

The following bullet points expand upon this idea:

  • endpoints: This is a constant value.
  • endpoint_name: This should be replaced with the desired endpoint. 
  • property: This can be id, sensitive, or enabled.

For example, let's suppose that you want to enable the health endpoint, rename it to status, and not enforce security. To achieve this requirement, the configuration should look as follows:

endpoints.health.id = status
endpoints.health.sensitive = false
endpoints.health.enabled = true

All of the endpoints are enabled by default, except for /shutdown, which is intended to stop the application gracefully. 

Furthermore, Spring actuator can be configured to generate business metrics, as well. This is an excellent feature that can be integrated with other tools, which makes it possible to visualize the collected metrics using graphical interfaces. We will review this feature in detail in Chapter 12, Monitoring.

..................Content has been hidden....................

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