Production systems need health probes, metrics and diagnostics; Actuator provides them out of the box.
Add spring-boot-starter-actuator and the app gains management endpoints under /actuator. Only health is exposed over HTTP by default; expose more deliberately with management.endpoints.web.exposure.include=health,info,metrics,prometheus.
Key endpoints:
/actuator/healthaggregates health indicators: database, disk space, Redis, message brokers, each auto-configured when the dependency is present. Show details withmanagement.endpoint.health.show-details=when-authorized. On Kubernetes,/actuator/health/livenessand/actuator/health/readinessprobe groups are enabled automatically./actuator/metricslists Micrometer metrics: JVM memory and GC, HTTP request timings (http.server.requests), connection pool usage. Addingmicrometer-registry-prometheusexposes/actuator/prometheusfor scraping./actuator/infoshows build and git information when configured;loggerschanges log levels at runtime;env,beans,mappings,configpropsandthreaddumphelp debugging.
Record your own metrics by injecting MeterRegistry and creating counters and timers, or use the @Observed annotation with the Observation API for metrics plus traces. Write a custom HealthIndicator bean to report the state of a dependency Boot doesn't know about.
Endpoints like env and heapdump expose sensitive data: put the management port behind the firewall (management.server.port) or secure it with Spring Security.
Example
# application.properties
management.endpoints.web.exposure.include=health,info,metrics,prometheus
management.endpoint.health.show-details=when-authorized
management.server.port=8081
// PaymentsHealth.java: a custom indicator, shown as "payments" in /actuator/health
@Component
class PaymentsHealth implements HealthIndicator {
public Health health() {
boolean up = pingPaymentProvider();
return up ? Health.up().withDetail("provider", "stripe").build()
: Health.down().withDetail("reason", "timeout").build();
}
private boolean pingPaymentProvider() { return true; }
}
@Service
class OrderService {
private final Counter placed;
OrderService(MeterRegistry registry) {
placed = Counter.builder("orders.placed").tag("channel", "web").register(registry);
}
void place() { placed.increment(); } // visible at /actuator/metrics/orders.placed
}Remember
- Actuator adds /actuator endpoints; only health is exposed by default
- Health indicators are auto-configured for each dependency
- Micrometer metrics export to Prometheus and other systems
- Secure or isolate management endpoints
Watch out for
- Exposing all endpoints (include=*) on the public port, leaking environment variables and heap dumps.