Spring Boot Actuator: Production-Ready Monitoring for Your Microservices
Spring Boot Actuator: Production-Ready Monitoring for Your Microservices
You’ve just deployed your Spring Boot application to production. The deployment went smoothly, but now you’re staring at a terminal, wondering: Is my app actually healthy? How many requests are being processed? Is memory usage about to spike? This is where Spring Boot Actuator comes to the rescue.
Spring Boot Actuator is a set of production-ready features that help you monitor and manage your application in any environment. It exposes operational information via HTTP endpoints and JMX MBeans, giving you deep visibility into your running application. In this post, we’ll explore how to set up, secure, and extend Actuator for real-world monitoring scenarios.
Getting Started with Actuator
To add Actuator to your Spring Boot project, include the following dependency:
1 | <dependency> |
For Gradle:
1 | implementation 'org.springframework.boot:spring-boot-starter-actuator' |
That’s it! By default, Actuator exposes several endpoints over HTTP. The most commonly used ones include:
/actuator/health- Application health information/actuator/info- Custom application information/actuator/metrics- Application metrics/actuator/env- Environment properties/actuator/beans- Spring beans in the context
Let’s start by accessing the health endpoint:
1 | curl http://localhost:8080/actuator/health |
You’ll get a simple response:
1 | {"status":"UP"} |
Configuring Actuator Endpoints
By default, only the /health and /info endpoints are exposed over HTTP. To expose more endpoints, configure them in application.yml:
1 | management: |
You can also expose all endpoints (not recommended for production):
1 | management: |
For fine-grained control, use exclude:
1 | management: |
Health Checks: Beyond UP/DOWN
The health endpoint is the most critical for production monitoring. By default, it aggregates health indicators from various components (database, disk space, etc.). You can customize it to include your own checks.
Custom Health Indicator
Let’s create a health indicator that checks if an external API is reachable:
1 | import org.springframework.boot.actuate.health.Health; |
Now when you hit /actuator/health, you’ll see detailed information:
1 | { |
Health Groups
You can group health indicators for specific audiences. For example, create a group for load balancers that only checks critical components:
1 | management: |
Now you can check:
1 | curl http://localhost:8080/actuator/health/liveness |
This is especially useful for Kubernetes liveness and readiness probes.
Metrics: The Pulse of Your Application
Actuator integrates with Micrometer to provide dimensional metrics. By default, it collects JVM metrics, system metrics, and more. Let’s explore some useful metrics.
Built-in Metrics
Access /actuator/metrics to see available metric names:
1 | { |
To view a specific metric, add its name:
1 | curl http://localhost:8080/actuator/metrics/jvm.memory.used |
Response:
1 | { |
Custom Metrics
You can record custom metrics using Micrometer’s MeterRegistry:
1 | import io.micrometer.core.instrument.MeterRegistry; |
Now you can query:
1 | curl http://localhost:8080/actuator/metrics/orders.created |
Info Endpoint: Your Application’s Identity Card
The /info endpoint exposes custom application information. Configure it in application.yml:
1 | info: |
With Maven resource filtering, the @...@ placeholders are replaced at build time. The response will look like:
1 | { |
Securing Actuator Endpoints
Exposing operational information to the world is dangerous. You must secure Actuator endpoints, especially in production.
Using Spring Security
If you have Spring Security on the classpath, Actuator endpoints are automatically secured. You can configure access rules:
1 | import org.springframework.context.annotation.Bean; |
Using Management Port
For better isolation, run Actuator on a separate port:
1 | management: |
Now Actuator is accessible at http://localhost:8081/internal/health. This allows you to firewall the management port separately from the main application port.
Custom Endpoints
Sometimes built-in endpoints aren’t enough. You can create custom endpoints for domain-specific operations.
Custom @Endpoint
Let’s create an endpoint that exposes cache statistics:
1 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; |
Now you can access GET /actuator/cache-stats.
Write Operations
You can also expose write operations:
1 |
|
This allows you to clear a cache by sending a POST to /actuator/cache-actions/myCache.
Integration with Monitoring Systems
Actuator metrics can be exported to popular monitoring systems. Here are two common setups.
Prometheus
Add the Micrometer Prometheus registry:
1 | <dependency> |
Expose the Prometheus endpoint:
1 | management: |
Now Prometheus can scrape metrics from /actuator/prometheus in the Prometheus text format.
Grafana
With Prometheus as a data source, you can create dashboards in Grafana. There are many pre-built dashboards for Spring Boot applications that visualize JVM metrics, request rates, and error percentages.
Production Best Practices
After implementing Actuator across multiple production systems, here are the practices I’ve found most valuable:
Always secure endpoints - Use Spring Security, management port, or network policies. Never expose sensitive endpoints to the internet.
Use health groups - Configure liveness and readiness probes for container orchestration platforms like Kubernetes.
Set up alerts - Monitor
healthstatus changes and key metrics likejvm.memory.usedandhttp.server.requests. Use tools like Prometheus Alertmanager or cloud monitoring services.Log access - Enable audit logging for Actuator endpoints to track who accessed what.
1
2
3
4
5
6
7
8management:
endpoints:
web:
exposure:
include: "*"
audit:
events:
enabled: trueLimit exposure in production - Only expose the endpoints you need. Start with
health,info,metrics, andprometheus. Add others as required.Monitor custom business metrics - Beyond system metrics, track domain-specific metrics like order rates, payment failures, or user registrations.
Version your endpoints - If you create custom endpoints, consider versioning them to avoid breaking changes.
Troubleshooting Common Issues
Endpoint Not Accessible
If you get a 404, check:
- The endpoint is exposed via
management.endpoints.web.exposure.include - The base path is correct (default
/actuator) - Security configuration isn’t blocking it
Health Status Always UP
If your custom health indicator isn’t affecting the overall status, ensure it’s properly registered as a Spring bean and implements HealthIndicator.
Metrics Not Appearing
For custom metrics, verify:
- The
MeterRegistryis injected correctly - The metric name is unique
- The metric is being recorded (e.g., counter incremented)
Key Takeaways
- Spring Boot Actuator provides production-ready monitoring with minimal configuration.
- Health indicators give deep insight into application and dependency health. Use custom indicators for external services.
- Metrics via Micrometer enable dimensional monitoring. Export to Prometheus and visualize in Grafana for powerful observability.
- Security is paramount — always secure Actuator endpoints using Spring Security, separate management ports, or network policies.
- Custom endpoints extend Actuator for domain-specific needs, but keep them focused and well-documented.
- Health groups simplify Kubernetes liveness and readiness probe configuration.
- Production best practices include limiting exposure, setting up alerts, and monitoring both system and business metrics.
By integrating Spring Boot Actuator into your deployment pipeline, you gain the visibility needed to operate confidently in production. Your application becomes not just a black box, but a transparent system that you can observe, diagnose, and optimize in real-time.