从01开始 从01开始
首页
  • 计算机科学导论
  • 数字电路
  • 计算机组成原理

    • 计算机组成原理-北大网课
  • 操作系统
  • Linux
  • Docker
  • 计算机网络
  • 计算机常识
  • Git
  • JavaSE
  • Java高级
  • JavaEE

    • Ant
    • Maven
    • Log4j
    • Junit
    • JDBC
    • XML-JSON
  • JavaWeb

    • 服务器软件
    • Servlet
  • Spring
  • 主流框架

    • Redis
    • Mybatis
    • Lucene
    • Elasticsearch
    • RabbitMQ
    • MyCat
    • Lombok
  • SpringMVC
  • SpringBoot
  • 学习网课的心得
  • 输入法
  • 节假日TodoList
  • 其他
  • 关于本站
  • 网站日记
  • 友人帐
  • 如何搭建一个博客
GitHub (opens new window)

peterjxl

人生如逆旅,我亦是行人
首页
  • 计算机科学导论
  • 数字电路
  • 计算机组成原理

    • 计算机组成原理-北大网课
  • 操作系统
  • Linux
  • Docker
  • 计算机网络
  • 计算机常识
  • Git
  • JavaSE
  • Java高级
  • JavaEE

    • Ant
    • Maven
    • Log4j
    • Junit
    • JDBC
    • XML-JSON
  • JavaWeb

    • 服务器软件
    • Servlet
  • Spring
  • 主流框架

    • Redis
    • Mybatis
    • Lucene
    • Elasticsearch
    • RabbitMQ
    • MyCat
    • Lombok
  • SpringMVC
  • SpringBoot
  • 学习网课的心得
  • 输入法
  • 节假日TodoList
  • 其他
  • 关于本站
  • 网站日记
  • 友人帐
  • 如何搭建一个博客
GitHub (opens new window)
  • JavaSE

  • JavaSenior

  • JavaEE

  • JavaWeb

  • Spring

  • 主流框架

  • SpringMVC

  • SpringBoot

    • SpringBoot教程-尚硅谷

      • SpringBoot课程介绍
      • Spring和SpringBoot
      • HelloWorld
      • 了解自动配置原理
      • 底层注解-@Configuration详解
      • 底层注解-@Import导入组件
      • 底层注解-@Conditional条件装配
      • 原生配置文件引入-@ImportResource
      • 底层注解-配置绑定@ConfigurationProperties
      • 自动配置原理
      • 自动配置流程
      • Lombok简化开发
      • DevTools
      • Spring-Initailizr
      • 配置文件-Yaml用法
      • Web开发简介
      • web开发-静态资源规则于定制化
      • 静态资源配置原理
      • Rest映射及源码解析
      • 请求映射原理
      • 常用参数注解使用
      • MatrixVariable:矩阵变量
      • 各种类型参数解析原理
      • Servlet-API参数解析原理
      • Model、Map参数解析原理
      • 自定义对象参数绑定原理
      • 自定义Converter原理
      • 数据响应原理
      • 内容协商原理
      • 基于请求参数的内容原理
      • 自定义MessageConverter原理
      • Thymeleaf初体验
      • web实验-后台管理系统
      • web实验-抽取公共页面
      • web实验-遍历数据
      • 源码分析-视图解析器与视图
      • 拦截器-登录检查与静态资源放行
      • 拦截器的执行时机和原理
      • 单文件和多文件上传的使用
      • 文件上传原理
      • 错误处理机制
      • 错误处理-底层组件源码分析
      • 异常处理流程
      • 几种异常处理原理
      • Web原生对象注入
      • 嵌入式Servlet容器
      • 定制化原理
      • 数据库场景的自动配置分析和整合测试
      • 自定义方式整合Druid
      • 通过starter整合Druid
      • 整合Mybatis
      • 使用注解整合Mybatis
      • 整合MybatisPlus操作数据库
      • MybatisPlus-列表分页展示
      • 整合Redis
      • 单元测试-Junit5
      • 单元测试-断言机制
      • 单元测试-前置条件
      • 单元测试-嵌套测试
      • 单元测试-参数化测试
      • 指标监控-基本概念
      • 指标监控-配置EndPoint
      • 指标监控-可视化
        • spring-boot-admin介绍
        • 新建项目
        • 注册客户端
        • 源码
      • 原理解析-Profile功能
      • 配置文件深入
      • 自定义Starter
      • SpringApplication初始化过程
      • SpringBoot完整启动过程
      • SpringBoot
  • Java并发

  • Java源码

  • JVM

  • 韩顺平

  • Java
  • Java
  • SpringBoot
  • SpringBoot教程-尚硅谷
2023-08-22
目录

指标监控-可视化

# 630.指标监控-可视化

介绍下使用第三方项目,来将监控数据展示   ‍

# spring-boot-admin介绍

该项目是开源的:codecentric/spring-boot-admin (opens new window),并且有丰富的文档:Spring Boot Admin – doc (opens new window)

简单来说就是可以新建一个项目,专门用来监控其他微服务项目,我们可以称之为监控系统;监控系统会定期向其他微服务获取监控信息,并展示。

‍

# 新建项目

为此,我们新建一个项目

​​

‍

主要选择web开发场景即可,其他的按需选择:

​​

‍

‍

根据文档 (opens new window),我们引入依赖:

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-server</artifactId>
    <version>2.7.10</version>
</dependency>
1
2
3
4
5

注意,该依赖的版本要和SpringBoot的版本对应,文档是这样说的:

In the Spring Boot Admin Server App, the Spring Boot Admin's version matches the major and minor versions of Spring Boot.

Spring Boot Version Spring Boot Admin
2.6 2.6.Y
2.7 2.7.Y
3.0 3.0.Y

Nevertheless, it is possible to monitor any version of a Spring Boot service independently of the underlying Spring Boot version in the service. Hence, it is possible to run Spring Boot Admin Server version 2.6 and monitor a service that is running on Spring Boot 2.3 using Spring Boot Admin Client version 2.3.

‍

‍

并且在主类上,加上注解@EnableAdminServer​

package com.peterjxl.learnspringbootwebadminserver;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableAdminServer // 开启监控
public class LearnSpringBootWebAdminServerApplication {

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

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

‍

为了防止端口冲突,可以修改下配置文件:

server.port=8888
1

‍

启动项目,效果:

​​

‍

‍

# 注册客户端

接下来配置监控微服务。

首先在之前的admin项目中,引入客户端的依赖:

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>2.3.1</version>
</dependency>
1
2
3
4
5

‍

并且配置监控系统的地址:

spring:
  application:
    name: boot-admin-client # 服务名
  boot:
    admin:
      client:
        url: http://localhost:8888
        instance:
          prefer-ip: true # 注册时使用IP而不是主机名
1
2
3
4
5
6
7
8
9

‍

‍

‍

重启项目,然后访问应用墙:

​​

‍

‍

然后单击中间的应用,可以看到详细信息:

​​

‍

‍

还能看运行时指标,例如gc暂停次数:

​​

‍

‍

# 源码

已将本文源码上传到Gitee (opens new window)或GitHub (opens new window) 的分支demo24,读者可以通过切换分支来查看本文的示例代码

关于监控项目源码:Gitee (opens new window)、GitHub (opens new window)

在GitHub上编辑此页 (opens new window)
上次更新: 2023/8/23 10:10:57
指标监控-配置EndPoint
原理解析-Profile功能

← 指标监控-配置EndPoint 原理解析-Profile功能→

Theme by Vdoing | Copyright © 2022-2023 粤ICP备2022067627号-1 粤公网安备 44011302003646号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式