1.监控端点信息
通过引入spring-boot-starter-actuator,可以使用Spring Boot为我们提供的准生产环境下的应用监控和管理功能。我们可以通过HTTP,JMX,SSH协议来进 行操作,自动得到审计、健康及指标信息等
autoconfig | 所有自动配置信息 |
auditevents | 审计事件 |
beans | 所有Bean的信息 |
configprops | 所有配置属性 |
dump | 线程状态信息 |
env | 当前环境信息 |
health | 应用健康状况 |
info | 当前应用信息 |
metrics | 应用的各项指标 |
mappings | 应用@RequestMapping映射路径 |
shutdown | 关闭当前应用(默认关闭) |
trace | 追踪信息(最新的http请求) |
步骤:
–
引入spring-boot-starter-actuator
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
– 通过http方式访问监控端点
启动项目打印的日志信息
配置文件设置安全关闭
management.security.enabled=false
–
可进行shutdown(POST 提交,此端点默认关闭)
远程发送post请求关闭服务
endpoints.shutdown.enabled=true
http://localhost:8080/shutdown
2.定制端点信息
–
定制端点一般通过endpoints+端点名+属性名来设置。
–
修改端点id(endpoints.beans.id=mybeans)
–
开启远程应用关闭功能(endpoints.shutdown.enabled=true)
–
关闭端点(endpoints.beans.enabled=false)
–
开启所需端点
•
endpoints.enabled=false
•
endpoints.beans.enabled=true
–
定制端点访问根路径
•
management.context-path=/manage
–
关闭http端点
•
management.port=-1
3.自定义健康状态指示器
1)、编写一个指示器 实现 HealthIndicator 接口
2)、指示器的名字 xxxxHealthIndicator
3)、加入容器中
@Component
public class MyAppHealthIndicator implements HealthIndicator {
@Override
public Health health() {
//自定义的检查方法
//Health.up().build()代表健康
return Health.down().withDetail("msg","服务异常").build();
}
}