Spring Boot应用监控(执行器)

本文详细介绍SpringBoot应用监控执行器(Actuator)的使用,包括如何通过端点(如beans、dump、env、health、info、mappings等)监控Web服务器运行状态,以及如何在远程服务器上实时查看系统运行情况。文章还提供了配置示例,说明了如何启用监控端点,并指出了安全注意事项。

Spring Boot应用监控(执行器)

Spring Boot应用监控
针对项目上线之后服务器的维护问题,可以及时的对Web服务器运行状态进行实时监控,即使在远程服务器上也可以随时方便地查找服务器和系统运行的状态。官方叫做 Actuator——执行器

框架内置的主要的端点(EndPiont)
beans——显示应用程序的审计事件信息
dump——dump所有线程
env ——陈列所有的环境变量
health——显示应用程序运行状况信息
info——显示应用信息
mappings——显示所有@RequestMapping的url整理列表
…等等

监控的依赖:
	<!-- 在pom.xml中添加以下依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <!-- 要使用http就要添加以下依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

处于安全问题,大部分端点都未开放,需要开启application.properties文件配置 management.endpoint.xxx.enabled=true 才能开启这个端点的信息监控
(xxx 是某个端点的名称)

#actuator配置
#配置访问监控的跟路径,默认是actuator
management.endpoints.web.base-path=/monitor
#默认开启所有端点
management.endpoints.enabled-by-default=true
#开启的端点需要给web访问的有哪些
management.endpoints.web.exposure.exclude=*

management.endpoints.beans.enabled=true
management.endpoints.health.enabled=true
management.endpoints.mappings.enabled=true
#表示开启所有端点给Web访问,还可以写health、beans等端点名称
management.endpoints.web.exposure.include=*

需要在application.properties配置,比如健康值(health)之类的

在.yml文件配置端口号

---
server:
  port: 8080

端口号为8080(多个环境使用’—’三个横杠进行隔开)

最后就可以执行:

http://localhost:8080/monitor/health

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值