Below is a concise cheat sheet for Spring Boot Actuator. It covers the most commonly used features and configurations for quickly getting started, observing, and monitoring a Spring Boot application.
1. Adding Actuator to Your Project
-
Maven
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
-
Gradle
dependencies { implementation 'org.springframework.boot:spring-boot-starter-actuator' }
2. Default Actuator Endpoints
Endpoint | Description | Default Path |
---|---|---|
|
Displays arbitrary application info (e.g., version,
description). Customizable in |
|
|
Shows application health status. Summaries from multiple health indicators. |
|
|
Shows metrics and counters such as memory usage, CPU usage, JVM stats, etc. |
|
|
Details on a particular metric (e.g.,
|
|
|
Exposes metrics in Prometheus format. |
|
|
Shows Spring Environment properties (active profiles, property sources). |
|
|
Shows detail for a specific property in the Spring Environment. |
|
|
Displays all beans in the ApplicationContext. |
|
|
Shows auto-configuration evaluation report. |
|
|
Shows configuration properties (prefix, default values, etc.). |
|
|
Performs a thread dump. |
|
|
Returns a heap dump file. |
|
|
Displays and modifies log levels at runtime. |
|
|
Gracefully shuts down the application. |
|
|
Displays HTTP trace information (recent request/response exchanges). |
|
Note: By default, all endpoints are exposed on the base path
/actuator
.
3. Key Configuration Properties
Configure Actuator endpoints in application.properties
or
application.yml
:
Property | Description | Example |
---|---|---|
|
Exposes specific endpoints over HTTP. |
|
|
Excludes specific endpoints from HTTP exposure. |
|
|
Sets health info detail
level ( |
|
|
Roles that can see full health
details ( |
|
|
Dedicated management HTTP port. |
|
|
Binds the management server to a specific network address. |
|
|
Changes the base path from |
|
|
Enables/disables the shutdown endpoint. |
|
|
Defines the items to include in HTTP trace. |
|
4. Security Considerations
-
In Spring Boot 2+, Actuator endpoints require secure access by default (if you have Spring Security on the classpath).
-
If using Spring Security, you can configure in
SecurityConfig
(Java config) orapplication.properties
.
Example (Basic Authentication in application.properties
):
spring.security.user.name=admin
spring.security.user.password=secret
Example (Granular Security with Java Config):
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/actuator/health").permitAll() // Publicly accessible
.antMatchers("/actuator/**").hasRole("ADMIN") // Admin only
.anyRequest().authenticated()
.and()
.httpBasic();
}
}
5. Customizing Actuator Health Indicators
-
Health indicators are beans that implement
HealthIndicator
. -
Add a custom health indicator by creating a class that implements
HealthIndicator
:
@Component
public class MyCustomHealthIndicator implements HealthIndicator {
@Override
public Health health() {
// Your logic to check health
boolean healthy = checkYourService();
if (healthy) {
return Health.up().withDetail("myService", "Available").build();
} else {
return Health.down().withDetail("myService", "Unavailable").build();
}
}
}
6. Viewing and Adding Metrics
-
Default Metrics: Memory usage, CPU usage, GC stats, system uptime, etc.
-
HTTP Request Metrics: Exposed at
http.server.requests
(including status codes, timings). -
Database Metrics (if using Spring Data): Connection pool metrics, etc.
Custom Metrics with Micrometer
-
Add Micrometer (usually included by default in newer Spring Boot apps).
-
Use
@Timed
,@Counted
, orMeterRegistry
:@RestController public class MyController { // Option 1: Annotation-based @Timed(value = "my.controller.timer", description = "Time spent in MyController") @GetMapping("/hello") public String hello() { return "Hello, World!"; } // Option 2: Programmatic @Autowired MeterRegistry meterRegistry; @GetMapping("/goodbye") public String goodbye() { Counter counter = meterRegistry.counter("my.controller.counter"); counter.increment(); return "Goodbye, World!"; } }
7. Exposing Actuator over HTTPS or a Separate Port
-
You can isolate Actuator endpoints from the main application endpoints:
server.port=8080 management.server.port=9001
-
(Optional) Enable HTTPS for management endpoints if your main application doesn’t use HTTPS:
management.server.ssl.enabled=true management.server.ssl.key-store=classpath:keystore.jks management.server.ssl.key-store-password=password management.server.ssl.key-password=password
8. Tips & Best Practices
-
Secure Sensitive Endpoints
Always secure or restrict access to sensitive endpoints likeshutdown
,threaddump
, orheapdump
. -
Limit Exposures in Production
By default, onlyhealth
andinfo
might be exposed. Expose additional endpoints only if needed. -
Use Custom Health Indicators
Write your ownHealthIndicator
orReactiveHealthIndicator
for key dependencies (databases, caches, message brokers). -
Integration with Monitoring Tools
Combine Actuator with Micrometer to export metrics to tools like Prometheus, Graphite, or New Relic. -
Version Control of
info
Include version info fromgit.properties
orMANIFEST.MF
so you can easily see what version is running. -
Leverage
@Endpoint
for Custom Requirements
Create entirely new endpoints by using the@Endpoint
or@WebEndpoint
annotation.
Quick Reference: Common Properties
# Include only selected endpoints
management.endpoints.web.exposure.include=health,info,metrics
# Exclude certain endpoints
management.endpoints.web.exposure.exclude=env
# Turn on/off the shutdown endpoint
management.endpoint.shutdown.enabled=true
# Return full health details to authorized roles only
management.endpoint.health.show-details=when_authorized
management.endpoint.health.roles=ADMIN,ACTUATOR
# Change base path
management.server.base-path=/management
# Run management on a separate port
management.server.port=9001