SpringBoot 提供了三种应用监控的方式
通过 HTTP(最简单方便)
通过 JMX
通过远程 shell
这里就是用最简单的方式来使用 SpringBoot 的应用监控
首先引入依赖, pom 文件如下
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-actuator</artifactId>
- </dependency>
- <!-- 由于应用监控会暴露很多服务器信息, 所以需要引入 security 对应用进行保护 -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-security</artifactId>
- </dependency>
配置文件如下
- application.properties
- #actuator 端口
- management.server.port=9001
- # 修改访问路径 2.0 之前默认是 / 2.0 默认是 /actuator 可以通过这个属性值修改
- management.endpoints.web.base-path=/monitor
- # 开放所有页面节点 默认只开启了 health,info 两个节点
- management.endpoints.Web.exposure.include=*
- # 显示健康具体信息 默认不会显示详细信息
- management.endpoint.health.show-details=always
- # 使用 security 保护端点, 因为监控的会有很多敏感的信息, 设置之后会需要登陆之后才能进入应用监控
- spring.security.user.name=wangx
- spring.security.user.password=wangx
- spring.security.user.roles=SUPERUSER
配置之后启动系统, SpringBoot 就已经对应用进行了监控, 它是通过监控各个端点来实现的.
访问 http://localhost:9001/monitor / 可以看到每个监控的所有端点的 url, 直接访问即可查看该运用的该端点的信息
ENDPOINTS
1.X 的时候属性: HTTP 方法 路径 描述
GET /autoconfig 提供了一份自动配置报告, 记录哪些自动配置条件通过了, 哪些没通过
GET /configprops 描述配置属性 (包含默认值) 如何注入 Bean
GET /beans 描述应用程序上下文里全部的 Bean, 以及它们的关系
GET /dump 获取线程活动的快照
GET /env 获取全部环境属性
GET /env/{name} 根据名称获取特定的环境属性值
GET /health 报告应用程序的健康指标, 这些值由 HealthIndicator 的实现类提供
GET /info 获取应用程序的定制信息, 这些信息由 info 打头的属性提供
GET /mappings 描述全部的 URI 路径, 以及它们和控制器 (包含 Actuator 端点) 的映射关系
GET /metrics 报告各种应用程序度量信息, 比如内存用量和 HTTP 请求计数
GET /metrics/{name} 报告指定名称的应用程序度量值
POST /shutdown 关闭应用程序, 要求 endpoints.shutdown.enabled 设置为 true
GET /trace 提供基本的 HTTP 请求跟踪信息(时间戳, HTTP 头等)
2.0 部分更改:
1.x 端点 2.0 端点(改变)
/actuator 不再可用. 但是, 在 management.endpoints.Web.base-path 的根目录中有一个映射, 它提供了到所有暴露端点的链接.
/auditevents 该 after 参数不再需要
/autoconfig 重命名为 /conditions
/docs 不再可用
/health 现在有一个 management.endpoint.health.show-details 选项 never, always, when-authenticated, 而不是依靠 sensitive 标志来确定 health 端点是否必须显示全部细节. 默认情况下,/actuator/health 公开并且不显示细节.
/trace 重命名为 /httptrace
原文 SpringBoot 学习笔记(14)---- 应用监控 - HTTP 方式
SpringBoot 学习笔记(14)---- 应用监控 - HTTP 方式
来源: http://www.bubuko.com/infodetail-3053563.html