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)

ApplicationContextOps / load balancerboxstatus @Endpoint/actuatorhealthinfometricsEquipmentHealthIndicatorMeterRegistryBoxInfoContributor30BookingServiceEquipment (rowers)

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>.enabled
  • HealthIndicator, Health.up()/down(), Status (UP, DOWN, OUT_OF_SERVICE, UNKNOWN); management.endpoint.health.show-details
  • InfoContributor, info.* properties with management.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 health is exposed by default; the rest must be included with management.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 is DOWN, the total is DOWN and the HTTP response is 503
  • The health component name comes from the bean without the HealthIndicator suffix: equipmentHealthIndicator → equipment
  • /actuator/metrics lists the names; /actuator/metrics/{name}?tag=key:value filters by tag
  • There are health groups for Kubernetes: /actuator/health/liveness and /actuator/health/readiness

Exam traps

  • Exposing everything (include=*) in production without security leaks sensitive information (env, heapdump…)
  • shutdown is disabled by default: it must be enabled and exposed
  • Since Boot 2.6, info.* properties don't appear in /actuator/info unless you set management.info.env.enabled
  • Health details aren't shown by default (show-details=never); when-authorized shows them only to authorized users

← Actuator · Run it