添加pom依赖:
|
1
2
3
4
5
6
7
8
9
|
application.yml中指定监控的http端口(如果不指定,则使用和server相同的端口);指定去掉某项的检查(比如不监控health.mail):
|
1
2
3
4
5
6
|
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 | 下载内存快照 |
读取配置文件application.properties的 info.*属性
在infoproperties 读取
application.properties :
|
1
2
|
info.app.version=v1.2.0
info.app.name=abc
|
在gitproperties 获取git.properties 的信息
|
1
2
3
4
5
|
info.app.version=v1.2.0
info.app.name=abc
#远程关闭开启
endpoints.shutdown.enabled=true
#访问:http://localhost:8083/shutdown 关闭服务
|
metrics
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
{
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
}
|
自定义配置说明:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#关闭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 时候就会检查
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
{
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、加入容器中
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
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(健康监控)配置和使用教程,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对快网idc网站的支持!
原文链接:https://blog.csdn.net/yangliuhbhd/article/details/80655847
相关文章
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
-
Sublime Text 3 实现C语言代码的编译和运行(示例讲解)
2025-05-27 65 -
【ASP.NET Core】在node.js上托管Blazor WebAssembly应用
2025-05-29 22 -
2025-06-04 25
-
IOS 使用Block二次封装AFNetworking 3.0详解
2025-05-29 33 -
2025-06-04 40

