springboot(十七)监控管理

 

1.监控端点信息

2.定制端点信息

3.自定义健康状态指示器


 

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();
    }
}

 

 
 
 
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值