为springboot项目添加springboot-admin监控

我们知道spring-boot-actuator暴露了大量统计和监控信息的端点,spring-boot-admin
就是为此提供的监控项目。

先来看看大概会提供什么样的功能

admin-list.png

admin-detail.png

从图中可以看出,主要内容都是由spring boot actuator来提供的。更多关于actuator的信息参见Springboot actuator

接下来,hello world时间。

server端

server端是一个单独的springboot项目,主要负责收集和展示监控指标,提供了ui page。

项目地址: https://github.com/Ryan-Miao/springboot-admin-demo

新建一个springboot项目,可以使用idea自带的spring initializr. 主要添加以下两个依赖,

<springboot.version>1.5.13.RELEASE</springboot.version>
<spring-boot-admin.version>1.5.7</spring-boot-admin.version>
    
  <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>
  
    <dependencies>
      <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-starter-server</artifactId>
      </dependency>
      <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-server-ui</artifactId>
      </dependency>
    </dependencies>

在启动类上添加@EnableAdminServer

在配置文件中设置服务地址,这里假设为8081

server.port=8081

启动。

client 端

client端是指我们正常的app,我们的spring boot项目就是。在原有的基础上添加依赖

    <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>
    </dependency>


  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>${springboot.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>build-info</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>

之后配置相关信息:

client端添加admin的url,这里暂时忽略spring security

spring:
  boot:
    admin:
      url: http://localhost:8081
management:
  security:
    enabled: false

然后,启动我们的app。访问localhost:8081就可以看到文章开始图片里的信息了。

更多文档: https://codecentric.github.io/spring-boot-admin/1.5.0/#_what_is_spring_boot_admin

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值