随笔 - 632  文章 - 17  评论 - 54  阅读 - 93万

使用SpringBootAdmin监控项目基本状态

一、概述

  当项目上线以后,开发/运维人员想要快速了解项目运行的健康状态。此时要怎么办,可以敲命令行查看服务器以及项目状态,单这样做太过于繁琐,且不够一目了然。有没有好心人帮我们把这块简化并且有可视化界面呢。答案当然是肯定的。那就是社区给出的开源插件SpringBootAdmin。非常简单,只需要两三步即可

二、使用步骤

  需要建立两个Web项目,一个是被监控项目(目标项目),一个是用来监控目标项目的辅助项目

  我们先做一个假设。假设SpringBootA项目是你要监控的目标。SpringBootB项目是监控A项目的辅助项目。

  现在先来处理SpringBootA。需要两步:

  1.给pom.xml中加入SpringBootAdmin支持

复制代码
 <!--监控-->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>2.7.10</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
复制代码

 

  2.修改application.xml文件

复制代码
  boot:
    admin:
      client:
        url: http://localhost:8090 #辅助项目的IP地址及端口号,配置上这一项之后,辅助项目就可以监控这个项目了
management:
  endpoints:
    web:
      exposure:
        include: "*" #[health,info,mappings] #或者直接配置 "*"代表监控所有
复制代码

  

  下面来配置SpringBootB的这个辅助项目。只需要简单的三步:

  1.在pom.xml中配置SpringBoot-Server支持

<!--SpringBootAdminServer支持-->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
            <version>2.7.10</version>
        </dependency>

 

  2.在application.yml中配置端口号(防止与SpringBootA端口重复,如果是独立部署则不需要担心此问题)

server:
  port: 8090

 

  3.在SpringBoot项目入口配置 @EnableSpringBootAdmin注解

复制代码
@EnableAdminServer//开启服务端监控
@SpringBootApplication
public class SpringBootAdminServerApplication {

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

}
复制代码

 4.配置完成后运行项目,在浏览器中输入http://localhost:8090就会出现如下图所示的界面,到此算是配置完成了

点击进去之后就可以查看一系列的监控信息了

 

posted on   飘杨......  阅读(205)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
历史上的今天:
2021-08-31 Android使用FFMpeg生成pcm格式音频,并利用AudioTrack播放出来
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示