English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
SpringBoot ActuatorYes, it is a subproject of the Spring Boot framework. It includes many other features that can help us monitor and manage Spring Boot applications. It contains Actuator endpoints (the location of the resources). We can use HTTP and JMX Endpoint to manage and monitor Spring Boot applications. If you want to get production-ready features in your application, you should use S pring Boot Actuator.
Spring Boot Actuator has threeMain features:
Endpoints Metrics Audit
Endpoint: Actuator endpoints allow us to monitor and interact with the application. Spring Boot provides many built-in endpoints. We can also create our own endpoints. We can enable and disable each endpoint individually. Most applications choose HTTP , the endpoint ID and /actuator prefixmapped to URL.
For example, /health endpoints to provide basic health information of the application. By default, Actuator maps it to /actuator/health .
Metrics: Spring Boot Actuator integrates with MicrometerIntegrated to provide size metrics. Micrometer is integrated into Spring Boot. It is a tool library for supporting application metrics delivery from Spring. It is for applications with dimension data models Timers, gauges, counters, distribution summariesand Long task timerIt provides an interface that is independent of suppliers.
Audit: Spring Boot provides a flexible audit framework that publishes events to AuditEventRepository.If you are running spring-security, which will automatically publish authentication events.
We can enable Spring Boot Actuator by injecting dependencies into the pom.xml file spring-boot-starter-actuator to enable Actuator.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <version>2.2.2.RELEASE</version> </dependency>
Actuator endpoints allow us to monitor and interact with Spring Boot applications. Spring Boot includes many built-in endpoints, and we can also add custom endpoints to Spring Boot applications.
The following table describes widely used endpoints.
Id | Usage | Default |
Actuator | It provides a hypermedia-basedDiscovery pageIt requires Spring HATEOAS to be on the classpath. | true |
auditevents | It exposes the audit event information of the current application. | true |
autoconfig | It is used to display the auto-configuration report, which shows all candidates for auto-configuration and the reasons why they were "applied" or "not applied". | true |
beans | It is used to display the complete list of all Spring Beans in the application. | true |
configprops | It is used to display a neatly organized list of all @ConfigurationProperties. | true |
dump | It is used to perform thread dumps. | true |
env | It is used to expose properties from Spring's ConfigurableEnvironment. | true |
flyway | It is used to display all applied Flyway database migrations. | true |
health | It is used to display the status information of the application. | Error |
info | It is used to display arbitrary application information. | Error |
loggers | It is used to display and modify the configuration of the loggers in the application. | true |
liquibase | It is used to display all applied Liquibase database migrations. | true |
metrics | It is used to display the metric information of the current application. | true |
mappings | It is used to display a neatly organized list of all @RequestMapping paths. | true |
shutdown | It is used to allow a normal shutdown of the application. | true |
trace | It is used to display trace information. | true |
For Spring MVC, the following additional endpoints are used.
Id | Description | Default |
docs | It is used to display documents, including example requests and responses for Actuator endpoints. | Error |
heapdump | It is used to return GZip-compressed heap dump files. | true |
jolokia | It is used to expose JMX beans over HTTP (when Jolokia is on the classpath). | true |
logfile | It is used to return the content of the log file. | true |
micrometer | It is used to expose metrics in a format that Prometheus server can scrape. It requires the dependency of Micrometer.-Prometheus. | true |
Spring Boot provides security for all Actuator endpoints. It uses form-basedauthentication, based on user ID and authentication, which provides password. We can also access restricted Actuator endpoints by customizing basic authentication security for endpoints. We need to provide a password as a user, and offer a randomly generated management.security.roles Property overrides this configuration. For example:
management.security.enabled=true management.security.roles=ADMIN security.basic.enabled=true security.user.name=admin security.user.password=admin
Let's understand the concept of Actuator through an example.
Steps1: Open Spring Initializr https://start.spring.io/and create Maven project.
Steps2: provide groupname. We provide com.w3codebox.
Steps3: provide artifacts ID. We provide spring-boot-actuator-example.
Steps4: . Add the following dependencies: Spring Web, Spring Boot Starter Actuatorand Spring Data Rest HAL browser.
Steps5: click Generatebutton. When we click the "Generate" button, it will package all the specifications related to the project into Jar file, and download it to our local system.
Steps6: Extract the Jar file and paste it into the STS workspace.
Steps7: Import the project folder.
file->Import->Existing Maven project->Browse->Select folder spring-boot-actuator-example- >Complete
Importing may take some time. After importing the project, we can see the project directory in the "Package Explorer" section.
Steps8: : Create a Controller class. We have created a controller class named DemoRestController.
DemoRestController.java
package com.w3codebox; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class DemoRestController { @GetMapping("/hello public String hello() { return "Hello User!"; } }
Steps9: open application.properties file, and add the following statement to disable the security feature of Actuator.
application.properties
management.security.enabled=false
Steps10: Run SpringBootActuatorExampleApplication.java File.
Steps11: Open a browser and call the URL http: //localhost: 8080/actuator. It returns the following page:
{"_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}}}
By default, the application runs on port8080 after the Actuator starts, we can see the list of all endpoints exposed via HTTP.
Let's call the URL http: //localhost: 8080/to call health Endpoints. Actuator/Health status. It indicates the status UP . This indicates that the application is running normally and is functioning properly.
Similarly, we can call other endpoints to help us monitor and manage Spring Boot applications.