SpringBoot3 Actuator使用如何以及自定义端点

参考: https://www.yuque.com/leifengyang/springboot3/wsx0br0dalot1pqn

作用: 对线上应用进行观测、监控、预警…
比如:
● 健康状况【组件状态、存活状态】Health
● 运行指标【cpu、内存、垃圾回收、吞吐量、响应成功率…】Metrics
● 链路追踪

1.使用

1.场景引入

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

2.暴露指标
在application.properties里面进行设置

#暴露所有端点信息  
management.endpoints.web.exposure.include=*
#以web方式暴露  
management.endpoint.health.enabled=true

3.访问数据
● 访问 http://localhost:8080/actuator;展示出所有可以用的监控端点
● http://localhost:8080/actuator/beans
● http://localhost:8080/actuator/configprops
● http://localhost:8080/actuator/metrics
● http://localhost:8080/actuator/metrics/jvm.gc.pause
● http://localhost:8080/actuator/endpointName/detailPath

2.Endpoint

常用端点: 默认提供了各种端点,来展示应用的详细信息
包括看有多少线程及线程运行情况,生成堆dump等各种端点
参考:
https://www.yuque.com/leifengyang/springboot3/wsx0br0dalot1pqn?inner=u8Ebe

3.如何自定义端点

自定义HealthEndpoint和MetricsEndpoint

3.1 HealthEndpoint

1.自定义健康端点
例如监控一个组件的状态,存活还是死亡
方法: 实现HealthIndicator接口或者继承AbstractHealthIndicator来实现
1)实现HealthIndicator接口–>类名必须以HealthIndicator结尾,并且实现HealthIndicator接口,spring boot就能够确定这个组件是用来监控的

一句话总结下面的代码: 实现HealthIndicator接口的health方法,返回Health对象

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值