SpringBoot 监控

本文主要内容

1. Actuator介绍

2. Spring Boot Admin

1. Actuator介绍

Actuator是Spring Boot的一个附加功能,可帮助你在应用程序生产环境时监视和管理应用程序。可以使用HTTP的各种请求来监管,审计,收集应用的运行情况。Spring Boot Actuator提供了对单个
Spring Boot的监控,信息包含:应用状态、内存、线程、堆栈等等,比较全面的监控了Spring
Boot应用的整个生命周期。特别对于微服务管理十分有意义。

在 Spring Boot 2.x 中,Actuator默认开放了两个接口  /actuator/health 和 /actuator/info; 可以在配置文件中设置打开

打开所有:

management.endpoints.web.exposure.include=*

打开指定接口 

management.endpoints.web.exposure.include=beans,trace

 Actuator 默认所有的监控点路径都在 /actuator/*  

自定义请求路径

management.endpoints.web.base-path=/manage

2. Spring Boot Admin

Spring Boot Admin 是一个针对spring-boot的actuator接口进行UI美化封装的监控工具

搭建Server端

1. 创建新的springboot项目 (选择Spring Initializer)

选择Spring Boot Actuator依赖环境

<dependencies>
   <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
   </dependency>
   <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
   </dependency>
   <dependency>
      <groupId>de.codecentric</groupId>
      <artifactId>spring-boot-admin-starter-server</artifactId>
   </dependency>

   <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
   </dependency>
</dependencies>
<dependencyManagement>
   <dependencies>
      <dependency>
         <groupId>de.codecentric</groupId>
         <artifactId>spring-boot-admin-dependencies</artifactId>
         <version>${spring-boot-admin.version}</version>
         <type>pom</type>
         <scope>import</scope>
      </dependency>
   </dependencies>
</dependencyManagement>

2. 启动类增加@EnableAdminServer注解

@EnableAdminServer
@SpringBootApplication
public class MySpringBootActuatorApplication {

   public static void main(String[] args) {
      SpringApplication.run(MySpringBootActuatorApplication.class, args);
   }

} 

3. 设置服务端口 (非必要,默认为8080) 

server.port=9090

http://localhost:9090/

 搭建Client端

1.  引入actuator及 admin-starter-client依赖

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
   <groupId>de.codecentric</groupId>
   <artifactId>spring-boot-admin-starter-client</artifactId>
   <version>2.1.0</version>
</dependency>

2. 将Client作为服务注册到Server,通过Server来监听项目的运行情况spring:
  boot.admin.client.url=http://localhost:9090;

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: always
spring:
  boot:
    admin:
      client:
        url: http://localhost:9090
  application:
    name: spring-boot-admin-client

启动Client端后,刷新原Server http://localhost:9090/ client注册成功

 

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值