Spring Boot Actuator
What Is Actuator?
Spring Boot Actuator provides production-ready features for monitoring and managing your application. Actuator exposes endpoints to view health, metrics, info, and more.
Adding the Dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Once added, restart the application. Many new endpoints become available at /actuator.
Active Endpoints
By default, only two endpoints are active:
| Endpoint | URL | Description |
|---|---|---|
health |
/actuator/health |
Application health status |
info |
/actuator/info |
Application information |
Access via browser or curl:
curl http://localhost:8080/actuator/health
{
"status": "UP"
}
Enabling All Endpoints
# application.properties
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
Now all endpoints are active. Check the full list:
curl http://localhost:8080/actuator
{
"_links": {
"self": { "href": "/actuator", "templated": false },
"health": { "href": "/actuator/health" },
"info": { "href": "/actuator/info" },
"beans": { "href": "/actuator/beans" },
"metrics": { "href": "/actuator/metrics" },
"env": { "href": "/actuator/env" },
"mappings": { "href": "/actuator/mappings" }
}
}
Important Endpoints
Health Check
management.endpoint.health.show-details=always
management.health.db.enabled=true
management.health.diskspace.enabled=true
curl http://localhost:8080/actuator/health
{
"status": "UP",
"components": {
"db": { "status": "UP", "details": { "database": "H2" } },
"diskSpace": { "status": "UP" }
}
}
Info Endpoint
Add info in application.properties:
info.app.name=My Spring Boot App
info.app.version=1.0.0
info.app.description=Spring Boot tutorial application
info.app.author=Luthfi
curl http://localhost:8080/actuator/info
{
"app": {
"name": "My Spring Boot App",
"version": "1.0.0",
"description": "Spring Boot tutorial application",
"author": "Luthfi"
}
}
Metrics Endpoint
# All metrics
curl http://localhost:8080/actuator/metrics
# A specific metric
curl http://localhost:8080/actuator/metrics/jvm.memory.used
# HTTP request metrics
curl http://localhost:8080/actuator/metrics/http.server.requests
Environment Endpoint
curl http://localhost:8080/actuator/env
Shows all environment properties, including system properties and application properties.
Exposure Configuration
Exposing Specific Endpoints
# Only expose certain endpoints
management.endpoints.web.exposure.include=health,info,metrics
Exposing via JMX
management.endpoints.jmx.exposure.include=health,info
Custom Base Path
# Replace /actuator with /manage
management.endpoints.web.base-path=/manage
Disabling an Endpoint
# Disable the env endpoint
management.endpoint.env.enabled=false
Custom Health Indicator
Create a custom health check for a specific component:
@Component
public class ExternalApiHealthIndicator implements HealthIndicator {
private final ExternalApiService apiService;
public ExternalApiHealthIndicator(ExternalApiService apiService) {
this.apiService = apiService;
}
@Override
public Health health() {
try {
boolean isUp = apiService.checkConnection();
if (isUp) {
return Health.up()
.withDetail("external-api", "Connected")
.build();
} else {
return Health.down()
.withDetail("external-api", "Not responding")
.build();
}
} catch (Exception e) {
return Health.down()
.withDetail("external-api", e.getMessage())
.build();
}
}
}
@Component
public class DiskSpaceHealthIndicator implements HealthIndicator {
@Override
public Health health() {
File root = new File("/");
long freeGB = root.getFreeSpace() / (1024 * 1024 * 1024);
if (freeGB < 1) {
return Health.down()
.withDetail("free-space", freeGB + " GB")
.build();
}
return Health.up()
.withDetail("free-space", freeGB + " GB")
.build();
}
}
Production Configuration
# Production config
management.endpoints.web.exposure.include=health,info,metrics
management.endpoint.health.show-details=when-authorized
management.health.db.enabled=true
management.health.livenessstate.enabled=true
management.health.readinessstate.enabled=true
# Info from git
info.git.mode=full
info.git.branch=main
Monitoring with Micrometer
Actuator uses Micrometer for metrics. Integrating with monitoring systems:
<!-- Prometheus -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
# Prometheus endpoint
management.endpoints.web.exposure.include=health,info,prometheus
management.metrics.tags.application=myapp
# Prometheus metrics
curl http://localhost:8080/actuator/prometheus
Actuator helps you monitor the application in production. In the next chapter, we'll learn about Spring Security to protect the application.