1. 程式人生 > >spring-boot-starter-actuator 是什麼

spring-boot-starter-actuator 是什麼

spring-boot-starter-actuator 是什麼

一句話,actuator是監控系統健康情況的工具。

- 怎麼用?

1. 新增 POM依賴

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

2. 啟動的時候就會有下面這些提示.

Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.uti
Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.ser
Mapped URL path [/webjars/**] onto handler of type [class org.springframework.we
Mapped URL path [/**] onto handler of type [class org.springframework.web.servle
Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframewor Mapped "{[/metrics/{name:.*}],methods=[GET],produces=[application/json]}" onto p Mapped "{[/metrics || /metrics.json],methods=[GET],produces=[application/json]}" Mapped "{[/trace || /trace.json],methods=[GET],produces=[application/json]}
" ont Mapped "{[/configprops || /configprops.json],methods=[GET],produces=[application Mapped "{[/autoconfig || /autoconfig.json],methods=[GET],produces=[application/j Mapped "{[/info || /info.json],methods=[GET],produces=[application/json]}" onto Mapped "{[/dump || /dump.json],methods=[GET],produces=[application/json]}" onto Mapped "{[/mappings || /mappings.json],methods=[GET],produces=[application/json] Mapped "{[/health || /health.json],produces=[application/json]}" onto public jav Mapped "{[/beans || /beans.json],methods=[GET],produces=[application/json]}" ont Mapped "{[/env/{name:.*}],methods=[GET],produces=[application/json]}" onto publi Mapped "{[/env || /env.json],methods=[GET],produces=[application/json]}" onto pu

- actuator 的端點分為3類

  1. 應用配置類

/configprops /autoconfig /beans /env /info /mappings

  1. 度量指標類

/dump /health

  1. 操作控制類
  • 下面找幾個來解釋

    • /autoconfig

自動化配置報告,可以看出一些自動化配置為什麼沒有生效


image.png
  • /beans

可以看到定義的所有的bean


image.png
  • /configprops

可以看到application.properties裡面的資訊


image.png
  • /env
image.png
  • /mappings
image.png
  • /info

返回application.properties檔案中info開頭的配置資訊,如:

# /info端點資訊配置
info.app.name=spring-boot-hello
info.app.version=v1.0.0
image.png

下面是度量指標類

  • /metrics

image.png
我們也可以自定實現 CounterService 介面來實現count指標.
image.png
也可以用 [/metrics/{name:.*}] 如: /metrics/mem.free 來獲取單個指標資訊
image.png

  • /health

可以通過實現 HealthIndicator 介面來實現健康檢查,返回值的狀態資訊在org.springframework.boot.actuate.health.Status

image.png
image.png

  • /dump

呼叫 java.lang.management.ThreadMXBean
public ThreadInfo[] dumpAllThreads(boolean lockedMonitors, boolean lockedSynchronizers); 方法來返回活動執行緒的資訊

image.png
image.png

  • 操作控制類

如:/shutdown ,通過在application.properties檔案中新增
endpoints.shutdown.enabled=true
來開啟

image.png
貌似上面命令直接把應用關了......

      </div>

轉載:https://www.jianshu.com/p/481134c3fab7