Cheatsheet
Actuator
Key idea
Spring Boot Actuator adds operational endpoints to your application (health, info, metrics, configuration, beans, logs…). They're turned on with `spring-boot-starter-actuator`, published over HTTP or JMX according to the exposure settings and extended with your own `HealthIndicator`s, `InfoContributor`s, Micrometer metrics and `@Endpoint`s.
Diagram (UML)
classDiagram
direction LR
class HealthEndpoint {
<<endpoint health>>
}
class InfoEndpoint {
<<endpoint info>>
}
class MetricsEndpoint {
<<endpoint metrics>>
}
class BoxStatusEndpoint {
<<@Endpoint boxstatus>>
+status() @ReadOperation
+rowers(int) @WriteOperation
}
class EquipmentHealthIndicator {
<<HealthIndicator>>
+health() Health
}
class BoxInfoContributor {
<<InfoContributor>>
+contribute(Info.Builder)
}
class MeterRegistry {
<<Micrometer>>
+counter / timer / gauge
}
class BookingService {
<<@Service>>
}
HealthEndpoint --> EquipmentHealthIndicator : aggregates (DOWN → 503)
InfoEndpoint --> BoxInfoContributor : collects
MetricsEndpoint --> MeterRegistry : reads
BookingService --> MeterRegistry : box.bookings{wod}Key pieces
spring-boot-starter-actuator; base path/actuator- Endpoints:
health,info,metrics,env,beans,conditions,configprops,loggers,mappings,threaddump,heapdump,prometheus,shutdown management.endpoints.web.exposure.include/exclude;management.endpoint.<id>.enabledHealthIndicator,Health.up()/down(),Status(UP,DOWN,OUT_OF_SERVICE,UNKNOWN);management.endpoint.health.show-detailsInfoContributor,info.*properties withmanagement.info.env.enabled=true- Micrometer:
MeterRegistry,Counter,Timer,Gauge, tags @Endpoint(id = …)+@ReadOperation(GET),@WriteOperation(POST),@DeleteOperation(DELETE)
EquipmentHealthIndicator.java
@Component // bean name "equipmentHealthIndicator" → component "equipment"
public class EquipmentHealthIndicator implements HealthIndicator {
private final Equipment equipment;
public EquipmentHealthIndicator(Equipment equipment) {
this.equipment = equipment;
}
@Override
public Health health() {
int rowers = equipment.workingRowers();
Health.Builder status = rowers >= 2 ? Health.up() : Health.down(); // DOWN → HTTP 503
return status.withDetail("workingRowers", rowers).build();
}
}Remember for the exam
- Over HTTP only
healthis exposed by default; the rest must be included withmanagement.endpoints.web.exposure.include - Exposed and enabled are different things: an endpoint can be enabled and not exposed (it answers 404 over HTTP)
- Health aggregates every
HealthIndicator: if one isDOWN, the total isDOWNand the HTTP response is 503 - The health component name comes from the bean without the
HealthIndicatorsuffix:equipmentHealthIndicator→equipment /actuator/metricslists the names;/actuator/metrics/{name}?tag=key:valuefilters by tag- There are health groups for Kubernetes:
/actuator/health/livenessand/actuator/health/readiness
Exam traps
- Exposing everything (
include=*) in production without security leaks sensitive information (env,heapdump…) shutdownis disabled by default: it must be enabled and exposed- Since Boot 2.6,
info.*properties don't appear in/actuator/infounless you setmanagement.info.env.enabled - Health details aren't shown by default (
show-details=never);when-authorizedshows them only to authorized users