一:環境準備.
1. Chrome瀏覽器,JSONView插件,SpringBoot框架,Maven.
JSONView插件的安裝:安裝教程.(用於美化Json輸出的).
SpringBoot框架的版本:1.5.10.RELEASE.
安裝完截圖如下
2. Maven依賴添加.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
3. application.properties中添加如下:(開啓性能指標)這個其實是actuator插件默認包含的,並且開啓的.
endpoints.metrics.enabled=true
4. 啓動SpringBoot程序,然後瀏覽器訪問如下.(我修改的端口是8082)
發現訪問異常了.閱讀錯誤提示信息發現是,訪問授權的問題.在application.properties中將管理授權關閉了,默認是開啓的.
management.security.enabled=false
5. 然後重新啓動程序.
上面包含了大量性能指標信息,包括內存,CPU,Java堆,線程,Java類,JVM垃圾回收,HTTP會話.
5.1 關閉metrics端點.
endpoints.metrics.enabled=false
5.2 關閉所有端點,僅開啓metrics端點.
endpoints.enabled=false
endpoints.metrics.enabled=true
5.3 修改metrics端點的名稱.
endpoints.metrics.id=testmetrics
5.4:修改metrics端點的請求路徑.
endpoints.metrics.path=/endpoints/metrics
6. SpringBoot的Actuator插件提供瞭如下端點信息.
autoconfig 獲取自動配置的信息.
beans 獲取Spring Bean基本信息.
configprops : 獲取配置項信息.
dump: 獲取當前線程基本信息.
env: 獲取當前的環境變量信息.
health: 獲取檢查檢查信息.
info: 獲取應用基本信息.
mappings:獲取請求映射基本信息.
trace: 獲取請求調用信息.
7. 查看SpringBoot給我們提供了哪些端點?
使用HATEOAS插件.它可以彙總端點信息,包括各個端點的名稱與鏈接.
使用HATEOAS插件,Maven添加依賴.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
這個時候我們就擁有了actuator端點了.
禁用actuator端點.
endpoints.actuator.enabled=false
8. 使用HAL bROWSER圖形化工具,更好地查看端點信息.
<dependency>
<groupId>org.webjars</groupId>
<artifactId>hal-browser</artifactId>
</dependency>
這個時候瀏覽器訪問站點.(非常漂亮的圖形界面)
9. 進一步瞭解Actuator,開啓Actuator插件.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-docs</artifactId>
</dependency>
如果有些端點不能訪問可能是框架爲了安全就不暴露這麼多的端點了.
例如:Spring Boot 2.0 的Actuator只暴露了health和info端點,其它的一堆怎麼也打不開.
在:management.endpoints.web.exposure.include= 指定要暴露的端點就可以的.