springbootstarteractuator(健康监控)配置和使⽤教程添加POM依赖:
<!-- spring-boot-监控-->
<dependency>
<groupId>org.springframework.boot</groupId>springboot和过滤器
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
server:
port: 8083
management:
port: 8083
security:
enabled: false #
监控和管理端点
端点名描述
autoconfig所有⾃动配置信息( positiveMatches :运⾏的, negativeMatches 未运⾏组件)
auditevents审计事件
beans所有Bean的信息
configprops所有配置属性
dump线程状态信息
env当前环境信息
health应⽤健康状况
info当前应⽤信息
metrics应⽤的各项指标
mappings应⽤@RequestMapping映射路径
shutdown关闭当前应⽤(默认关闭)
trace追踪信息(最新的http请求)
heapdump下载内存快照
在InfoProperties 读取
application.properties :
info.app.version=v1.2.0
info.app.name=abc
在GitProperties  获取git.properties 的信息
info.app.version=v1.2.0
info.app.name=abc
#远程关闭开启
abled=true
#访问:localhost:8083/shutdown  关闭服务
metrics
{
mem: 573549,  //内存⼤⼩
mem.free: 388198, //内存剩余⼤⼩
processors: 4, //处理器数量
instance.uptime: 338426,
uptime: 345091,
systemload.average: -1,
heapmitted: 489984,
heap.init: 131072,
heap.used: 101785,
heap: 1842688,
nonheapmitted: 85056,
nonheap.init: 2496,
nonheap.used: 83566,
nonheap: 0,
threads.peak: 46,
threads.daemon: 36,
threads: 39, //线程
classes: 12109,
classes.loaded: 12109, //加载的类
classes.unloaded: 0, //没加载的类
gc.unt: 10,
gc.ps_scavenge.time: 103,
gc.unt: 3,
gc.ps_marksweep.time: 219,
httpsessions.max: -1,
httpsessions.active: 0,
counter.status.200.mappings: 1,
counter.status.200.autoconfig: 2,
counter.ace: 1
}
⾃定义配置说明:
#关闭metrics功能
#开启shutdown远程关闭功能
abled=true
#设置beansId
endpoints.beans.id=mybean
#设置beans路径
endpoints.beans.path=/bean
#关闭beans 功能
abled=false
#关闭所有的
#开启单个beans功能
abled=true
#所有访问添加根⽬录
management.port=8181
org.springframework.boot.actuate.health 包下对于所有的健康状态检查例如:RedisHealthIndicator ,当有redis的starter 时候就会检查
{
status: "DOWN", //状态
diskSpace: {
status: "UP",
total: 395243941888,
free: 367246643200,
threshold: 10485760
},
rabbit: {
status: "DOWN",
error: "org.springframework.amqp.AmqpConnectException: java.ConnectException: Connection refused: connect"
},
redis: {
status: "UP",
version: "4.0.9"
},
db: {
status: "UP",
database: "MySQL",
hello: 1
}
}
⾃定义health
•⾃定义健康状态指⽰器
•1、编写⼀个指⽰器实现 HealthIndicator 接⼝
•2、指⽰器的名字 xxxxHealthIndicator
•3、加⼊容器中
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
@Component
public class MyAppHealthIndicator implements HealthIndicator {
@Override
public Health health() {
//⾃定义的检查⽅法
/
/Health.up().build()代表健康
return Health.down().withDetail("msg","服务异常").build();
}
}
总结
以上所述是⼩编给⼤家介绍的spring boot starter actuator(健康监控)配置和使⽤教程,希望对⼤家有所帮助,如果⼤家有任何疑问请给我留⾔,⼩编会及时回复⼤家的。在此也⾮常感谢⼤家对⽹站的⽀持!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。