Actuator: health, metrics and info

Spring Boot · Practical · 12 min

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/health aggregates health indicators: database, disk space, Redis, message brokers, each auto-configured when the dependency is present. Show details with management.endpoint.health.show-details=when-authorized. On Kubernetes, /actuator/health/liveness and /actuator/health/readiness probe groups are enabled automatically.
  • /actuator/metrics lists Micrometer metrics: JVM memory and GC, HTTP request timings (http.server.requests), connection pool usage. Adding micrometer-registry-prometheus exposes /actuator/prometheus for scraping.
  • /actuator/info shows build and git information when configured; loggers changes log levels at runtime; env, beans, mappings, configprops and threaddump help 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.

Check yourself

  1. Which endpoint is exposed over HTTP by default after adding Actuator?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: docs.spring.io/spring-boot/reference/actuator/endpoints.html

Builds on

Unlocks

Nothing builds on this yet.