Master Spring Boot Actuator: Monitoring, Metrics, and Management Endpoints
This guide explains how to add Spring Boot Actuator to a project, configure security, enable and customize monitoring endpoints, and use the built‑in REST APIs such as health, info, beans, metrics, and shutdown for production‑grade application observability.
Actuator Overview
In production systems you often need to monitor runtime metrics such as CPU, I/O, disk usage, database health, and custom business indicators. Spring Boot Actuator provides a set of HTTP endpoints that expose internal state information, health checks, metrics, and management operations.
Adding Actuator to a Spring Boot Project
Include the starter dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>Actuator brings in two additional modules: spring-boot-actuator (functionality) and spring-boot-actuator-autoconfigure (auto‑configuration).
For security, add spring-boot-starter-security and configure a username/password in application.yml (e.g., admin/admin). The tutorial disables security for simplicity.
Accessing Actuator Endpoints
After starting the application, the base URL http://localhost:8080/actuator returns a JSON document with links to all enabled endpoints, for example:
{
"_links": {
"self": {"href": "http://localhost:8080/actuator","templated": false},
"health": {"href": "http://localhost:8080/actuator/health","templated": false},
"info": {"href": "http://localhost:8080/actuator/info","templated": false}
}
}Common default endpoints include:
/actuator
/actuator/health
/actuator/info
/actuator/metrics
/actuator/beans
/actuator/env
/actuator/configprops
/actuator/mappings
/actuator/conditions
/actuator/heapdump
/actuator/logfile
/actuator/prometheus
You can enable additional endpoints by configuring management.endpoints.web.exposure.include in application.yml. Setting it to '*' exposes all endpoints; you can also list specific ones (e.g., beans,trace).
CORS Configuration
Cross‑origin requests are disabled by default. Enable them with:
management.endpoints.web.cors.allowed-origins: https://www.example.com
management.endpoints.web.cors.allowed-methods: GET,POSTREST Endpoint Details
Health
The /actuator/health endpoint reports the overall application status (UP, DOWN, etc.) and aggregates health indicators such as database connectivity, disk space, and external services. Example response: {"status":"UP"} You can control the order of status evaluation with setStatusOrder(...) and expose detailed health information by setting management.endpoint.health.show-details=always.
Info
The /actuator/info endpoint returns arbitrary key‑value pairs defined under the info prefix in application.yml or values extracted from the Maven POM using @project placeholders.
info:
app:
name: spring-boot-actuator
version: 1.0.0Beans
/actuator/beanslists all Spring beans in the application context, showing bean name, scope, type, resource location, and dependencies.
{
"contexts": {
"application": {
"beans": {
"endpointCachingOperationInvokerAdvisor": {
"scope": "singleton",
"type": "org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvokerAdvisor",
"resource": "class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.class]",
"dependencies": ["environment"]
}
}
}
}
}Config Props
/actuator/configpropsprovides a report of all @ConfigurationProperties beans and their bound values.
{
"spring.transaction-org.springframework.boot.autoconfigure.transaction.TransactionProperties": {
"prefix": "spring.transaction",
"properties": {}
}
}Environment
/actuator/envreturns all environment properties, including system variables, JVM properties, and command‑line arguments.
Metrics
/actuator/metricslists available metric names (e.g., jvm.memory.used, http.server.requests, process.cpu.usage) and can be queried for a specific metric value.
{
"names": ["jvm.memory.max","jvm.threads.states","http.server.requests",...]
}Key metric groups include system information, memory (heap, non‑heap), threads, classes, garbage collection, HTTP sessions, gauges, and counters.
Thread Dump
/actuator/threaddumpreturns a snapshot of all live threads, their states, stack traces, and lock information, useful for debugging concurrency issues.
{
"threads": [{
"threadName": "Reference Handler",
"threadId": 2,
"threadState": "RUNNABLE",
"stackTrace": [{...}]
}, ...]
}Shutdown
Enable graceful shutdown with management.endpoint.shutdown.enabled=true. Trigger it via a POST request: curl -X POST "http://localhost:8080/actuator/shutdown" Response:
{"message":"Shutting down, bye..."}Native Endpoint Categories
Application configuration endpoints (e.g., /conditions, /info) provide static reports about auto‑configuration and custom info.
Metrics endpoints (e.g., /metrics, /heapdump) deliver dynamic runtime snapshots such as memory usage and request statistics.
Operational control endpoints (e.g., /shutdown) allow actions like terminating the application.
Conclusion
The article covers the essential features of Spring Boot Actuator, showing how to add the dependency, secure the endpoints, expose additional endpoints, configure CORS, and use the most common REST endpoints for health checks, application info, bean inspection, configuration properties, environment details, metrics, thread dumps, and graceful shutdown.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Senior Brother's Insights
A public account focused on workplace, career growth, team management, and self-improvement. The author is the writer of books including 'SpringBoot Technology Insider' and 'Drools 8 Rule Engine: Core Technology and Practice'.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
