mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	add 集成 spring-boot-admin 全方位监控
This commit is contained in:
		@@ -33,6 +33,7 @@
 | 
			
		||||
* swagger 修改为 knife4j
 | 
			
		||||
* 集成 Hutool 5.X 并重写RuoYi部分功能
 | 
			
		||||
* 集成 Feign 接口化管理 Http 请求(如三方请求 支付,短信,推送等)
 | 
			
		||||
* 集成 spring-boot-admin 全方位监控
 | 
			
		||||
* 升级MybatisPlus 3.4.2
 | 
			
		||||
* 增加demo模块示例(给不会增加模块的小伙伴做参考)
 | 
			
		||||
* 同步升级 3.4.0
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										17
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								pom.xml
									
									
									
									
									
								
							@@ -31,6 +31,7 @@
 | 
			
		||||
        <hutool.version>5.5.8</hutool.version>
 | 
			
		||||
        <feign.version>2.2.6.RELEASE</feign.version>
 | 
			
		||||
        <feign-okhttp.version>11.0</feign-okhttp.version>
 | 
			
		||||
        <spring-boot-admin.version>2.3.1</spring-boot-admin.version>
 | 
			
		||||
    </properties>
 | 
			
		||||
	
 | 
			
		||||
    <!-- 依赖声明 -->
 | 
			
		||||
@@ -147,6 +148,22 @@
 | 
			
		||||
                <version>${feign-okhttp.version}</version>
 | 
			
		||||
            </dependency>
 | 
			
		||||
 | 
			
		||||
            <dependency>
 | 
			
		||||
                <groupId>de.codecentric</groupId>
 | 
			
		||||
                <artifactId>spring-boot-admin-starter-server</artifactId>
 | 
			
		||||
                <version>${spring-boot-admin.version}</version>
 | 
			
		||||
            </dependency>
 | 
			
		||||
            <dependency>
 | 
			
		||||
                <groupId>de.codecentric</groupId>
 | 
			
		||||
                <artifactId>spring-boot-admin-starter-client</artifactId>
 | 
			
		||||
                <version>${spring-boot-admin.version}</version>
 | 
			
		||||
            </dependency>
 | 
			
		||||
 | 
			
		||||
            <dependency>
 | 
			
		||||
                <groupId>org.springframework.boot</groupId>
 | 
			
		||||
                <artifactId>spring-boot-starter-actuator</artifactId>
 | 
			
		||||
            </dependency>
 | 
			
		||||
 | 
			
		||||
            <!-- 定时任务-->
 | 
			
		||||
            <dependency>
 | 
			
		||||
                <groupId>com.ruoyi</groupId>
 | 
			
		||||
 
 | 
			
		||||
@@ -43,8 +43,8 @@ spring:
 | 
			
		||||
                allow:
 | 
			
		||||
                url-pattern: /druid/*
 | 
			
		||||
                # 控制台管理用户名和密码
 | 
			
		||||
                login-username: 
 | 
			
		||||
                login-password: 
 | 
			
		||||
                login-username: ruoyi
 | 
			
		||||
                login-password: 123456
 | 
			
		||||
            filter:
 | 
			
		||||
                stat:
 | 
			
		||||
                    enabled: true
 | 
			
		||||
 
 | 
			
		||||
@@ -57,6 +57,7 @@ logging:
 | 
			
		||||
  level:
 | 
			
		||||
    com.ruoyi: @logging.level@
 | 
			
		||||
    org.springframework: warn
 | 
			
		||||
  config: classpath:logback.xml
 | 
			
		||||
 | 
			
		||||
# Spring配置
 | 
			
		||||
spring:
 | 
			
		||||
@@ -78,6 +79,33 @@ spring:
 | 
			
		||||
    restart:
 | 
			
		||||
      # 热部署开关
 | 
			
		||||
      enabled: true
 | 
			
		||||
  application:
 | 
			
		||||
    name: ruoyi-vue-plus
 | 
			
		||||
  boot:
 | 
			
		||||
    admin:
 | 
			
		||||
      # Spring Boot Admin Client 客户端的相关配置
 | 
			
		||||
      client:
 | 
			
		||||
        # 设置 Spring Boot Admin Server 地址
 | 
			
		||||
        url: http://localhost:${server.port}${spring.boot.admin.context-path}
 | 
			
		||||
        instance:
 | 
			
		||||
          prefer-ip: true # 注册实例时,优先使用 IP
 | 
			
		||||
#        username: ruoyi
 | 
			
		||||
#        password: 123456
 | 
			
		||||
      # Spring Boot Admin Server 服务端的相关配置
 | 
			
		||||
      context-path: /admin # 配置 Spring
 | 
			
		||||
 | 
			
		||||
# Actuator 监控端点的配置项
 | 
			
		||||
management:
 | 
			
		||||
  endpoints:
 | 
			
		||||
    web:
 | 
			
		||||
      # Actuator 提供的 API 接口的根目录。默认为 /actuator
 | 
			
		||||
      base-path: /actuator
 | 
			
		||||
      exposure:
 | 
			
		||||
        # 需要开放的端点。默认值只打开 health 和 info 两个端点。通过设置 * ,可以开放所有端点。
 | 
			
		||||
        include: '*'
 | 
			
		||||
  endpoint:
 | 
			
		||||
    logfile:
 | 
			
		||||
      external-file: ./logs/sys-console.log
 | 
			
		||||
 | 
			
		||||
# token配置
 | 
			
		||||
token:
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,19 @@
 | 
			
		||||
            <charset>utf-8</charset>
 | 
			
		||||
		</encoder>
 | 
			
		||||
	</appender>
 | 
			
		||||
 | 
			
		||||
    <!-- 控制台输出 -->
 | 
			
		||||
    <appender name="file_console" class="ch.qos.logback.core.FileAppender">
 | 
			
		||||
        <file>${log.path}/sys-console.log</file>
 | 
			
		||||
        <encoder>
 | 
			
		||||
            <pattern>${log.pattern}</pattern>
 | 
			
		||||
            <charset>utf-8</charset>
 | 
			
		||||
        </encoder>
 | 
			
		||||
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
 | 
			
		||||
            <!-- 过滤的级别 -->
 | 
			
		||||
            <level>INFO</level>
 | 
			
		||||
        </filter>
 | 
			
		||||
    </appender>
 | 
			
		||||
	
 | 
			
		||||
	<!-- 系统日志输出 -->
 | 
			
		||||
	<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
 | 
			
		||||
@@ -85,6 +98,7 @@
 | 
			
		||||
    <root level="info">
 | 
			
		||||
        <appender-ref ref="file_info" />
 | 
			
		||||
        <appender-ref ref="file_error" />
 | 
			
		||||
        <appender-ref ref="file_console" />
 | 
			
		||||
    </root>
 | 
			
		||||
	
 | 
			
		||||
	<!--系统用户操作日志-->
 | 
			
		||||
 
 | 
			
		||||
@@ -128,6 +128,15 @@
 | 
			
		||||
            <artifactId>feign-okhttp</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>
 | 
			
		||||
 | 
			
		||||
    </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -0,0 +1,24 @@
 | 
			
		||||
package com.ruoyi.framework.config;
 | 
			
		||||
 | 
			
		||||
import de.codecentric.boot.admin.server.config.EnableAdminServer;
 | 
			
		||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
 | 
			
		||||
import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
 | 
			
		||||
import org.springframework.boot.task.TaskExecutorBuilder;
 | 
			
		||||
import org.springframework.context.annotation.Bean;
 | 
			
		||||
import org.springframework.context.annotation.Configuration;
 | 
			
		||||
import org.springframework.context.annotation.Lazy;
 | 
			
		||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 | 
			
		||||
 | 
			
		||||
import java.util.concurrent.Executor;
 | 
			
		||||
 | 
			
		||||
@Configuration
 | 
			
		||||
@EnableAdminServer
 | 
			
		||||
public class AdminServerConfig {
 | 
			
		||||
 | 
			
		||||
    @Lazy
 | 
			
		||||
    @Bean(name = TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME)
 | 
			
		||||
    @ConditionalOnMissingBean(Executor.class)
 | 
			
		||||
    public ThreadPoolTaskExecutor applicationTaskExecutor(TaskExecutorBuilder builder) {
 | 
			
		||||
        return builder.build();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,5 +1,9 @@
 | 
			
		||||
package com.ruoyi.framework.config;
 | 
			
		||||
 | 
			
		||||
import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
 | 
			
		||||
import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
 | 
			
		||||
import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
 | 
			
		||||
import de.codecentric.boot.admin.server.config.AdminServerProperties;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.context.annotation.Bean;
 | 
			
		||||
import org.springframework.http.HttpMethod;
 | 
			
		||||
@@ -14,9 +18,6 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 | 
			
		||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
 | 
			
		||||
import org.springframework.security.web.authentication.logout.LogoutFilter;
 | 
			
		||||
import org.springframework.web.filter.CorsFilter;
 | 
			
		||||
import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
 | 
			
		||||
import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
 | 
			
		||||
import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * spring security配置
 | 
			
		||||
@@ -55,6 +56,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
 | 
			
		||||
     */
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private CorsFilter corsFilter;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private AdminServerProperties adminServerProperties;
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * 解决 无法直接注入 AuthenticationManager
 | 
			
		||||
@@ -113,6 +117,12 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
 | 
			
		||||
                .antMatchers("/webjars/**").anonymous()
 | 
			
		||||
                .antMatchers("/*/api-docs").anonymous()
 | 
			
		||||
                .antMatchers("/druid/**").anonymous()
 | 
			
		||||
                // Spring Boot Admin Server 的安全配置
 | 
			
		||||
                .antMatchers(adminServerProperties.getContextPath()).anonymous()
 | 
			
		||||
                .antMatchers(adminServerProperties.getContextPath() + "/**").anonymous()
 | 
			
		||||
                // Spring Boot Actuator 的安全配置
 | 
			
		||||
                .antMatchers("/actuator").anonymous()
 | 
			
		||||
                .antMatchers("/actuator/**").anonymous()
 | 
			
		||||
                // 除上面外的所有请求全部需要鉴权认证
 | 
			
		||||
                .anyRequest().authenticated()
 | 
			
		||||
                .and()
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										26
									
								
								ruoyi-ui/src/views/monitor/admin/index.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								ruoyi-ui/src/views/monitor/admin/index.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <div v-loading="loading" :style="'height:'+ height">
 | 
			
		||||
    <iframe :src="src" frameborder="no" style="width: 100%;height: 100%" scrolling="auto" />
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
<script>
 | 
			
		||||
export default {
 | 
			
		||||
  name: "Admin",
 | 
			
		||||
  data() {
 | 
			
		||||
    return {
 | 
			
		||||
      src: process.env.VUE_APP_BASE_API + "/admin",
 | 
			
		||||
      height: document.documentElement.clientHeight - 94.5 + "px;",
 | 
			
		||||
      loading: true
 | 
			
		||||
    };
 | 
			
		||||
  },
 | 
			
		||||
  mounted: function() {
 | 
			
		||||
    setTimeout(() => {
 | 
			
		||||
      this.loading = false;
 | 
			
		||||
    }, 230);
 | 
			
		||||
    const that = this;
 | 
			
		||||
    window.onresize = function temp() {
 | 
			
		||||
      that.height = document.documentElement.clientHeight - 94.5 + "px;";
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
</script>
 | 
			
		||||
@@ -178,6 +178,9 @@ insert into sys_menu values('113',  '缓存监控', '2',   '5', 'cache',      'm
 | 
			
		||||
insert into sys_menu values('114',  '表单构建', '3',   '1', 'build',      'tool/build/index',         1, 0, 'C', '0', '0', 'tool:build:list',         'build',         'admin', sysdate(), '', null, '表单构建菜单');
 | 
			
		||||
insert into sys_menu values('115',  '代码生成', '3',   '2', 'gen',        'tool/gen/index',           1, 0, 'C', '0', '0', 'tool:gen:list',           'code',          'admin', sysdate(), '', null, '代码生成菜单');
 | 
			
		||||
insert into sys_menu values('116',  '系统接口', '3',   '3', 'swagger',    'tool/swagger/index',       1, 0, 'C', '0', '0', 'tool:swagger:list',       'swagger',       'admin', sysdate(), '', null, '系统接口菜单');
 | 
			
		||||
-- springboot-admin监控
 | 
			
		||||
insert into sys_menu values('117',  'Admin监控', '2',  '5', 'Admin',      'monitor/admin/index',      1, 0, 'C', '0', '0', 'monitor:admin:list',      'dashboard',     'admin', sysdate(), '', null, 'Admin监控菜单');
 | 
			
		||||
 | 
			
		||||
-- 三级菜单
 | 
			
		||||
insert into sys_menu values('500',  '操作日志', '108', '1', 'operlog',    'monitor/operlog/index',    1, 0, 'C', '0', '0', 'monitor:operlog:list',    'form',          'admin', sysdate(), '', null, '操作日志菜单');
 | 
			
		||||
insert into sys_menu values('501',  '登录日志', '108', '2', 'logininfor', 'monitor/logininfor/index', 1, 0, 'C', '0', '0', 'monitor:logininfor:list', 'logininfor',    'admin', sysdate(), '', null, '登录日志菜单');
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user