SpringCloud Study Notes 03 - Integrating Spring Boot Actuator


1. What is Spring Boot Actuator?

Provide monitoring function, you can monitor many endpoints. These monitoring endpoints can be accessed in the form of http://{ip}:{port}/{endpoint} to understand the running status of the application. The following figure shows the commonly used endpoints and descriptions of Spring Boot Actuator:

insert image description here

2. Integration steps

以项目user微服务为例

add dependencies

as follows:

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

Integrating Actuator only needs to introduce dependencies. Similarly, Actuator can also be integrated for movie microservices


3. Test

/health endpoint

Access http://localhost:8060/health
and report error 404. After checking the startup log, it is found that Exposing 1 endpoint(s) beneath base path '/actuator' is printed out
. The default url prefix of endpoints needs to be added to access,
so the access address is http:// localhost:8060/actuator/health, if 404 is still reported, you need to check whether the project is configured with context-path

The test results are shown in the figure:
insert image description here

说明:UP代表运行正常,除UP外,还有DOWN、OUT_OF_SERVICE、UNKNOWN等状态。上图只显示了一个概要
情况,如需展示详情,需要设置management.endpoint.health.show-details=always(默认never,
还有when-authorized)或者show-components,如果show-components 没有指定 则用show-details的
值进行展示,否则以show-components的配置为准

The following figure shows the test results with management.endpoint.health.show-details=always added:
insert image description here
Summary: The essence of /health, by checking the resources of the spring boot application to determine whether the application is normal.

/info endpoint

Visit http://localhost:8060/actuator/info and report 404
to check the exposed endpoint, visit http://localhost:8060/actuator, and find the exposed endpoint as shown below:

insert image description here

说明:端点未暴露时,可以通过修改配置management.endpoints.web.exposure.include的值来调整要
暴露的端点,"*"为全部暴露

After modifying the configuration, visit http://localhost:8060/actuator/info, and the return is {}. At this time, the info endpoint does not return any data. After modifying management.info.java.enabled=true (displaying Java runtime information), visit as follows Graphic:
insert image description here

Since there are many Actuator endpoints, this article will not go into details here. Interested partners can refer to the official documents for further study:
https://docs.spring.io/spring-boot/docs/2.7.1/reference/htmlsingle/

Guess you like

Origin blog.csdn.net/Shiny_boy_/article/details/126116805