柏竹 柏竹
首页
后端
前端
  • 应用推荐
关于
友链
  • 分类
  • 标签
  • 归档

柏竹

奋斗柏竹
首页
后端
前端
  • 应用推荐
关于
友链
  • 分类
  • 标签
  • 归档
  • Java基础

  • JavaWeb

  • 拓展技术

  • 框架技术

  • 数据库

  • 数据结构

  • Spring

  • SpringMVC

  • SpringBoot

  • SpringClound

  • Ruoyi-Vue-Plus

    • ruoyi-vue-plus-基础功能
    • ruoyi-vue-plus-权限控制
    • ruoyi-vue-plus-表格操作
    • ruoyi-vue-plus-缓存功能
    • ruoyi-vue-plus-日志功能
    • ruoyi-vue-plus-线程相关
    • ruoyi-vue-plus-OSS功能
    • ruoyi-vue-plus-代码生成功能
    • ruoyi-vue-plus-多数据源
    • ruoyi-vue-plus-任务调度
    • ruoyi-vue-plus-监控功能
      • Admin 监控中心
      • 依赖
      • 配置
        • ruoyi-monlitor-admin模块配置
        • ruoyi-admin模块配置
      • 拓展模块监控
    • ruoyi-vue-plus-国际化
    • ruoyi-vue-plus-XSS功能
    • ruoyi-vue-plus-防重幂&限流 功能
    • ruoyi-vue-plus-推送功能
    • ruoyi-vue-plus-序列化功能
    • ruoyi-vue-plus-数据加密
    • ruoyi-vue-plus-单元测试
    • ruoyi-vue-plus-前端插件
    • ruoyi-vue-plus-前端工具篇
    • ruoyi-vue-plus-部署篇
    • ruoyi-vue-plus-前端篇
    • ruoyi-vue-plus-后端工具篇
    • ruoyi-vue-plus-框架篇
    • ruoyi-vue-plus-问题解决
  • 后端
  • Ruoyi-Vue-Plus
柏竹
2024-01-29
目录

ruoyi-vue-plus-监控功能

# Admin 监控中心

Spring Actuator 用于 管理和监控应用程序的拓展模块 . 它提供了端点对实例进行监控 , 这些端点会暴露接口 , 我们能够通过暴露的接口获取到 实例的运行状态、性能指标、健康状态等信息

参考文档

  • 官方文档 : https://docs.spring.io (opens new window)
  • ruoyi-vue-plus应用文档 : https://plus-doc.dromara.org (opens new window)

提示

endpoints端点 是指监控和管理应用交互的一组接口 . 这些接口提供了实例运行的内置信息

# 依赖

ruoyi-monlitor-admin模块

<!-- Web模块 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 安全认证 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- 服务端 -->
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
<!-- 客户端 (监控自己) -->
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
</dependency>

# 配置

# ruoyi-monlitor-admin模块配置

application.yml配置文件

主要关注 : 账号密码、访问路径















 
 




 















server:
  port: 9090
spring:
  application:
    name: ruoyi-monitor-admin
  profiles:
    active: @profiles.active@
logging:
  config: classpath:logback-plus.xml

--- # 监控中心服务端配置
spring:
  security:
    user:
      name: ruoyi
      password: 123456
  boot:
    admin:
      ui:
        title: RuoYi-Vue-Plus服务监控中心
      context-path: /admin

--- # Actuator 监控端点的配置项
management:
  endpoints:
    web:
      exposure:
        # 监控所有端点
        include: '*'
  endpoint:
    health:
      # 始终显示健康细节
      show-details: ALWAYS
    logfile:
      external-file: ./logs/ruoyi-monitor-admin.log

application-{环境}.yml配置文件

--- # 监控中心配置
spring.boot.admin.client:
  # 增加客户端开关
  enabled: true
  url: http://localhost:9090/admin
  instance:
    service-host-type: IP
  username: ruoyi
  password: 123456

AdminServerConfig配置类 (server配置类)

@Configuration
@EnableAdminServer
public class AdminServerConfig {
    /**
    *  懒加载Bean 用的时候才会进行加载
    *  没有 Executor类 时才会进行当前Bean的初始化
    **/
    @Lazy
    @Bean(name = TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME)
    @ConditionalOnMissingBean(Executor.class)
    public ThreadPoolTaskExecutor applicationTaskExecutor(TaskExecutorBuilder builder) {
        return builder.build();
    }
}

SecurityConfig配置类 (安全配置)

@EnableWebSecurity
public class SecurityConfig {

    private final String adminContextPath;

    public SecurityConfig(AdminServerProperties adminServerProperties) {
        this.adminContextPath = adminServerProperties.getContextPath();
    }

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
        SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
        successHandler.setTargetUrlParameter("redirectTo");
        successHandler.setDefaultTargetUrl(adminContextPath + "/");

        return httpSecurity
                .headers().frameOptions().disable()
                .and().authorizeRequests()
                // 放行 静态目录、登录、监控自身路径
                .antMatchers(adminContextPath + "/assets/**"
                    , adminContextPath + "/login"
                    , "/actuator"
                    , "/actuator/**"
                ).permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin().loginPage(adminContextPath + "/login")
                .successHandler(successHandler).and()
                .logout().logoutUrl(adminContextPath + "/logout")
                .and()
                .httpBasic().and()
                .csrf()
                .disable()
                .build();
    }

}

# ruoyi-admin模块配置

application.yml配置文件

--- # Actuator 监控端点的配置项
management:
  endpoints:
    web:
      exposure:
        # 监控所有端点
        include: '*'
  endpoint:
    health:
      # 总是展示健康细节
      show-details: ALWAYS
    logfile:
      # 日志信息目录
      external-file: ./logs/sys-console.log

application-{环境}.yml 配置文件

--- # 监控中心配置
spring.boot.admin.client:
  # 增加客户端开关
  enabled: true
  url: http://localhost:9090/admin
  instance:
    service-host-type: IP
  username: ruoyi
  password: 123456

# 拓展模块监控

拓展模块的服务一般情况是与主服务分开运行的 , 监控拓展模块的服务需要走一下流程配置

大致流程

  1. 引入依赖
  2. 配置追加端点监控
  3. 进入控制中心查看即可

引入依赖

<!-- 暴露端点 -->
<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>

配置文件追加端点监控

application.yml配置文件

--- # Actuator 监控端点的配置项
management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: ALWAYS
    logfile:
      external-file: ./logs/ruoyi-monitor-admin.log
      
--- # 客户端配置
spring.boot.admin.client:
  # 增加客户端开关
  enabled: true
  # 服务端地址
  url: http://localhost:9090/admin
  instance:
    service-host-type: IP
#ruoyi-vue-plus#监控中心

← ruoyi-vue-plus-任务调度 ruoyi-vue-plus-国际化→

最近更新
01
HTTPS自动续签
10-21
02
博客搭建-简化版(脚本)
10-20
03
ruoyi-vue-plus-部署篇
07-13
更多文章>
Theme by Vdoing | Copyright © 2019-2024 | 桂ICP备2022009417号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式