Spring Boot ctuator
SpringBoot自带监控功能Actuator,通过 restful api 请求来监管、审计、收集应用的运行情况,可以帮助实现对程序内部运行情况监控,比如监控状况、Bean加载情况、环境变量、日志信息、线程信息等。
简称: 健康监控? 啊哈哈【自己瞎编的】
先创建一个新的SpringBoot项目,然后:
dap 整起来:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
然后直接跑起来【打开http://localhost:8081/actuator/】 注意: 我的是8081端口 当然你可以自己更换
可以看到 控制台爆出了一个端点,访问即可看到:
既然没给我格式化...服了
格式化后:
{
"_links": {
"self": {
"href": "http://localhost:8081/actuator",
"templated": false
},
"health": {
"href": "http://localhost:8081/actuator/health",
"templated": false
},
"health-path": {
"href": "http://localhost:8081/actuator/health/{*path}",
"templated": true
}
}
}
health端点
尝试访问这个 health 【http://localhost:8081/actuator/health】 ,这个是健康检查,我们访问可以看到:
就一个status ,我们可以在配置中打开查看全部详情:
再次访问:
state的值:
UP: 正常
DOWN:遇到问题,不正常
OUT_OF_SERVICE : 资源未使用,不应该去使用
UNKNOWN:不知道【未知】
INFO端点
一般会给出的,但我没给出,我们在配置文件开启所有端点 也可以开启指定端点:
我现在是激活了所有 可以看到info就出来了:
{
"_links": {
"self": {
"href": "http://localhost:8081/actuator",
"templated": false
},
"beans": {
"href": "http://localhost:8081/actuator/beans",
"templated": false
},
"caches-cache": {
"href": "http://localhost:8081/actuator/caches/{cache}",
"templated": true
},
"caches": {
"href": "http://localhost:8081/actuator/caches",
"templated": false
},
"health": {
"href": "http://localhost:8081/actuator/health",
"templated": false
},
"health-path": {
"href": "http://localhost:8081/actuator/health/{*path}",
"templated": true
},
"info": {
"href": "http://localhost:8081/actuator/info",
"templated": false
},
"conditions": {
"href": "http://localhost:8081/actuator/conditions",
"templated": false
},
"configprops": {
"href": "http://localhost:8081/actuator/configprops",
"templated": false
},
"configprops-prefix": {
"href": "http://localhost:8081/actuator/configprops/{prefix}",
"templated": true
},
"env": {
"href": "http://localhost:8081/actuator/env",
"templated": false
},
"env-toMatch": {
"href": "http://localhost:8081/actuator/env/{toMatch}",
"templated": true
},
"loggers": {
"href": "http://localhost:8081/actuator/loggers",
"templated": false
},
"loggers-name": {
"href": "http://localhost:8081/actuator/loggers/{name}",
"templated": true
},
"heapdump": {
"href": "http://localhost:8081/actuator/heapdump",
"templated": false
},
"threaddump": {
"href": "http://localhost:8081/actuator/threaddump",
"templated": false
},
"metrics-requiredMetricName": {
"href": "http://localhost:8081/actuator/metrics/{requiredMetricName}",
"templated": true
},
"metrics": {
"href": "http://localhost:8081/actuator/metrics",
"templated": false
},
"scheduledtasks": {
"href": "http://localhost:8081/actuator/scheduledtasks",
"templated": false
},
"mappings": {
"href": "http://localhost:8081/actuator/mappings",
"templated": false
}
}
}
进行访问info:
可以看到啥也没有,info意思是描述应用的意思,我们可以在配置文件中直接写入:
再次访问:
这里没做编码转换...所以服了。。。反之就是现实上面的内容吧。
他有很多很多这些,具体官网也给出:
https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.endpoints
如果需要详细了解的小伙伴 可以直接去官网看文档即可。
作者:咸瑜