Actuator 簡介
官方媽媽說:
Spring Boot includes a number of additional features to help you monitor and manage your application when you push it to production. You can choose to manage and monitor your application by using HTTP endpoints or with JMX. Auditing, health, and metrics gathering can also be automatically applied to your application.
傳送至官方:https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready
大概的意思是說,Spring boot 包括了許多額外的、可配置的特性,可以幫助我們來管理、監(jiān)控在生產環(huán)境下運行的應用程序,可使用HTTP或者JMX收集應用程序的各項指標,包括但不限定于審計(Auditing)、健康(health)狀態(tài)信息、數據采集(metrics gathering)統計等監(jiān)控運維的功能.
同時,我們可以擴展 Actuator 端點(Endpoint) 自定義監(jiān)控指標。這些指標都是以 JSON 接口數據的方式呈現。而使用 Spring Boot Admin 可以實現這些 JSON 接口數據的界面展現。
本章介紹 Spring Boot Actuator 和使用Spring Boot Admin實現對 Spring Boot應用的監(jiān)控與管理。
使用方式 / Usage
Maven , add pom dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Gradle, use the following declaration:
dependencies {
compile("org.springframework.boot:spring-boot-starter-actuator")
}
啟動的時候就會有下面這些提示.
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類
- 應用配置類
/configprops /autoconfig /beans /env /info /mappings
- 度量指標類
/dump /health
- 操作控制類
-
下面找?guī)讉€來解釋
-
/autoconfig
-
自動化配置報告,可以看出一些自動化配置為什么沒有生效

-
/beans
可以看到定義的所有的bean

-
/configprops
可以看到application.properties里面的信息

-
/env

-
/mappings

-
/info
返回application.properties文件中info開頭的配置信息,如:
# /info端點信息配置
info.app.name=spring-boot-hello
info.app.version=v1.0.0

下面是度量指標類
-
/metrics

我們也可以自定實現 CounterService 接口來實現count指標.

也可以用 [/metrics/{name:.*}] 如: /metrics/mem.free 來獲取單個指標信息

-
/health
可以通過實現 HealthIndicator 接口來實現健康檢查,返回值的狀態(tài)信息在org.springframework.boot.actuate.health.Status內


-
/dump
調用 java.lang.management.ThreadMXBean的
public ThreadInfo[] dumpAllThreads(boolean lockedMonitors, boolean lockedSynchronizers); 方法來返回活動線程的信息


-
操作控制類
如:/shutdown ,通過在application.properties文件中添加
endpoints.shutdown.enabled=true
來開啟

END