Loading

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 测试

  • 应用启动后,如果需要远程关闭应用,只需要使用POST请求http://localhost:8080/shutdown即可。

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
posted @ 2020-09-23 17:03  许大仙  阅读(418)  评论(0编辑  收藏  举报