Spring Boot Actuator
An actuator is a spring boot sub-project that helps to expose production-ready support features against Spring boot application.
Join the DZone community and get the full member experience.
Join For FreeKey Features Offered by an Actuator
- Health check: You can use a health endpoint to check the status of your running application.
- Monitoring and Management over HTTP/JMX: Actuator support HTTP endpoint as well as Java Management Extensions (JMX) to provide a standard mechanism to monitor and manage applications.
- Logger: It provides a feature to view and update the logs level.
- Metrics: Spring Boot Actuator provides dependency management and auto-configuration for Micrometer, an application metrics facade that supports numerous monitoring systems.
- Auditing: Once Spring Security is in play, Spring Boot Actuator has a flexible audit framework that publishes events (by default, “authentication success”, “failure” and “access denied” exceptions). This feature can be very useful for reporting and for implementing a lock-out policy based on authentication failures.
- Http Tracing: HTTP Tracing can be enabled by providing a bean of type
HttpTraceRepository
in your application’s configuration. For convenience, Spring Boot offers anInMemoryHttpTraceRepository
that store traces for the last 100 request-response exchanges - Process Monitoring
Enable Actuator Into Spring Boot Project
You can enable Actuator into Spring boot project by including below dependency.
//Gradle
org.springframework.boot:spring-boot-starter-actuator:2.3.1.RELEASE
//Maven
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.3.1.RELEASE</version>
</dependency>
Endpoint Offer by Actuator
By default ‘health’ and ‘info’ endpoint is enabled
Other endpoints are sensitive and not advisable to expose to the production environment without security. As we are demonstrating, let’s expose all the APIs.
management.endpoints.web.exposure.include=*
Include and Exclude Endpoint.
Even you can include or exclude endpoint by defining below properties
# wild card to include/exclude all
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=*
# you can include specific properties like below
management.endpoints.web.exposure.include=env,beans
management.endpoints.web.exposure.exclude=heapdump
Customize Management Server Address
You can customize the management server port, it will help you define the limited scope to the ports.
management.server.port=8081
management.server.address=127.0.0.1
Expose Custom Endpoint
Any methods annotated with @ReadOperation
, @WriteOperation
, or @DeleteOperation
are automatically exposed over JMX and HTTP. Even you can expose technology-specific endpoint by using @JmxEndpoint
or @WebEndpoint
.
Here I’m sharing you example for exposing endpoint using Spring boot 2.x
xxxxxxxxxx
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.stereotype.Component;
springframework.boot.actuate.endpoint.annotation.Endpoint(id = "say-hello") .
public class Endpoint {
public String sayHello()
{
return "Hello World";
}
}
Summary: Spring boot actuator is one of the best libraries you can add in your application to enable production-ready features in less effort. it offers key features that can be used in day to day production support.
Opinions expressed by DZone contributors are their own.
Trending
-
WireMock: The Ridiculously Easy Way (For Spring Microservices)
-
Using OpenAI Embeddings Search With SingleStoreDB
-
Designing a New Framework for Ephemeral Resources
-
A Data-Driven Approach to Application Modernization
Comments