三、项目接入Spring Boot Actuator

Actuator简介

生产系统中,往往需要对系统实际运行的情况(例如cpu、io、disk、db、业务功能等指标)进行监控运维。在SpringBoot项目中Actuator模块提供了众多HTTP接口端点(Endpoint),来提供应用程序运行时的内部状态信息。

Actuator模块提供了一个监控和管理生产环境的模块,可以使用http、jmx、ssh、telnet等来管理和监控应用。包括应用的审计(Auditing)、健康(health)状态信息、数据采集(metrics gathering)统计等监控运维的功能。同时,提供了可以扩展 Actuator端点(Endpoint)自定义监控指标。这些指标都是以JSON接口数据的方式呈现。

pom依赖

actuator并没有默认集成在自动配置中,而在作为独立的项目来呈现的。

        <!--监控和管理-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

当引入了上面的依赖,默认会引入actuator相关的两个项目:

	<!-- 默认引入项目,不需要手动添加依赖 -->
	<dependency>
	  <groupId>org.springframework.boot</groupId>
	  <artifactId>spring-boot-actuator</artifactId>
	</dependency>
	<dependency>
	  <groupId>org.springframework.boot</groupId>
	  <artifactId>spring-boot-actuator-autoconfigure</artifactId>
	</dependency>

其中spring-boot-actuator为功能实现,spring-boot-actuator-autoconfigure为自动配置。
需要注意:因SpringBoot Actuator会暴露服务的详细信息,为了保障安全性,建议添加安全控制的相关依赖spring-boot-starter-security,这样在访问应用监控端点时,都需要输入验证信息。
关于security的使用我们在此不进行展开详见Security接入。

效果

经过以上步骤的操作,启动SpringBoot项目,actuator便自动集成配置了,可通过:http://localhost:8080/actuator 访问,结果如下:

{
  "_links": {
    "self": {
      "href": "http://localhost:8080/actuator",
      "templated": false
    },
    "health-path": {
      "href": "http://localhost:8080/actuator/health/{*path}",
      "templated": true
    },
    "health": {
      "href": "http://localhost:8080/actuator/health",
      "templated": false
    },
    "info": {
      "href": "http://localhost:8080/actuator/info",
      "templated": false
    }
  }
}

拓展

以上actuator已经接入项目中
配置拓展使用详见

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值