Spring Boot · Lesson 10 of 15
Actuator, Health and Metrics
Expose health, info and Prometheus metrics without leaking internals.
- Intermediate
- 15 min read
- 3 objectives
Before this lessonLesson 9: Caching with Spring Cache
What you will learn
- Add Actuator
- Customise health
- Scrape metrics
Your Progress
0 of 15 lessons 0%
- Lessons0 / 15
- Completed0
- Est. time left~ 4 hours
Create a free account to keep your progress on every device.
Actuator exposes operational endpoints: health for the load balancer, metrics for Prometheus, info for the build version.
Dependencies and exposure
# application.yml
management:
endpoints:
web:
exposure:
include: health,info,prometheus
endpoint:
health:
show-details: when_authorized
probes:
enabled: true # /actuator/health/liveness and /readinessA custom health indicator
@Component
public class DiskHealth implements HealthIndicator {
@Override public Health health() {
long free = new File("/").getUsableSpace();
return free < 100_000_000
? Health.down().withDetail("free", free).build()
: Health.up().build();
}
}Do not expose env or heapdump on the public internet. Put Actuator on a separate port or restrict it to the cluster network.
