SpringBoot – Actuators
Spring Boot Actuator brings in several production grade services to your application. Spring Boot Actuators has various number of built-in endpoints.

Actuators helps us monitor and interact with your application. Spring Boot also lets us to create our own endpoints too. These end points can be both enabled or disabled.

Below are some of the Spring Boot Actuator endpoints,

EndPoint Description
/actuator/health Basic health information of the application
/actuator/configprops list of all @ConfigurationProperties
/actuator/info Arbitrary Information
/actuator/auditevents audit events of the application
/actuator/httptrace HTTP trace information
/actuator/metrics Metrics information of the application
/actuator/mappings @RequestMappings in the application
/actuator/scheduledtasks Scheduled tasks in the application
/actuator/shutdown Shutdowns the application

Let us write a sample application to test the spring boot actuator end points.

pom.xml

  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
    </parent>

    <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>

    <properties>
        <java.version>1.8</java.version>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<maven.compiler.target>1.8</maven.compiler.target>
		<maven.compiler.source>1.8</maven.compiler.source>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

add this property in application.properties,

application.properties

management.endpoints.web.exposure.include=* (or you can include separate end points like health, info etc - to include all use '*')

SampleController.java

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ControllerSample {
	@GetMapping(value = "/")
	public String showStatus() {
		return "Lets check ";
	}
}

App.java

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

Let us start the application,

 

Once the application is started, we can see the actuators are getting initialized. when we hit localhost:8080/actuator/{endpoint} we can see the information

Here are some sample endpoint outputs,

/actuator/health

/actuator/mappings

/actuator/httptrace

Download Example here

By Sri

One thought on “Spring Boot Actuators – How to use it in application”

Leave a Reply

Your email address will not be published. Required fields are marked *