Spring Boot - spring-boot-starter-actuator

spring-boot-starter-actuator

spring-boot-starter-actuator is a module provided by Spring Boot to monitor and manage the runtime information of the application. It provides a set of built-in endpoints for obtaining application health status, performance metrics, configuration information, and more.
Through these endpoints, you can view and manage applications at runtime for troubleshooting, performance tuning, and configuration management.

Here is a code example showing how to use spring-boot-starter-actuator:

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootStarterActuatorApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringBootStarterActuatorApplication.class, args);
    }

}

The above code is the entry point for a simple Spring Boot application. Through the @SpringBootApplication annotation, it automatically enables Spring Boot's auto-configuration and component scanning features.

Next, some configuration needs to be added to enable the Actuator endpoint. In the application.properties or application.yml file, add the following configuration:

management.endpoints.web.exposure.include=*

The above configuration exposes all Actuator endpoints to web ports so that they can be accessed via HTTP requests.

Now, you can start the application and try to access the Actuator endpoint. Here are some commonly used Actuator endpoints:

/actuator/health: 返回应用程序的健康状态信息。http://localhost:8080/actuator/health
/actuator/info: 返回应用程序的自定义信息。http://localhost:8080/actuator/info
/actuator/metrics: 返回应用程序的各种指标,如内存使用、CPU 使用等。http://localhost:8080/actuator/metrics
/actuator/env: 返回应用程序的环境变量和配置属性。http://localhost:8080/actuator/env

These endpoints can be accessed using a browser or command line tools such as cURL or HTTPie, for example: http://localhost:8080/actuator

In addition, spring-boot-starter-actuator also provides some other functions, such as remote shell, audit log, configuration refresh, etc. It can be configured and used in the application as needed.

Note that in order to keep the application secure, it is strongly recommended to limit access to the Actuator endpoints in a production environment and expose only necessary endpoints.

Guess you like

Origin blog.csdn.net/qq_43116031/article/details/131116619