3、SpringBoot项目整合Actuator

本文介绍了Spring Boot Actuator对Spring Boot应用的监控和管理功能,如健康检查、审计等,还能与外部监控系统整合。详细说明了修改配置文件、项目启动、访问不同端点查看信息的操作,包括展示详细健康信息、创建自定义健康指标等,最后提及使用springSecurity保证其安全。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

接着上一章:https://blog.youkuaiyun.com/romulusla01/article/details/93469258
本章项目源码:https://download.youkuaiyun.com/download/romulusla01/11256054
参考:https://www.jianshu.com/p/d5943e303a1f
Spring Boot Actuator可以帮助你监控和管理Spring Boot应用,比如健康检查、审计、统计和HTTP追踪等。所有的这些特性可以通过JMX或者HTTP endpoints来获得。
Actuator同时还可以与外部应用监控系统整合,比如 Prometheus, Graphite, DataDog, Influx, Wavefront, New Relic等。这些系统提供了非常好的仪表盘、图标、分析和告警等功能,使得你可以通过统一的接口轻松的监控和管理你的应用。
Actuator使用Micrometer来整合上面提到的外部应用监控系统。这使得只要通过非常小的配置就可以集成任何应用监控系统。
1、修改pom.xml
在这里插入图片描述
2、修改配置文件application.properties
在这里插入图片描述
3、项目启动
访问http://localhost:8085/getUsersByName?name=rome,发现程序正常运行
在这里插入图片描述
访问http://localhost:8086/actuator,查看所有actuator
在这里插入图片描述
访问http://localhost:8086/actuator/httptrace,跟踪请求
在这里插入图片描述
访问http://localhost:8086/actuator/health,这里status为UP,就是健康的
在这里插入图片描述
这里就成功了。
4、常用的actuator endpoints列表
在这里插入图片描述
5、展示详细的health,增加一个配置文件application.yaml并输入如下内容
在这里插入图片描述
management:
endpoint:
health:
show-details: always
在这里插入图片描述
启动后访问:http://localhost:8086/actuator/health,界面变成了
在这里插入图片描述

6、创建自定义的健康指标,新建一个package,创建RomeHealthIndicator类
在这里插入图片描述
在这里插入图片描述
7、启动项目,访问http://localhost:8086/actuator/health
在这里插入图片描述
已经把自定义内容展示了。
8、访问http://localhost:8086/actuator/metrics,追踪所有的度量
在这里插入图片描述
想要获得每个度量的详细信息,你需要传递度量的名称到URL中,像
http://localhost:8086/actuator/metrics/{MetricName}
如访问:http://localhost:8086/actuator/metrics/system.cpu.count
在这里插入图片描述
9、http://localhost:8086/actuator/loggers/{name}
在这里插入图片描述
10、http://localhost:8086/actuator/info
在这里插入图片描述
info endpoint展示了应用的基本信息。它通过META-INF/build-info.properties来获得编译信息,通过git.properties来获得Git信息。它同时可以展示任何其他信息,只要这个环境property中含有info key。

修改application.yaml
在这里插入图片描述
再次访问:http://localhost:8086/actuator/info
在这里插入图片描述

11、使用springSecurity保证Actuator的安全,修改pom.xml

	<dependency>
	   	<groupId>org.springframework.boot</groupId>
	   	<artifactId>spring-boot-starter-security</artifactId>
	</dependency>

在这里插入图片描述
新建package
在这里插入图片描述
新建RomeSecurityConfig
在这里插入图片描述
修改application.yaml
在这里插入图片描述
访问:http://localhost:8086/actuator,会跳转到login页面
在这里插入图片描述
输入账号密码后,进入http://localhost:8086/actuator
在这里插入图片描述
HttpSecurity方法介绍
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值