Spring Boot Actuator is a library providing built-in APIs (such as health check) to help you monitor and manage Spring Boot applications on production environment through HTTP endpoints and JMX

Let's walk through this tutorial to explore in more details

Add Spring Boot Actuator to your project

You can add Spring Boot Actuator into your project as a dependency on pom.xml or build.gradle file. The library versions can be omitted as Spring Boot can help you to resolve

On pom.xml file

<dependencies>  
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>  

On build.gradle file

dependencies {  
    compile("org.springframework.boot:spring-boot-starter-actuator")
    compile("org.springframework.boot:spring-boot-starter-web")
}

spring-boot-starter-web should be included if you'd like to use the HTTP endpoints

Actuator APIs and endpoints

Actuator exposes its APIs through endpoints with prefix as /actuator by default. You can see and use it immediately after including the dependency into your project

Let's start the application on your local and access to http://localhost:8080/actuator, you would see the currently available APIs

These default enabled APIs can be controlled via below properties

management.endpoints.web.exposure.include=info, health  
management.endpoints.web.exposure.exclude  

Beside info and health, Actuator also provide other APIs such as

  • loggers for retrieving and modifying loggers configuration

  • metrics for retrieving all available metrics information

  • prometheus for exposing metrics to be scrapped by a Prometheus server

  • flyway and liquibase for retrieving database migration history if you're using Flyway or Liquibase

To discover all the available APIs, inside your application.properties file, update management.endpoints.web.exposure.include=* and refresh http://localhost:8080/actuator

Modify endpoints

You can use another prefix instead of /actuator for the Actuator APIs, by updating property as the following

management.endpoints.web.base-path=/manage  

The endpoint of each API can also be modified by updating the respective property. The following updates the health check endpoint to healthcheck instead of health by default

management.endpoints.web.path-mapping.health=healthcheck  

Conclusion

In this tutorial, we learned using Spring Boot Actuator APIs to provide monitoring APIs to the application on the production environment. You can explore more about it at here

Share to social

Van N.

Van N. is a software engineer, creator of HelloKoding. He loves coding, blogging, and traveling. You may find him on GitHub and LinkedIn