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

Lets 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

Lets start the application on your local and access to http://localhost:8080/actuator, you would see the current 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  

Endpoint of each API can also be modified by updating 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 application on production environment. You can explore more about it at here