Spring Boot Actuator Endpoints lets us monitor and interact with our application. Spring Actuator is a Spring Boot sub-module and provides built-in endpoints that we can enable and disable for our application.

Spring Boot Actuator Endpoints

Spring Boot Actuator Endpoints are exposed over JMX and HTTP, most of the times we use HTTP based Actuator endpoints because they are easy to access over the browser, CURL command, shell scripts etc.

Some of the useful actuator endpoints are:

  1. beans: this endpoint returns the list of all the beans configured in our application.
  2. env: provides information about the Spring Environment properties.
  3. health: Shows application health
  4. info: Displays application information, we can configure this in Spring environment properties.
  5. mappings: Displays the list of all @RequestMapping paths.
  6. shutdown: allows us to gracefully shutdown the application.
  7. threaddump: provides the thread dump of the application.

You can get the complete list of spring actuator endpoints from here.

Spring Actuator Endpoints Security

Only “health” and “info” endpoints are exposed without any security, for accessing all other endpoints we need to configure our application for spring security. This is very easy to achieve, we will get to it in the later part of the tutorial.

Enable Spring Actuator Endpoints

When we add Spring Actuator Dependencies to our spring boot project, it automatically enables actuator endpoints.

Add below dependencies to your spring application to enable spring boot actuator endpoints.

Now when you will run the application, you will see actuator endpoints being mapped in the logs.

Notice that only two endpoints – health and info has been mapped.

Below image shows the output of these actuator endpoints.

spring-boot-actuator-endpoint-info-default

spring-boot-actuator-endpoint-info-default

 

Did you noticed that there is no data in the /actuator/info, it’s because we haven’t configured them. Just add following properties to your application.properties file.

Restart the application and you will get following output:

spring-boot-actuator-endpoint-info-value

Customizing Actuator End Points Base Path

By default base-path of actuator endpoints is /actuator, we can change it to any other value by setting management.endpoints.web.base-path in application properties file.

Exposing Other Actuator Endpoints

We can enable and disable other actuator endpoints through property files.

If you want to enable all actuator endpoints, then add following property.

To enable only specific actuator endpoints, provide the list of endpoint id.

Spring Security for Actuator Endpoints

Note that we need to add Spring Security to our application for enabling additional endpoints because all other endpoints need at least basic authentication.

Add following dependency for spring security in your application.

Also, add spring security username and password in application properties file.

Restart the application and you will see additional endpoints being mapped.

Now when you will try to access the secured actuator endpoints, you will have to provide login credentials.

spring-boot-actuator-endpoint-security-user-password

Below images shows the response of beans and env/java.home endpoints.

spring boot actuator endpoint beans

spring boot actuator endpoint env java.home

Spring Actuator Custom Endpoints

One of the great features of Spring Framework is that it’s very easy to extend. We can create our own custom actuator endpoints using @Endpoint annotation on a class. Then we have to use @ReadOperation, @WriteOperation, or @DeleteOperation annotations on the methods to expose them as actuator endpoint bean.

We can create technology-specific Endpoints using @JmxEndpoint and @WebEndpoint annotations.

Here is an example of our own custom spring actuator endpoint.

Did you notice the endpoint id? We also need to configure this in the list of actuator endpoints to be enabled.

Update following properties in application.properties file.

Now when you will start the application, check for this new endpoint being mapped in the logs.

Below image shows the output when we invoke our custom actuator endpoint.

spring-boot-actuator-custom-endpoint

Summary

Spring Boot Actuator is a production ready management and information module. We can easily extend it to add our own APIs and manage our application.

By admin

Leave a Reply

%d bloggers like this: