What is Spring Boot Actuator?

Spring Boot Actuator provides production-ready features to monitor and manage your application. It includes several built-in endpoints to gather application metrics, monitor health, and interact with the application in real-time.

Advantages of Spring Boot Actuator

Actuator Endpoints

Below are the commonly used Actuator endpoints:

Endpoint Description Default Status
/actuator/health Displays the health status of the application. Enabled
/actuator/metrics Shows metrics for the application (e.g., memory, CPU, threads). Enabled
/actuator/loggers Shows and modifies the application's logging configuration. Enabled
/actuator/env Displays properties and their sources in the environment. Enabled
/actuator/mappings Displays a list of all request mappings in the application. Disabled
/actuator/beans Displays all Spring beans in the application context. Disabled

Real-Time Use Cases

How to Enable and Disable Actuator Endpoints

Actuator endpoints can be enabled or disabled using the application.properties file or Java configuration.

Enable/Disable All Endpoints


# Enable all Actuator endpoints
management.endpoints.web.exposure.include=*

# Disable all Actuator endpoints
management.endpoints.web.exposure.include=none
            

Enable/Disable Specific Endpoints


# Enable specific endpoints
management.endpoints.web.exposure.include=health,info,metrics

# Disable specific endpoints
management.endpoints.web.exposure.exclude=beans,mappings
            

Spring Boot Actuator - Testing All Endpoints

This guide provides detailed steps to test all built-in Spring Boot Actuator endpoints. Follow along to enable, configure, and test these endpoints effectively.

Setup

1. Add Dependency


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

2. Enable Endpoints

In application.properties, specify the endpoints to include:


# Enable all Actuator endpoints
management.endpoints.web.exposure.include=*

# Optional: Set base path for Actuator endpoints
management.endpoints.web.base-path=/actuator
            

Testing Built-in Endpoints

Below is a detailed list of Actuator endpoints with examples and usage:

Endpoint Description Example Output Test Instructions
/actuator/health Provides application health status. { "status": "UP", "components": { "db": { "status": "UP", "details": { "database": "H2", "validationQuery": "isValid()" } }, "diskSpace": { "status": "UP", "details": { "total": 499963174912, "free": 211963174912, "threshold": 10485760 } } } } Open http://localhost:8080/actuator/health in a browser or use a tool like Postman.
/actuator/metrics Displays application metrics like memory usage, CPU usage, and thread count. { "names": [ "jvm.memory.used", "jvm.gc.pause", "system.cpu.usage" ] } Visit http://localhost:8080/actuator/metrics and explore specific metrics by appending the metric name (e.g., /actuator/metrics/jvm.memory.used).
/actuator/info Displays custom application information. { "app": { "name": "Demo Application", "version": "1.0.0" } } Add application details in application.properties: info.app.name=Demo Application info.app.version=1.0.0 Test at http://localhost:8080/actuator/info.
/actuator/env Shows environment properties and their sources. { "activeProfiles": [], "propertySources": [ { "name": "systemProperties", "properties": { "java.runtime.name": { "value": "OpenJDK Runtime Environment" } } } ] } Visit http://localhost:8080/actuator/env.
/actuator/loggers Displays and modifies application logging levels. { "levels": [ "OFF", "ERROR", "WARN", "INFO", "DEBUG", "TRACE" ], "loggers": { "root": { "configuredLevel": "INFO", "effectiveLevel": "INFO" } } } Test at http://localhost:8080/actuator/loggers. To change a logger level, send a POST request: curl -X POST -H "Content-Type: application/json" -d '{"configuredLevel":"DEBUG"}' http://localhost:8080/actuator/loggers/com.example
/actuator/mappings Displays all request mappings in the application. { "contexts": { "application": { "mappings": { "dispatcherServlets": { "dispatcherServlet": [ { "handler": "ExampleController", "method": "exampleMethod" } ] } } } } } Test at http://localhost:8080/actuator/mappings.

Enable or Disable Specific Endpoints

Configuration in application.properties


# Enable specific endpoints
management.endpoints.web.exposure.include=health,info,metrics

# Disable specific endpoints
management.endpoints.web.exposure.exclude=env,loggers
            

Custom Actuator Endpoint

Create a custom endpoint:


@Component
@Endpoint(id = "custom")
public class CustomEndpoint {
    @ReadOperation
    public String customOperation() {
        return "Custom Actuator Endpoint Response";
    }
}
            

Access it at /actuator/custom.

Testing Tips