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 包括了许多额外的、可配置的特性,可以帮助我们来管理、监控在生产环境下运行的应用程序,可使用HTTP或者JMX收集应用程序的各项指标,包括但不限定于审计(Auditing)、健康(health)状态信息、数据采集(metrics gathering)统计等监控运维的功能.
同时,我们可以扩展 Actuator 端点(Endpoint) 自定义监控指标。这些指标都是以 JSON 接口数据的方式呈现。而使用 Spring Boot Admin 可以实现这些 JSON 接口数据的界面展现。
本章介绍 Spring Boot Actuator 和使用Spring Boot Admin实现对 Spring Boot应用的监控与管理。
使用方式 / 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
- 操作控制类
-
下面找几个来解释
-
/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
接口来实现健康检查,返回值的状态信息在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