1.添加POM依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
二.添加配置文件
server:
port: 8080
servlet:
context-path: /demo
# actuator 监控配置
management:
#actuator端口 如果不配置做默认使用上面8080端口
server:
port: 9090
endpoints:
web:
exposure:
#默认值访问health,info端点 用*可以包含全部端点
include: "*"
#修改访问路径 2.0之前默认是/; 2.0默认是/actuator可以通过这个属性值修改
base-path: /actuator
配置完成启动项目后就可以通过postman或者直接在预览器输入路径等方式来查看应用的运行状态了。
当项目启动时,访问http://127.0.0.1:9090/actuator地址
注意:如果没有配置 actuator端口,采用默认访问地址:http://127.0.0.1:8080/demo/actuator
如果看到类似下面的内容,说明actuator已经生效了
{
"_links": {
"self": {
"href": "http://127.0.0.1:9090/actuator",
"templated": false
},
"auditevents": {
"href": "http://127.0.0.1:9090/actuator/auditevents",
"templated": false
},
"beans": {
"href": "http://127.0.0.1:9090/actuator/beans",
"templated": false
},
"caches-cache": {
"href": "http://127.0.0.1:9090/actuator/caches/{cache}",
"templated": true
},
"caches": {
"href": "http://127.0.0.1:9090/actuator/caches",
"templated": false
},
"health": {
"href": "http://127.0.0.1:9090/actuator/health",
"templated": false
},
"health-component": {
"href": "http://127.0.0.1:9090/actuator/health/{component}",
"templated": true
},
"health-component-instance": {
"href": "http://127.0.0.1:9090/actuator/health/{component}/{instance}",
"templated": true
},
"conditions": {
"href": "http://127.0.0.1:9090/actuator/conditions",
"templated": false
},
"configprops": {
"href": "http://127.0.0.1:9090/actuator/configprops",
"templated": false
},
"env": {
"href": "http://127.0.0.1:9090/actuator/env",
"templated": false
},
"env-toMatch": {
"href": "http://127.0.0.1:9090/actuator/env/{toMatch}",
"templated": true
},
"info": {
"href": "http://127.0.0.1:9090/actuator/info",
"templated": false
},
"loggers": {
"href": "http://127.0.0.1:9090/actuator/loggers",
"templated": false
},
"loggers-name": {
"href": "http://127.0.0.1:9090/actuator/loggers/{name}",
"templated": true
},
"heapdump": {
"href": "http://127.0.0.1:9090/actuator/heapdump",
"templated": false
},
"threaddump": {
"href": "http://127.0.0.1:9090/actuator/threaddump",
"templated": false
},
"metrics-requiredMetricName": {
"href": "http://127.0.0.1:9090/actuator/metrics/{requiredMetricName}",
"templated": true
},
"metrics": {
"href": "http://127.0.0.1:9090/actuator/metrics",
"templated": false
},
"scheduledtasks": {
"href": "http://127.0.0.1:9090/actuator/scheduledtasks",
"templated": false
},
"httptrace": {
"href": "http://127.0.0.1:9090/actuator/httptrace",
"templated": false
},
"mappings": {
"href": "http://127.0.0.1:9090/actuator/mappings",
"templated": false
}
}
}