Spring Boot提供了运行时的应用监控和管理的功能,我们可以通过http, JMX, SSH协议进行操作.
端点名 | 描 述 |
actuator | 所有EndPoint的列表,需加入springHATEOAS支持 |
autoconfig | 当前应用所有自动配置 |
beans | 当前应用中所有bean的信息 |
configprops | 当前应用中所有的配置属性 |
dump | 显示当前应用线程状态信息 |
env | 显示当前应用当前环境信息 |
health | 健康状况 |
info | 显示当前应用信息 |
metrics | 各项指标信息 |
mappings | 显示所有的@RequestMapping映射的路径 |
shutdown | 关闭当前应用,默认关闭 |
trace | 显示追踪信息, 默认是最新的http请求 |
1, HTTP
pom.xml添加:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
测试e.g. http://localhost:8080/actuator, xxx/autoconfig
1), 定制端点
一般通过endPoints + 端点名 + 属性名来设置,每段之间用","隔开
修改端点id: endpoint.beans.id=mybeans
访问就变为: http://localhost:8080/mybeans
2), 自定义端点
当spring boot提供的端点不能满足我们特殊的需求,我们就需要自定义一个.
需继承AbstractEndpoint的实现类,并将其注册为Bean即可
3), 自定义HealthIndicator
实现HealthIndicator接口类
2, JMX
在控制台调用java内置的jconsole来实现JMX监控
cmd ---> jconsole, 会弹出监控窗口
3, SSH
这是spring借助CraSH(http://www.crashub.org)来实现的.
在项目中添加spring-boot-starter-remote-shell依赖即可
1), 运行
启动程序时控制台会打印SSH访问密码,可使用puTTY, SecureCRT等访问
主机: localhost
端口: 2000
账号: user
密码: 如上控制台输出
2), 常用命令
help, metrics, endpoint health
3), 定制登录用户
在application.properties定制下面属性
shell.auth.simple.user.name=xxxx
shell.auth.simple.user.password=xxxx
4), 扩展命令
可在spring-boot-starter-remote-shell.jar中查看