目 录CONTENT

文章目录

SpringBoot和监控管理(12)

Eric
2022-02-15 / 0 评论 / 0 点赞 / 171 阅读 / 540 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2023-12-12,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

SpringBoot和监控管理

1 概述

  • 通过引入spring-boot-starter-actuator,可以使用SpringBoot为我们提供的准生产环境下的应用监控和管理功能。我们可以通过HTTP、JMX、SSH协议来进行操作,自动得到审计、健康以及指标信息等。
  • 监控和管理端点:
端点名描述
autoconfig所有自动配置信息
auditevents审计事件
beans所有Bean的信息
configprops所有配置属性
dump线程状态信息
env当前环境信息
health应用健康状况
info当前应用信息
metrics应用的各项指标
mappings应用@RequestMapping映射路径
shutdown关闭当前应用(默认关闭)
trace追踪信息(最新的http请求)

2 SpringBoot整合actuator

SpringBoot的版本是1.5.12.RELEASE

2.1 引入spring-boot-starter-actuator的Maven坐标

<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>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    <optional>true</optional>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

2.2 修改application.propreties

# 关闭安全
management.security.enabled=false
#远程关闭应用
endpoints.shutdown.enabled=true

info.app.id=hello
info.app.version=1.0

2.3 测试

3 定制端点

  • 定制端点一般通过endpoints+端点名+属性名来设置。
# 关闭安全
management.security.enabled=false
#远程关闭应用
endpoints.shutdown.enabled=true

info.app.id=hello
info.app.version=1.0

# 修改端点
#endpoints.beans.id=mybean
#endpoints.beans.path=/bean

# 禁用端点
#endpoints.beans.enabled=false

# 关闭所有的端点,并启用某个端点
#endpoints.enabled=false
#endpoints.beans.enabled=true

# 定制所有端点的根路径
management.context-path=/manage
# 定制所有端点的端口,如果是-1,就表示不能访问
management.port=8081
0

评论区