【SpringBoot/Actuator】给SpringBoot程序添加Actuator监控管理

注意:本例针对SpringBoot v2.5.4版本写成,不保证在其它版本的效果。

例程:

 https://files.cnblogs.com/files/heyang78/redisCache_actuator_210925.rar

 

给应用程序添加Actuator的支持不难,只要遵循以下步骤:

1.在pom.xml中添加对Actuator的支持

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

 

2.在appication.yml中开启Actuator端点

#application.yml
server:
    servlet: 
        context-path: /myapp
management: 
    endpoints: 
        web: 
            exposure: 
                include: '*'
spring:
    profiles:
        active: dev

注意,上面我设置app的上下文路径是/myapp,那么Actuator的地址就是http://localhost:port/myapp/actuator/healt或info或matrics之类,总之记住context-path在app路径及actuator路径之上就好。Actuator是可以设置自己的根路径和端口的,如果不设,它会和控制器共享同样的根路径和端口。

 

3.启动application,在控制台能发现actutor已经被激活了。

2021-09-25 14:29:19.536  ...: Root WebApplicationContext: initialization completed in 2399 ms
2021-09-25 14:29:20.662  ...: Exposing 13 endpoint(s) beneath base path '/actuator'
2021-09-25 14:29:20.767  ... : Tomcat started on port(s): 8080 (http) with context path '/myapp'

 

4.在浏览器地址栏输入http://localhost:8080/myapp/actuator/health,出现以下画面就对了。

 

END

posted @ 2021-09-25 14:54  逆火狂飙  阅读(219)  评论(0编辑  收藏  举报
生当作人杰 死亦为鬼雄 至今思项羽 不肯过江东