Spring Boot monitoring (Actuator endpoints)

One of the important thing is the monitoring of the production environment. And the Actuator endpoints will give us some capability to monitor the spring boot application. So for this we need to include the Actuator dependency in the pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.springboot</groupId>
    <artifactId>example</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>1.4.1.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    </dependencies>
</project>

[addToAppearHere]

And the next step will be to create the application.properties file in the resources folder:

endpoints.enabled=true

And the last thing is to create the Application.java class which will run the Spring Boot Application:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan({"com.springboot.example"})
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

By default it will use 8080 port. So you can use following endpoints:

  • /health – shows application health information
  • /beans – the list of all spring beans in the application
  • /metrics –  metrics like memory, processor, up time, committed heap, etc…

The full documentation you can fine here.

We can also enable/disable the individual endpoints. So let’s say that we want to disable all Actuator endoints, and enable only health endpoint. To do this we need to change the application.propeties file:

# disable all endpoints
endpoints.enabled=false
# enable health endpoint
endpoints.health.enabled=true