© 版權聲明:本文為博主原創文章,轉載請注明出處
1. 版本
SpringBoot:2.0.0.RELEASE
2. 集成
SpringBoot集成actuator模塊非常簡單,只需要引入actuator模塊的依賴即可。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
3. 訪問
書上寫的訪問方式為:http://ip:port/health;但是我訪問一直報錯400,百度的結果跟書上一致。
最后查詢官方文檔,發現2.0.0.RELEASE的訪問方式已經變了,最新訪問方式為:http://ip:port/actuator/health
4. 配置
> actuator默認的訪問端口跟項目端口一致,但也可自己指定
management:
server:
port: 8100
> actuator訪問必須通過JMX和HTTP,但是使用HTTP默認只暴露health和info,因此想訪問其他端點需自己配置
management:
endpoints:
web:
exposure:
exclude: shutdown,info # 排除端點,不可訪問;多端點之間用逗號分隔
include: httptrace,env # 包含端點,可以訪問;多端點之間用逗號分隔
> 在Spring Boot 2.0.0.RELEAS版本中,訪問health端口,只能查詢系統的狀態,不能查看詳細的信息。若想查看所需信息,需進行如下配置
management:
endpoint:
health:
show-details: always
其中show-details的值有三個:never,when-authorized,always。具體含義如下:
never:從不展示詳情(默認)
when-authorized:詳情只展示給授權用戶,授權角色可使用 management.endpoint.health.roles 進行配置
always:展示詳情給所有用戶
參考: