springboot项目配置应用监控中心

一、为应用添加健康检查
1、maven引入actuator依赖

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

2、修改全局配置文件,添加以下内容

#健康检查
management:                 					  #第1级
  endpoints:								      #第2级
    web:  										  #第3级
      exposure:          						  #第4级
        #默认只加载了info、health
        include: 'prometheus,info,health'         #第5级
  endpoint:
    health:
      show-details: always
    #可以关闭指定的端点
    shutdown:
      enabled: false

3、访问http://localhost:8090/actuator/health,看到以下信息,说明应用监控添加成功
springboot项目配置应用监控中心

可能出现的问题:
1、访问http://localhost:8090/actuator/health,只能看见状态,看不到详细信息
springboot项目配置应用监控中心
解决方法:检查全局配置文件,确保show-details在第4级,笔者之前就是因为把endpoint写在endpoints下,导致show-details配在了第5级导致配置无效。