Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
A comparison of the traditional implementation of the actuator and its enhancements in the latest spring framework 6.2 and Spring Boot 3.4, along with its usage.
Join the DZone community and get the full member experience.
Join For FreeIn Spring Boot, an Actuator is a framework module that provides features for managing and monitoring applications. It helps developers and operations teams to gain insights into the run-time behavior of their applications and provides capabilities for health checking, metrics collection, and application management via a set of built-in and customizable endpoints.
Traditional Implementation of Actuators
- Monitor health of the applications using endpoints like
/actuator/health
. - Provide application metrics such as memory usage and thread count using
/actuator/metrics
. - Endpoints like
/info
,/env
, and/beans
expose state of the application. - Developers had to integrate monitoring tools manually.
Example of traditional use:
management.endpoints.web.exposure.include=health,info
Accessing the health endpoint:
curl http://localhost:8080/actuator/health
Output:
{
"status": "UP"
}
Actuator Enhancements in Spring Framework 6.2 and Spring Boot 3.4
The latest updates to Spring Boot Actuator in Spring Boot 3.4 provide updated features and extended capabilities to monitor, manage, and troubleshoot Spring-based applications.
1. Expanded Endpoint Functionality
Additional endpoints are introduced to provide deeper insights into the health of the application and its runtime behavior.
/actuator/startup
– Displays application startup metrics and the detailed information about the initialization process./actuator/env/{name}
– This allows querying specific environment properties./actuator/containers
– When running in a Docker or Kubernetes environment, this endpoint monitors container-specific metrics.
Example:
management.endpoints.web.exposure.include=health,info,startup,env,containers
Accessing the /actuator/startup
endpoint:
curl http://localhost:8000/actuator/startup
Output:
{
"timeline": {
"events": [
{ "phase": "starting", "duration": 100 },
{ "phase": "environment prepared", "duration": 200 },
{ "phase": "context refreshed", "duration": 800 }
],
"totalTime": 1100
}
}
2. Structured Logging Support
The actuator now integrates with a structured logging framework to output the logs in machine-readable formats like JSON, which makes it easier to process logs in centralized logging systems.
Example of log integration for startup:
{
"timestamp": "2025-01-18T12:34:56.789Z",
"level": "INFO",
"message": "Application started",
"logger": "org.springframework.boot.actuate.endpoint.StartupEndpoint",
"data": {
"beansInitialized": 350,
"startupTime": "1200ms"
}
}
3. Improved Metrics and Observability
Integration with Prometheus and other metrics systems is updated to provide more granular application insights.
Example of adding dependencies for metrics and tracing:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk</artifactId>
</dependency>
Exposing the Prometheus metrics:
management.metrics.export.prometheus.enabled=true management.endpoints.web.exposure.include=prometheus
Accessing the Prometheus metrics:
curl http://localhost:8080/actuator/prometheus
Output (truncated):
# HELP jvm_memory_used_bytes The amount of used memory
jvm_memory_used_bytes{area="heap"} 12345678
jvm_memory_used_bytes{area="nonheap"} 9876543
4. Kubernetes Probes Integration
This ensures better orchestration and reliability of the application.
Example of a Kubernetes configuration:
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: 8080
initialDelaySeconds: 3
periodSeconds: 10
readinessProbe:
httpGet:
path: /actuator/health/readiness
port: 8080
initialDelaySeconds: 3
periodSeconds: 10
Accessing readiness probe:
curl http://localhost:8080/actuator/health/readiness
Output:
{
"status": "UP",
"components": {
"database": { "status": "UP" },
"diskSpace": { "status": "UP" }
}
}
5. Customizable Health Indicators
Developers can now define more granular health checks for specific components and services.
Example of a custom health indicator:
@Component
public class CustomHealthIndicator implements HealthIndicator {
@Override
public Health health() {
boolean healthy = checkExternalService();
return healthy ? Health.up().build() : Health.down().withDetail("Error", "Service unavailable").build();
}
private boolean checkExternalService() {
// Logic to check the status of an external service
return true;
}
}
Accessing the health endpoint:
curl http://localhost:8080/actuator/health
Output:
{
"status": "UP",
"components": {
"customHealthIndicator": {
"status": "UP"
}
}
}
6. Simplified Configuration For Cloud Environments
Enhanced support is now provided for managing Actuator configurations in cloud-native environments, including dynamically enabling or disabling the endpoints and integration of ConfigMaps and Secrets in Kubernetes.
Example of dynamic configuration:
apiVersion: v1
kind: ConfigMap
metadata:
name: actuator-config
namespace: default
labels:
app: spring-boot
annotations:
description: "Dynamic configuration for Spring Boot Actuator"
data:
management.endpoints.web.exposure.include: "health,info,metrics"
Reloading the configuration and access metrics:
curl http://localhost:8080/actuator/metrics
Output:
{
"names": [
"jvm.memory.used",
"http.server.requests"
]
}
Conclusion
The enhancements added in Spring Framework 6.2 and Spring Boot 3.4 significantly help in building observable and cloud-native applications that help developers and teams manage applications efficiently in production environments.
Opinions expressed by DZone contributors are their own.
Comments