spring boot starter actuator(健康监控)配置和使用教程
作者:yangliuhbhd 发布时间:2021-07-29 06:24:18
添加POM依赖:
<!-- spring-boot-监控-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
application.yml中指定监控的HTTP端口(如果不指定,则使用和Server相同的端口);指定去掉某项的检查(比如不监控health.mail):
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 下载内存快照 http://localhost:8083/info 读取配置文件application.properties的 info.*属性
在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
#远程关闭开启
endpoints.shutdown.enabled=true
#访问:http://localhost:8083/shutdown 关闭服务metrics
{
mem: 573549, //内存大小
mem.free: 388198, //内存剩余大小
processors: 4, //处理器数量
instance.uptime: 338426,
uptime: 345091,
systemload.average: -1,
heap.committed: 489984,
heap.init: 131072,
heap.used: 101785,
heap: 1842688,
nonheap.committed: 85056,
nonheap.init: 2496,
nonheap.used: 83566,
nonheap: 0,
threads.peak: 46,
threads.daemon: 36,
threads.totalStarted: 72,
threads: 39, //线程
classes: 12109,
classes.loaded: 12109, //加载的类
classes.unloaded: 0, //没加载的类
gc.ps_scavenge.count: 10,
gc.ps_scavenge.time: 103,
gc.ps_marksweep.count: 3,
gc.ps_marksweep.time: 219,
httpsessions.max: -1,
httpsessions.active: 0,
gauge.response.mappings: 3,
gauge.response.autoconfig: 4,
gauge.response.trace: 167,
counter.status.200.mappings: 1,
counter.status.200.autoconfig: 2,
counter.status.200.trace: 1
}
自定义配置说明:
#关闭metrics功能
endpoints.metrics.enabled=false
#开启shutdown远程关闭功能
endpoints.shutdown.enabled=true
#设置beansId
endpoints.beans.id=mybean
#设置beans路径
endpoints.beans.path=/bean
#关闭beans 功能
endpoints.beans.enabled=false
#关闭所有的
endpoints.enabled=false
#开启单个beans功能
endpoints.beans.enabled=true
#所有访问添加根目录
management.context-path=/manage
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.net.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(健康监控)配置和使用教程网站的支持!
来源:https://blog.csdn.net/yangliuhbhd/article/details/80655847


猜你喜欢
- 本文介绍了JAVA利用HttpClient进行HTTPS接口调用的方法,分享给大家,具体如下:1.为了避免需要证书,所以用一个类继承Defa
- 一. * 搭建及配置1 . * 简介 * 是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件。有了 * 之后,当 Maven
- 一、获取当前文件的路径1. System.Diagnostics.Process.GetCurrentProcess().MainModul
- 简单的页面分析在上一个文章简单的数据库连接测试,已经测试和数据库做简单的交互,也就是dao层的实现,接下来要说的却是action的简单实现,
- 我这里 shiro 并没有集成 springMVC,直接使用 ini 配置文件。shiro.ini[main]# Objects and t
- SpringBoot在annotation的层面实现了数据缓存的功能,基于Spring的AOP技术。所有的缓存配置只是在annotation
- 一致性哈希节点的增加和减少,大部分节点的 Hash一致package consistenthashimport ("hash/cr
- 多层嵌套JSON类型数据解析简单来说:“key”:“value&rdqu
- 用Linq从一个集合选取几列得到一个新的集合-可改列名
- 1、定义一个接口 Animalpackage com.zh.vo;public interface Animal { void
- 这篇文章主要介绍了Java import导入及访问控制权限修饰符过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考
- 性能测试过程中,如果进行大量的并发时,界面容易卡死。通过非GUI(命令行)的方式是个不错的选择。windows环境1.在安装Jmeter的目
- VisualVM是JDK自带的一款全能型性能监控和故障分析工具,包括对CPU使用、JVM堆内存消耗、线程、类加载的实时监控,内存dump文件
- 本文实例为大家分享了C#实现简单打字小游戏的具体代码,供大家参考,具体内容如下using System;using System.Colle
- 本文实例为大家分享了java利用数组随机抽取幸运观众的具体代码,供大家参考,具体内容如下思想:首先将所有观众姓名生成数组,然后获取数组元素的
- 前几天,公司数据库出现了两条相同的数据,而且时间相同(毫秒也相同)。排查原因,发现是网络波动造成了重复提交。由于网络波动而重复提交的例子也比
- 带搜索的ComboBox就是给ComboBox一个依赖属性的ItemSource,然后通过数据源中是否包含要查询的值,重新给ComboBox
- 本文实例为大家分享了Android九宫格图片展示的具体代码,供大家参考,具体内容如下此篇博客为整理文章,供大家学习。1.首先下载common
- AOP注解无效,切面不执行的解决想做一个api请求日志,想到使用aop,配置过程中遇到了一个坑,aop不起作用,我的aop是这样的:pack
- 路由事件模型传统的简单事件模型中,在消息激发是将消息通过事件订阅的然后交给事件的相应者,事件的相应者使用事件的处理器来做出相应,这样就存在一