介绍
Actuator 是Spring Boot提供的对应用系统的自省和监控的集成功能,可以对应用系统进行配置查看、健康检查、相关功能统计等
实现
-
加依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
-
在application.properties配置文件中指定端口
如果不指定,其使用端口和服务端口一致#服务端口 server.port=9000 #web项目访问的上下文路径 server.servlet.context-path=/springboot-web #actuator端口 management.server.port=9100 #actuator监控的接口上下文路径 management.server.servlet.context-path=/springboot-actuator #默认只开启了health和info,设置为*,则包含所有的web监控入口端点都可以访问(上面两个如果不配置则默认使用web项目的配置) management.endpoints.web.exposure.include=*
例如:
http://localhost:9100/springboot-actuator/actuator/health
http://localhost:9100/springboot-actuator/actuator/info
功能及注意
-
actuator提供的主要功能
-
HTTP方法 路径 描述 是否为wen入口 GET /configprops 查看配置属性,包括默认配置 true GET /beans 查看bean及其关系列表 true GET /env 查看所有环境变量 true GET /health 查看应用健康指标 false GET /info 查看应用信息 false GET /mappings 查看所有url映射 true GET /metrics 查看应用基本指标 true GET /metrics/{name} 查看具体指标 true JMX /shutdown 关闭应用 true -
注意
- /info需要自己在application.properties文件中添加信息:
info.contact.name=张三 info.contact.age=20 info.contact.phone=123456789012
- /shutdown需要在配置文件中开启才能生效
JMX是Java管理拓展,需要用jdk的一个应用去操作management.endpoint.shutdown.enabled=true
jdk安装路径------->bin------>jcosole.exe双击
- /info需要自己在application.properties文件中添加信息: