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
方法逻辑。也能够增长自定义监控方法。