Skip to main content

Quiz: Spring Boot Actuator

Test your knowledge on Actuator, metrics, and monitoring.

30 questions - Click on each question to reveal the answer.


Questions 1-15: Actuator Basics​

Question 1: What is Spring Boot Actuator?

Answer: Actuator provides endpoints to monitor and manage a Spring Boot application in production:

  • Application health
  • Metrics
  • Environment information
  • Log management
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Question 2: How to expose all Actuator endpoints?

Answer:

management:
endpoints:
web:
exposure:
include: "*"

By default, only /health and /info are exposed.


Question 3: What are the main Actuator endpoints?

Answer:

EndpointDescription
/actuator/healthApplication health
/actuator/infoCustom information
/actuator/metricsMetrics
/actuator/envEnvironment properties
/actuator/loggersLog levels
/actuator/beansSpring Beans
/actuator/mappingsHTTP routes
/actuator/threaddumpActive threads
/actuator/heapdumpMemory dump

Question 4: How to configure the health endpoint?

Answer:

management:
endpoint:
health:
show-details: always # never, when-authorized, always
show-components: always
health:
db:
enabled: true
diskspace:
enabled: true
threshold: 10MB

Question 5: How to create a custom Health Indicator?

Answer:

@Component
public class ExternalApiHealthIndicator implements HealthIndicator {

private final ExternalApiClient apiClient;

@Override
public Health health() {
try {
boolean isUp = apiClient.ping();
if (isUp) {
return Health.up()
.withDetail("api", "Available")
.withDetail("responseTime", "50ms")
.build();
}
return Health.down()
.withDetail("api", "Unavailable")
.build();
} catch (Exception e) {
return Health.down(e).build();
}
}
}

Question 6: How to add information to /actuator/info?

Answer:

# application.yml
info:
app:
name: My Application
version: 1.0.0
description: REST API
contact:
email: support@example.com

Or with an InfoContributor:

@Component
public class CustomInfoContributor implements InfoContributor {

@Override
public void contribute(Info.Builder builder) {
builder.withDetail("uptime", getUptime());
builder.withDetail("activeUsers", getActiveUsers());
}
}

Question 7: How to secure Actuator endpoints?

Answer:

@Configuration
public class SecurityConfig {

@Bean
public SecurityFilterChain actuatorSecurity(HttpSecurity http) throws Exception {
http.securityMatcher("/actuator/**")
.authorizeHttpRequests(auth -> auth
.requestMatchers("/actuator/health").permitAll()
.requestMatchers("/actuator/**").hasRole("ADMIN")
)
.httpBasic(Customizer.withDefaults());

return http.build();
}
}

Question 8: How to change the base path of Actuator?

Answer:

management:
endpoints:
web:
base-path: /manage # /manage/health instead of /actuator/health

Question 9: How to disable a specific endpoint?

Answer:

management:
endpoint:
env:
enabled: false
beans:
enabled: false

Question 10: How to expose Actuator on a different port?

Answer:

management:
server:
port: 9090 # Actuator on port 9090
address: 127.0.0.1 # Accessible only locally

Question 11: How to change log levels on the fly?

Answer:

# View loggers
curl http://localhost:8080/actuator/loggers

# Change a level
curl -X POST http://localhost:8080/actuator/loggers/com.example \
-H "Content-Type: application/json" \
-d '{"configuredLevel": "DEBUG"}'

Question 12: How to obtain a thread dump?

Answer:

curl http://localhost:8080/actuator/threaddump

Useful for diagnosing:

  • Deadlocks
  • Blocked threads
  • Performance issues

Question 13: How to obtain a heap dump?

Answer:

curl -o heapdump.hprof http://localhost:8080/actuator/heapdump

Analyze with:

  • Eclipse MAT
  • VisualVM
  • JProfiler

Question 14: What is the /actuator/env endpoint?

Answer: Displays all environment properties:

  • System variables
  • Environment variables
  • application.yml properties
  • Active profiles
curl http://localhost:8080/actuator/env/spring.datasource.url

Warning: may expose secrets!


Question 15: How to hide sensitive properties?

Answer:

management:
endpoint:
env:
keys-to-sanitize:
- password
- secret
- key
- token
- credential

Values are replaced by ******.


Questions 16-30: Metrics and Monitoring​

Question 16: What is Micrometer?

Answer: Micrometer is a metrics facade (like SLF4J for logging) that allows publishing metrics to different systems:

  • Prometheus
  • Datadog
  • InfluxDB
  • CloudWatch

Spring Boot Actuator uses it by default.


Question 17: How to access metrics?

Answer:

# List of metrics
curl http://localhost:8080/actuator/metrics

# Specific metric
curl http://localhost:8080/actuator/metrics/jvm.memory.used

# With tags
curl http://localhost:8080/actuator/metrics/http.server.requests?tag=uri:/api/users

Question 18: What metrics are available by default?

Answer:

CategoryExamples
JVMjvm.memory.used, jvm.gc.pause
HTTPhttp.server.requests
Tomcattomcat.sessions.active
DataSourcehikaricp.connections.active
Cachecache.gets, cache.puts
Systemsystem.cpu.usage, disk.free

Question 19: How to create a custom Counter metric?

Answer:

@Service
public class OrderService {

private final Counter ordersCounter;

public OrderService(MeterRegistry registry) {
this.ordersCounter = Counter.builder("orders.created")
.description("Number of orders created")
.tag("type", "online")
.register(registry);
}

public Order createOrder(OrderRequest request) {
Order order = processOrder(request);
ordersCounter.increment();
return order;
}
}

Question 20: How to create a Timer metric?

Answer:

@Service
public class PaymentService {

private final Timer paymentTimer;

public PaymentService(MeterRegistry registry) {
this.paymentTimer = Timer.builder("payment.processing")
.description("Payment processing time")
.register(registry);
}

public Payment process(PaymentRequest request) {
return paymentTimer.record(() -> {
// Processing
return doProcess(request);
});
}
}

Question 21: How to create a Gauge metric?

Answer:

@Component
public class QueueMetrics {

private final BlockingQueue<Task> queue;

public QueueMetrics(MeterRegistry registry, BlockingQueue<Task> queue) {
this.queue = queue;

Gauge.builder("queue.size", queue, BlockingQueue::size)
.description("Current queue size")
.register(registry);
}
}

Question 22: How to use @Timed to measure methods?

Answer:

@Configuration
public class MetricsConfig {
@Bean
public TimedAspect timedAspect(MeterRegistry registry) {
return new TimedAspect(registry);
}
}

@Service
public class UserService {

@Timed(value = "user.find", description = "Time to find user")
public User findById(Long id) {
return userRepository.findById(id).orElseThrow();
}
}

Question 23: How to configure Prometheus?

Answer:

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
management:
endpoints:
web:
exposure:
include: prometheus

Access: /actuator/prometheus


Question 24: How to configure Prometheus to scrape metrics?

Answer:

# prometheus.yml
scrape_configs:
- job_name: 'spring-boot'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['app:8080']

Question 25: How to visualize metrics in Grafana?

Answer:

  1. Configure Prometheus as a data source
  2. Import a Spring Boot dashboard (ID: 12900)
  3. Or create custom panels:
# HTTP requests per second
rate(http_server_requests_seconds_count[5m])

# Average response time
rate(http_server_requests_seconds_sum[5m]) / rate(http_server_requests_seconds_count[5m])

# Memory usage
jvm_memory_used_bytes{area="heap"}

Question 26: How to add global tags to metrics?

Answer:

@Configuration
public class MetricsConfig {

@Bean
public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
return registry -> registry.config()
.commonTags("application", "my-app")
.commonTags("environment", "production");
}
}

Question 27: How to measure startup time?

Answer:

@Component
public class StartupMetrics implements ApplicationListener<ApplicationReadyEvent> {

@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
long startupTime = System.currentTimeMillis()
- event.getTimestamp().toEpochMilli();
log.info("Application started in {} ms", startupTime);
}
}

Also available via Actuator: /actuator/startup


Question 28: How to implement alerts on metrics?

Answer: In Prometheus/Alertmanager:

# alerts.yml
groups:
- name: spring-boot
rules:
- alert: HighErrorRate
expr: rate(http_server_requests_seconds_count{status="500"}[5m]) > 0.1
for: 5m
labels:
severity: critical
annotations:
summary: "High error rate detected"

Question 29: How to monitor database connections?

Answer: Automatic HikariCP metrics:

# Active connections
curl .../actuator/metrics/hikaricp.connections.active

# Pending connections
curl .../actuator/metrics/hikaricp.connections.pending

# Acquisition time
curl .../actuator/metrics/hikaricp.connections.acquire

Question 30: What are the best practices for monitoring?

Answer:

  1. Monitor the 4 key signals (RED): Rate, Errors, Duration
  2. Set up relevant alerts
  3. Use dashboards
  4. Centralize logs and metrics
  5. Monitor dependencies (DB, cache, external APIs)
  6. Health checks for the load balancer
  7. Distributed tracing for microservices
  8. Automate runbooks

Score​

ScoreLevel
27-30Excellent - Actuator mastered
21-26Good - Some revisions needed
15-20Average - Review the chapters
Less than 15Needs improvement

Back to Module 11