Spring Boot & Actuator 监控
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
如果需要详细了解的小伙伴 可以直接去官网看文档即可。
本文来自博客园,作者:咸瑜,转载请注明原文链接:https://www.cnblogs.com/bi-hu/p/15761466.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!