1.添加POM依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
二.添加配置文件
server:
port: 8080
servlet:
context-path: /demo
# actuator 監(jiān)控配置
management:
#actuator端口 如果不配置做默認使用上面8080端口
server:
port: 9090
endpoints:
web:
exposure:
#默認值訪問health,info端點 用*可以包含全部端點
include: "*"
#修改訪問路徑 2.0之前默認是/; 2.0默認是/actuator可以通過這個屬性值修改
base-path: /actuator
配置完成啟動項目后就可以通過postman或者直接在預覽器輸入路徑等方式來查看應用的運行狀態(tài)了。
當項目啟動時,訪問http://127.0.0.1:9090/actuator地址
注意:如果沒有配置 actuator端口,采用默認訪問地址:http://127.0.0.1:8080/demo/actuator
如果看到類似下面的內(nèi)容透典,說明actuator已經(jīng)生效了
{
"_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
}
}
}