# Spring Boot Actuator for Production Monitoring

> What is Spring Boot Actuator, which endpoints matter most, and how do you secure them?

Canonical: https://www.internhack.in/learn/interview/spring-boot-interview/spring-boot-actuator
Last updated: 2026-11-28

Difficulty: Intermediate

## Question

What is Spring Boot Actuator, which endpoints matter most, and how do you secure them?

## Answer

Shipping code is only half the job; you also need to know whether it is healthy once it is running. Is the database connection alive? How much memory is the JVM using? Which log level is active? Actuator is the Spring Boot module that answers those questions by exposing operational endpoints, and it is the foundation of monitoring for Boot microservices.

You add spring-boot-starter-actuator. Immediately you get endpoints under /actuator. By default over HTTP only health is exposed in Boot 2.5 and later, to be safe, and you opt in to others with management.endpoints.web.exposure.include. The important ones: health reports UP or DOWN by aggregating health indicators for the database, disk space, Redis, message brokers, and anything custom you register. info shows build and Git information. metrics exposes numbers such as JVM memory, GC, HTTP request counts and latencies, and connection pool statistics. prometheus, with micrometer-registry-prometheus, publishes these in a format a Prometheus server scrapes for Grafana dashboards. env and configprops show the configuration, loggers lets you change log levels at runtime without restart, threaddump and heapdump help debug production issues, mappings lists request mappings, beans lists the context, and conditions shows the auto-configuration report.

Micrometer is the metrics library underneath. Think of it as SLF4J for metrics: you write to a vendor-neutral API, and registries ship the data to Prometheus, Datadog, CloudWatch, or New Relic. You can add your own counters and timers with MeterRegistry, for example counting successful payments or timing a third-party call.

Health has two special uses in Kubernetes. Liveness answers is the process alive, and if it fails Kubernetes restarts the pod. Readiness answers can it serve traffic now, and if it fails the pod is removed from the load balancer without restarting. Boot supports these as health groups at /actuator/health/liveness and /actuator/health/readiness, enabled by management.endpoint.health.probes.enabled=true. A common mistake is making liveness depend on the database, so a database outage restarts every pod and worsens the incident. Keep liveness simple.

Security matters a lot here. Endpoints like env, heapdump, and loggers can leak secrets or let attackers change behaviour. Only expose what you need, place Actuator behind Spring Security with role restrictions, or move it to a separate management port using management.server.port so it is not reachable from the public internet. Sensitive values are sanitised by default, but do not rely on that alone.

Custom health indicators are easy: implement HealthIndicator and return Health.up() or Health.down().withDetail(...). Use this for a payment gateway ping, but keep the check quick and cached, since the health endpoint may be polled every few seconds.

## Code examples

### Configuring and extending Actuator

```
# application.yml
management:
  endpoints:
    web:
      exposure:
        include: health,info,metrics,prometheus,loggers
  endpoint:
    health:
      show-details: when-authorized
      probes:
        enabled: true
  server:
    port: 9091            # separate management port, not public

@Component
class PaymentGatewayHealth implements HealthIndicator {
    private final GatewayClient client;
    PaymentGatewayHealth(GatewayClient client) { this.client = client; }

    @Override
    public Health health() {
        return client.ping()
                ? Health.up().withDetail("gateway", "reachable").build()
                : Health.down().withDetail("gateway", "timeout").build();
    }
}

@Service
class PaymentService {
    private final Counter successCounter;
    PaymentService(MeterRegistry registry) {
        this.successCounter = registry.counter("payments.success");
    }
    void onSuccess() { successCounter.increment(); }
}
```

The custom indicator appears in the aggregate health, and Micrometer counters flow to Prometheus.

## Key points

- Only health is exposed over the web by default.
- Micrometer is the vendor-neutral metrics facade behind Actuator.
- Use separate liveness and readiness probes in Kubernetes.
- Restrict or move sensitive endpoints such as env and heapdump.

## Common follow-up questions

- What is the difference between liveness and readiness?
- How do you change a log level at runtime?
- How does Prometheus scrape a Spring Boot app?

## Interview tips

- Highlight the security risk of exposing all endpoints, it is a common interview check.
- Mention Kubernetes probes to show deployment awareness.

## Concepts covered

Actuator, Health Checks, Micrometer, Endpoints

Previous: [Password Encoding with BCrypt in Spring Security](https://www.internhack.in/learn/interview/spring-boot-interview/spring-security-password-encoding) · Next: [Spring AOP: Aspects, Advice and Proxies](https://www.internhack.in/learn/interview/spring-boot-interview/spring-aop-basics) · [All of Spring Boot](https://www.internhack.in/learn/interview/spring-boot-interview)

## More Spring Boot questions

- [Microservices with Spring Cloud: Service Discovery and API Gateway](https://www.internhack.in/learn/interview/spring-boot-interview/spring-cloud-discovery-gateway)
- [Circuit Breaker and Resilience4j](https://www.internhack.in/learn/interview/spring-boot-interview/spring-circuit-breaker-resilience4j)
- [Testing: @SpringBootTest vs @WebMvcTest vs @DataJpaTest](https://www.internhack.in/learn/interview/spring-boot-interview/spring-testing-slices)
- [Testing Controllers with MockMvc and Mockito](https://www.internhack.in/learn/interview/spring-boot-interview/spring-mockito-mockmvc-testing)
- [Circular Dependencies in Spring and How to Fix Them](https://www.internhack.in/learn/interview/spring-boot-interview/spring-circular-dependencies)
- [Spring vs Spring Boot: What Problem Does Boot Solve?](https://www.internhack.in/learn/interview/spring-boot-interview/spring-vs-spring-boot)

## Related

- [Learn](https://www.internhack.in/learn)
- [Interview Prep](https://www.internhack.in/learn/interview)
- [Spring Boot](https://www.internhack.in/learn/interview/spring-boot-interview)
