What is Spring Actuator?
Spring Boot Actuator is available from the very first release of Spring Boot.
It proves several features like health check-up, auditing JVM metrics,
log information, caching statics, etc. We have the option to use JMX or
HTTP end points to manage and monitor our applications on the production
environment.
Actuator also make it easy to integrate with external monitoring systems like Prometheus, Graphite, DataDog, New Relic, etc. The Actuator uses for Micrometer,
an application metrics facade to support the integration with external
monitoring systems.Actuator make it super easy to integrate our
application with any external system with a very minimal configurations.
Enabling
If we use Sprng Initializer we have to add Spring Web Starter and Spring Boot Actuator starter.
On pom.xml you will be able to see it:
dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Verifying
Spring boot actuator creates and expose the end points. Actuator end
points allow us to monitor and interact with our application. Spring
Boot 2 provides the option to expose these end points as JMX or HTTP
end points. These different end points provide specific information /
status for our application, let’s briefly cover a few of these endpoints.
Once you start your application you will be able to see if it is working using the following endpoint:
https://localhost:8080//actuator
{
"_links": {
"self": {
"href": "http://localhost:8080/actuator",
"templated": false
},
"health": {
"href": "http://localhost:8080/actuator/health",
"templated": false
},
"health-path": {
"href": "http://localhost:8080/actuator/health/{*path}",
"templated": true
},
"info": {
"href": "http://localhost:8080/actuator/info",
"templated": false
}
}
}
To enable all endpoints you need to change your application.properties:
management.endpoints.web.exposure.include=*
The most basic actuator is the health endpoint which provides basic application health information.
http://localhost:8080/actuator/health
{
"status": "UP"
}
The healthendpoint will show status as DOWNif there is any issue within the application like database connection or lower disk space etc.
The info endpoint display general information from the standard files like META-INF/build-info.properties.Initially this will be empty but you can add information to your application.properties to be shown here.
## Configuring info endpoint
info.app.name=Spring Sample Application
info.app.description=This is my first spring boot application
info.app.version=1.0.0
{
"app": {
"name": "Spring Sample Application",
"description": "This is my first spring boot application",
"version": "1.0.0"
}
}
Spring Boot Actuator Endpoints
There are several endpoints that can be enable on your application. There are also some additional endpoints available for Spring MVC, Spring WebFlux, or Jersey.
Enable/Disable Actuator Endpoints
Spring boot actuator make it easy to enable or disable any end point
using the application. properties file. To enable an endpoint, use the management.endpoint.<id>.enabled
property in the application.properties
file.
To enable beans endpoint:
management.endpoint.beans.enabled=true
To include/exclude endpoints over HTTP we should configure the properties through the application.properties.
management.endpoints.web.exposure.include=health,info
management.endpoints.web.exposure.exclude=
To expose all endpoints:
management.endpoints.web.exposure.include=*
It is not recommended to expose all endpoints for security reasons.
When you start your application you can actually see those endpoint your have started like this:
Exposing 13 endpoint(s) beneath base path '/actuator'
/metrics Endpoint
The metrics endpoint publishes information about the current application which includes OS, JVM information, memory and heap information, thread pool, etc.
With '/actuator/metrics' you will see which metrics are available like: "http.server.requests", "jvm.buffer.count", "jvm.buffer.memory.used", "jvm.buffer.total.capacity", ...
With 'actuator/metrics/'metric_name you can see details of each metric.
Ex. http://localhost:8080/actuator/metrics/http.server.requests
{
"name": "http.server.requests",
"description": null,
"baseUnit": "seconds",
"measurements": [{
"statistic": "COUNT",
"value": 2.0
}, {
"statistic": "TOTAL_TIME",
"value": 0.0518762
}, {
"statistic": "MAX",
"value": 0.0
}],
"availableTags": [{
"tag": "exception",
"values": ["None"]
}, {
"tag": "method",
"values": ["GET"]
}, {
"tag": "uri",
"values": ["/actuator", "/actuator/metrics"]
}, {
"tag": "outcome",
"values": ["SUCCESS"]
}, {
"tag": "status",
"values": ["200"]
}]
}
/health Endpoint
The /health endpoint is to check the health or state of the running application. By default this endpoint only display a simple status of the application like up
or DOWN
. To display details you need to add the following property in the application.properties file.
management.endpoint.health.show-details=always
This will show the so called Health Indicators. On properties file you can enable or disable each individually. Some contain information like your disk space, if you database is running and if you can ping your site.
/loggers Endpoint
To check the list of all configured logger for our application, we can use the http://localhost:8080/actuator/loggers endpoint.This endpoint display all the logger and configured log levels for your application and all libraries included.
It also provides the option to check the details for the individual logger.Use the URL http://localhost:8080/actuator/loggers/{name} where {name}
is the name of the logger.To check the details for the {com.javdevjournal}
logger, use the http://localhost:8080/actuator/loggers/com.javadevjournal.