DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • How Spring Boot Starters Integrate With Your Project
  • A Practical Guide to Creating a Spring Modulith Project
  • Structured Logging in Spring Boot 3.4 for Improved Logs

Trending

  • Apache Doris vs Elasticsearch: An In-Depth Comparative Analysis
  • Solid Testing Strategies for Salesforce Releases
  • Simplify Authorization in Ruby on Rails With the Power of Pundit Gem
  • Chaos Engineering for Microservices
  1. DZone
  2. Coding
  3. Frameworks
  4. Introduction to the Spring Boot Actuator

Introduction to the Spring Boot Actuator

Learn more about the Spring Boot Actuator!

By 
James Warner user avatar
James Warner
·
Nov. 12, 19 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
27.4K Views

Join the DZone community and get the full member experience.

Join For Free

Spring Boot actuator

Learn more about the Spring Boot Actuator!

The Spring Boot Actuator provides production-ready features for our Spring Boot application. Additionally, this library provides all endpoints for production — without having to write a single line of code just by adding the proper dependency.

You may also like: Magic With the Spring Boot Actuator

The Spring Boot Actuator mainly exposes endpoints like health, metrics, logger, info, thread dump, and more. Let's take a closer look!

Dependencies

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-actuator</artifactId>

</dependency>


Endpoints Provided by the Spring Boot Actuator

  1.  /auditevents — lists security audit-related events such as user login/logout. Also, we can use this to filter by principal or type among other fields.

  2.  /beans — returns all available beans in our BeanFactory. Unlike /auditevents, it doesn't support filtering.

  3.   /conditions — formerly known as  /autoconfig, this endpoint builds a report of conditions around auto-configuration.

  4.  /configprops — allows us to fetch all @ConfigurationProperties beans.

  5.  /env — returns the current environment properties. Additionally, we can retrieve single properties.

  6.  /flyway — provides details about our Flyway database migrations.

  7.  /health – summarizes the health status of our application.

  8.  /heapdump — builds and returns a heap dump from the JVM used by our application.

  9.  /info — returns general information. It might be custom data, build information, or details about the latest commit.

  10.  /liquibase — behaves like /flyway, but for Liquibase.

  11.  /logfile — returns ordinary Java application logs.

  12.  /loggers — enables us to query and modify the logging level of our application.

  13.  /metrics — details the metrics of our application. This might include generic metrics as well as custom ones.

  14.  /prometheus — returns metrics like the previous one, but formatted to work with a Prometheus server.

  15.  /scheduledtasks — provides details about every scheduled task within our application.

  16.  /sessions — lists HTTP sessions, given we are using Spring Session.

  17.  /shutdown — performs a graceful shutdown of the application.

  18.  /threaddump — dumps the thread information of the underlying JVM.

By default, all of these endpoints are exposed as REST APIs and as JMX endpoints. Spring Boot provides a set of properties for controlling the endpoints available to REST APIs and also for JMX.

management.endpoints.jmx.exposure.include and management.endpoints.jmx.exposure.exclude  are two properties for controlling the exposed endpoints for JMX.

 management.endpoints.web.exposure.exclude and  management.endpoints.web.exposure.include are two properties for controlling the exposed endpoints for the REST API.

Configuring Endpoints

By default, for performance, all of the actuator's endpoints responses are cached for reading operations, which do not take any parameters. We can also set cache time using property below:

management.endpoint.beans.cache 

Instead, we can also set time-to-live at each endpoint level, like so: 

management.endpoint.loggers.cache

CORS Support

The Spring Boot Actuator provides a set of properties for allowing requests from a specified host. It also provides the type of request methods to support methods from remote hosts:

management.endpoints.web.cors.://example.com 

management.endpoints.web.cors.,POST 

Implementing Custom Endpoints

The Spring Boot Actuator provides the @Endpoint annotation to specify the endpoint.

By default, this endpoint is allowed for both HTTP and JMX.

The @Endpoint-annotated class will have  @ReadOperation,  @WriteOperation, and  @DeleteOperation. These annotated methods will provide a new endpoint for all of these endpoints.

@Selector is an annotation to mark the method argument as part of the request URI.

If we cleanly observe the HealthEndpoint class, it is annotated with @Endpoint, and it has one of the methods annotated with @ReadOperation.

@ReadOperation

public Health healthForComponentInstance(@Selector String component, @Selector String instance) {

….

}


In the above code, method, component, and instance are annotated with @Selector, and a result of the REST API syntax is:

http://localhost:8080/actuator/health/{component}/{instance}

If we want to restrict endpoints to web or JMX, we can use @JMXEnpoint or  @WebEndpoint; these endpoints are restricted to only specified technology.

@EndpointExtension is used as meta-annotation for @Endpoint to indicate the extension support for an endpoint. These extensions support filters where these endpoints need to execute.

@EndpointWebExtensionand @EndpointJmxExtension are two annotation extensions for a specific technology.

Customizing the Management Server Port

By default, management endpoints will use the HTTP protocol, but it is sensible for choice for cloud-based deployments.

The Spring Boot Actuator provides configuration property to expose management endpoints in a different port:

management.server

It also provides the configuration for enabling SSL for management endpoints.

Customizing the Management Server Address

management.server.address is the property used to specify the list of addresses from where we want to listen.

If we want to listen to management requests only from the localhost, then specify the property value as 127.0.0.1. For this to work, the management endpoint must be configured to a different port from the HTTP port.

Disabling HTTP Endpoints

We can disable the management endpoint in two ways:

  1. We can set management.server.port to -1

  2. management.endpoints.web.exposure.exclude and  management.endpoints.jmx.exposure.exclude set these two properties to *  to exclude all properties.

Conclusion

Today, we learned more about the Spring Boot Actuator, endpoints provided by the Actuator, its use cases, and how to customize the Spring Boot Actuator.

Further Reading

Spring Boot Actuator: A Complete Guide

Spring Boot Actuator in Spring Boot 2.0

Magic With the Spring Boot Actuator

Spring Framework Spring Boot

Opinions expressed by DZone contributors are their own.

Related

  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • How Spring Boot Starters Integrate With Your Project
  • A Practical Guide to Creating a Spring Modulith Project
  • Structured Logging in Spring Boot 3.4 for Improved Logs

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: