Actuator是Spring Boot提供的對應用系統的自省和監控的集成功能,能夠對應用系統進行配置查看、相關功能統計等。html
引入依賴便可spring
Maven
:<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
複製代碼
Gradle
:compile('org.springframework.boot:spring-boot-starter-actuator')
複製代碼
列舉一些主要的endpoints 安全
management.port
:指定訪問這些監控方法的端口,與邏輯接口端口分離。若是不想將這些暴露在http中,能夠設置 management.port = -1management.address
:指定地址,好比只能經過本機監控,能夠設置 management.address = 127.0.0.1根據上面表格,鑑權爲false
的,表示不敏感,能夠隨意訪問,不然就是作了一些保護,不能隨意訪問。bash
endpoints.mappings.sensitive=falseapp
這樣須要對每個都設置,比較麻煩。敏感方法默認是須要用戶擁有ACTUATOR
角色,所以,也能夠設置關閉安全限制:maven
management.security.enabled=falsespring-boot
或者配合Spring Security
作細粒度控制。post
能夠經過訪問/info
獲取信息,須要在配置文件設置ui
info:
aaa:
name: xxx
email: xxx@qq.com
bbb:
age: 25
hobbies: running
build:
artifact: "@project.artifactId@"
name: "@project.name@"
version: "@project.version@"
複製代碼
此時訪問localhost:8080/info返回一下信息 spa
若是使用maven
,能夠訪問pom.xml文件的信息,用法以下:
// 獲取pom.xml中project節點下artifactId屬性 artifact: "@project.artifactId@"
/shutdown
這個須要post方式,經過請求來關閉應用。 這個操做比較敏感,要想真正生效,須要如下配置:
endpoints.shutdown.enabled: true
HealthIndicator
接口,編寫本身的/health
方法邏輯。也能夠增長自定義監控方法。