If your app is a ticking time bomb you can at least make the countdown less mysterious. This guide walks through adding Spring Boot Actuator to your Java service so you can see what is actually broken when the pager goes off. No fluff, some snark, and real steps for monitoring, metrics, and health checks with Micrometer and Prometheus.
Why use Actuator at all
Actuator gives you endpoints for health status, metrics, and other operational data for Spring Boot applications. That means fewer blind guesses during incidents and more evidence to blame the database or the intern who changed the config last week.
Add the Actuator dependency
Include the Spring Boot Actuator starter in your build. For Gradle use the implementation line and for Maven add the starter dependency. This is the tiny change that buys you a dashboard and less chaos.
Gradle example
implementation 'org.springframework.boot:spring-boot-starter-actuator'
Maven example
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Expose and configure endpoints
By default only a few actuator endpoints are visible. Use properties to control what you expose. Keep admin level surfaces off the public internet unless you enjoy surprises.
management.endpoints.web.exposure.include=health,info,metrics
management.endpoints.web.base-path=/actuator
If you want an extra safety layer run the management endpoints on a separate port. That gives firewalls and routing one more chance to save the day.
management.server.port=9090
Secure sensitive endpoints
Protect management endpoints with Spring Security or network isolation. Role based access control is the grown up way to avoid accidental prod surgery. If you leave health or metrics open you might get useful info but also an easy target for weird bots.
Metrics with Micrometer and Prometheus
Bring in a metrics registry and let Micrometer do the heavy lifting. Prometheus can scrape the app once you add the registry. That gives you time series data and the ability to graph the slow creeping death of one microservice.
implementation 'io.micrometer:micrometer-registry-prometheus'
With this in place the /actuator/metrics endpoint will report JVM, HTTP, and custom meters. Connect a long term storage and you can finally answer questions like why CPU spikes at 3am.
Custom health indicators
Sometimes the built in health checks are not enough. Make a small component that implements HealthIndicator to express your own checks. Keep it fast and deterministic so the health endpoint does not itself become a problem.
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
@Component
public class ExternalServiceHealth implements HealthIndicator {
@Override
public Health health() {
boolean ok = checkDependency();
if (ok) {
return Health.up().withDetail("externalService", "reachable").build();
}
return Health.down().withDetail("externalService", "unreachable").build();
}
private boolean checkDependency() {
// small network call or quick check
return true;
}
}
Querying endpoints and integrating with monitoring
Use curl for quick checks or let your monitoring system poll endpoints. Common endpoints are /actuator/health and /actuator/metrics. If you added the Prometheus registry point Prometheus to the metrics scrape path and let it collect data over time.
curl http://localhost:8080/actuator/health
curl http://localhost:8080/actuator/metrics
Operational tips you will thank yourself for later
- Run management endpoints on a separate port for extra safety and routing control.
- Use role based access for admin level actions and sensitive endpoints.
- Connect a Prometheus registry and a durable storage so metrics outlive process restarts.
- Keep custom health checks fast. A slow check makes the health endpoint useless when you need it most.
Wrap up
Spring Boot Actuator with Micrometer gives you a sane view into your application's health and behavior. Add the starter, expose only what you need, secure the admin surfaces, register a metrics registry, and write prudent custom health indicators. The result is fewer surprises during incidents and just enough pride when dashboards are green and the oncall phone stays quiet.