4.4 Spring Boot Actuator
← Back to Chapter 4: Exception Handling, Logging & Production Support
Spring Boot Actuator brings production-ready monitoring, telemetry, and management endpoints to your running application via HTTP or JMX.
What is Spring Boot Actuator?
Actuator provides production-ready features for monitoring and managing Spring Boot applications.
Common endpoints include:
/actuator/health
/actuator/info
/actuator/metrics
Other endpoints exist, but they should be exposed carefully.
Example configuration:
management.endpoints.web.exposure.include=health,info,metrics
1. Key Actuator Endpoints
| Endpoint | Purpose | Security Default |
|---|---|---|
/actuator/health | Shows application uptime status (UP, DOWN, OUT_OF_SERVICE). Used by Kubernetes probes. | Exposed by default |
/actuator/info | Arbitrary application metadata (git commit hash, version, build time). | Disabled by default |
/actuator/metrics | JVM memory, thread pool usage, HTTP request latencies. | Disabled by default |
/actuator/env | Inspects currently loaded environment properties. | Disabled by default (Sensitive) |
/actuator/beans | Full catalog of all registered Spring beans in the container. | Disabled by default |
/actuator/loggers | Query and dynamically adjust logging levels at runtime without restarting! | Disabled by default |
2. Exposing & Securing Actuator in application.yml
management:
endpoints:
web:
exposure:
include: health,info,metrics,prometheus
base-path: /actuator
endpoint:
health:
show-details: when-authorized
probes:
enabled: true # Enables /actuator/health/liveness and readiness for K8s
server:
port: 8081 # Separate management port from user-facing port 8080!
Security Warning: Exposing sensitive endpoints like
/actuator/envor/actuator/heapdumppublicly without authentication can leak database passwords and secrets. Always secure the management port or restrict it to internal VPC networks.
3. Custom Health Indicators
You can write custom health indicators to check downstream dependencies:
@Component
public class PaymentGatewayHealthIndicator implements HealthIndicator {
private final PaymentGatewayClient client;
public PaymentGatewayHealthIndicator(PaymentGatewayClient client) {
this.client = client;
}
@Override
public Health health() {
try {
boolean isReachable = client.ping();
if (isReachable) {
return Health.up().withDetail("provider", "Stripe").withDetail("latencyMs", 12).build();
}
return Health.down().withDetail("error", "Ping timeout").build();
} catch (Exception ex) {
return Health.down(ex).build();
}
}
}