Compare commits
No commits in common. "c731409c06626f7d64e20b93f023870c5c06d4b9" and "35775b0fcc3e92e3a9b7a7df822bd658461bacb3" have entirely different histories.
c731409c06
...
35775b0fcc
@ -1,65 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>org.leocoder.thin</groupId>
|
|
||||||
<artifactId>coder-common-thin-backend</artifactId>
|
|
||||||
<version>${revision}</version>
|
|
||||||
<relativePath>../../pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<name>coder-common-thin-monitor</name>
|
|
||||||
<artifactId>coder-common-thin-monitor</artifactId>
|
|
||||||
<description>系统监控模块:服务器资源监控、Redis监控、缓存管理等功能</description>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!-- 公共模块 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.leocoder.thin</groupId>
|
|
||||||
<artifactId>coder-common-thin-common</artifactId>
|
|
||||||
<version>${revision}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- 数据统一返回、全局异常以及限流、数据脱敏、重复提交等插件 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.leocoder.thin</groupId>
|
|
||||||
<artifactId>coder-common-thin-resultex</artifactId>
|
|
||||||
<version>${revision}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Sa-Token组件 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.leocoder.thin</groupId>
|
|
||||||
<artifactId>coder-common-thin-sa-token</artifactId>
|
|
||||||
<version>${revision}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- SpringDoc OpenAPI 3.0 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springdoc</groupId>
|
|
||||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Spring Boot Starter Data Redis -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- OSHI - 系统硬件信息库 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.oshi</groupId>
|
|
||||||
<artifactId>oshi-core</artifactId>
|
|
||||||
<version>6.4.10</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Apache Commons Lang3 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-lang3</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@ -1,134 +0,0 @@
|
|||||||
package org.leocoder.thin.monitor.controller;
|
|
||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.leocoder.thin.monitor.pojo.server.SysCache;
|
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Leocoder
|
|
||||||
* @description [缓存管理]
|
|
||||||
*/
|
|
||||||
@Tag(name = "缓存管理", description = "Redis缓存管理,包括缓存查看、删除、清空等操作")
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/coder/monitor")
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class CacheController {
|
|
||||||
|
|
||||||
private final RedisTemplate<String, String> redisTemplate;
|
|
||||||
|
|
||||||
private final static List<SysCache> cacheList = new ArrayList<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
cacheList.add(new SysCache("Authorization:login:session:", "用户登录信息"));
|
|
||||||
cacheList.add(new SysCache("coderDict:", "数据字典"));
|
|
||||||
cacheList.add(new SysCache("coderCaptchaCodes:", "验证码"));
|
|
||||||
cacheList.add(new SysCache("repeat_submit:", "防重提交"));
|
|
||||||
cacheList.add(new SysCache("rate_limit:", "限流处理"));
|
|
||||||
cacheList.add(new SysCache("pwd_error:", "密码错误次数"));
|
|
||||||
cacheList.add(new SysCache("coderBlacklistIp:", "黑名单IP"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [查询Redis缓存所有Key]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
@Operation(summary = "查询Redis缓存所有Key", description = "获取系统中所有缓存分类的Key列表")
|
|
||||||
@SaCheckPermission("monitor:cache:list")
|
|
||||||
@GetMapping("/cache/getRedisCache")
|
|
||||||
public List<SysCache> getRedisInformation() {
|
|
||||||
return cacheList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [查询Redis缓存键名列表]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
@Operation(summary = "查询Redis缓存键名列表", description = "根据缓存名称获取对应的键名列表")
|
|
||||||
@SaCheckPermission("monitor:cache:list")
|
|
||||||
@GetMapping("/cache/getCacheKeys/{cacheName}")
|
|
||||||
public TreeSet<Object> getCacheKeys(@PathVariable("cacheName") String cacheName) {
|
|
||||||
Set<String> cacheKeys = redisTemplate.keys(cacheName + "*");
|
|
||||||
if (ObjectUtils.isEmpty(cacheKeys)) {
|
|
||||||
return new TreeSet<>();
|
|
||||||
}
|
|
||||||
return new TreeSet<>(cacheKeys);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取Redis缓存内容]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
@Operation(summary = "获取Redis缓存内容", description = "根据缓存键名获取缓存内容和过期时间")
|
|
||||||
@SaCheckPermission("monitor:cache:list")
|
|
||||||
@PostMapping("/cache/getValue")
|
|
||||||
public SysCache getCacheValue(@RequestBody SysCache sysCache) {
|
|
||||||
Boolean hasKey = redisTemplate.hasKey(sysCache.getCacheKey());
|
|
||||||
if (!hasKey) {
|
|
||||||
return new SysCache(sysCache.getCacheName(), sysCache.getCacheKey(), "", "");
|
|
||||||
}
|
|
||||||
String cacheValue = redisTemplate.opsForValue().get(sysCache.getCacheKey());
|
|
||||||
Long cacheTime = redisTemplate.getExpire(sysCache.getCacheKey(), TimeUnit.SECONDS);
|
|
||||||
String formatCacheTime = "";
|
|
||||||
if (cacheTime != null) {
|
|
||||||
if (cacheTime == -1L) {
|
|
||||||
formatCacheTime = "不过期";
|
|
||||||
} else {
|
|
||||||
int hours = (int) (cacheTime / 3600);
|
|
||||||
int minutes = (int) ((cacheTime % 3600) / 60);
|
|
||||||
int seconds = (int) (cacheTime % 60);
|
|
||||||
formatCacheTime = String.format("%02d小时%02d分钟%02d秒", hours, minutes, seconds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new SysCache(sysCache.getCacheName(), sysCache.getCacheKey(), cacheValue, formatCacheTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [删除Redis指定名称缓存]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
@Operation(summary = "删除Redis指定名称缓存", description = "根据缓存名称前缀删除所有相关缓存")
|
|
||||||
@SaCheckPermission("monitor:cache:delete")
|
|
||||||
@PostMapping("/cache/deleteCacheName/{cacheName}")
|
|
||||||
public void deleteCacheName(@PathVariable("cacheName") String cacheName) {
|
|
||||||
Collection<String> cacheKeys = redisTemplate.keys(cacheName + "*");
|
|
||||||
if (ObjectUtils.isNotEmpty(cacheKeys)) {
|
|
||||||
redisTemplate.delete(cacheKeys);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [删除Redis指定键名缓存]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
@Operation(summary = "删除Redis指定键名缓存", description = "根据具体的缓存键名删除单个缓存")
|
|
||||||
@SaCheckPermission("monitor:cache:delete")
|
|
||||||
@PostMapping("/cache/deleteCacheKey")
|
|
||||||
public void deleteCacheKey(@RequestBody SysCache sysCache) {
|
|
||||||
if (StringUtils.isNotBlank(sysCache.getCacheKey())) {
|
|
||||||
redisTemplate.delete(sysCache.getCacheKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [删除Redis所有信息]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
@Operation(summary = "删除Redis所有信息", description = "清空Redis中的所有缓存数据(谨慎操作)")
|
|
||||||
@SaCheckPermission("monitor:cache:clear")
|
|
||||||
@PostMapping("/cache/deleteCacheAll")
|
|
||||||
public void deleteCacheAll() {
|
|
||||||
Collection<String> cacheKeys = redisTemplate.keys("*");
|
|
||||||
if (ObjectUtils.isNotEmpty(cacheKeys)) {
|
|
||||||
redisTemplate.delete(cacheKeys);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,63 +0,0 @@
|
|||||||
package org.leocoder.thin.monitor.controller;
|
|
||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.data.redis.core.RedisCallback;
|
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Leocoder
|
|
||||||
* @description [Redis监控]
|
|
||||||
*/
|
|
||||||
@Tag(name = "Redis监控", description = "Redis数据库监控,包括连接信息、内存使用、命令统计等")
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/coder/monitor")
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class RedisController {
|
|
||||||
|
|
||||||
private final RedisTemplate<String, String> redisTemplate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取Redis监控信息]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
@Operation(summary = "获取Redis监控信息", description = "获取Redis服务器监控数据,包括服务信息、内存使用、连接数、命令统计等")
|
|
||||||
@SaCheckPermission("monitor:redis:list")
|
|
||||||
@GetMapping("/redis/getRedisInformation")
|
|
||||||
public Map<String, Object> getRedisInformation() {
|
|
||||||
try {
|
|
||||||
Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info());
|
|
||||||
Properties commandStats = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info("commandstats"));
|
|
||||||
Object dbSize = redisTemplate.execute((RedisCallback<Object>) connection -> connection.dbSize());
|
|
||||||
|
|
||||||
Map<String, Object> result = new HashMap<>(3);
|
|
||||||
result.put("info", info);
|
|
||||||
result.put("dbSize", dbSize);
|
|
||||||
|
|
||||||
List<Map<String, String>> pieList = new ArrayList<>();
|
|
||||||
if (commandStats != null) {
|
|
||||||
commandStats.stringPropertyNames().forEach(key -> {
|
|
||||||
Map<String, String> data = new HashMap<>(2);
|
|
||||||
String propertyValue = commandStats.getProperty(key);
|
|
||||||
data.put("name", StringUtils.removeStart(key, "cmdstat_"));
|
|
||||||
data.put("value", StringUtils.substringBetween(propertyValue, "calls=", ",usec"));
|
|
||||||
pieList.add(data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
result.put("commandStats", pieList);
|
|
||||||
return result;
|
|
||||||
} catch (Exception e) {
|
|
||||||
Map<String, Object> errorResult = new HashMap<>();
|
|
||||||
errorResult.put("error", "获取Redis监控信息失败: " + e.getMessage());
|
|
||||||
return errorResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
package org.leocoder.thin.monitor.controller;
|
|
||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.leocoder.thin.monitor.pojo.server.Server;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Leocoder
|
|
||||||
* @description [服务器监控]
|
|
||||||
*/
|
|
||||||
@Tag(name = "服务器监控", description = "系统服务器资源监控,包括CPU、内存、磁盘、JVM等信息")
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/coder/monitor")
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class ServerController {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取服务器监控信息]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
@Operation(summary = "获取服务器监控信息", description = "获取服务器实时监控数据,包括CPU使用率、内存使用情况、磁盘空间、JVM状态等")
|
|
||||||
@SaCheckPermission("monitor:server:list")
|
|
||||||
@GetMapping("/server/getServerInformation")
|
|
||||||
public Server getServerInformation() {
|
|
||||||
Server server = new Server();
|
|
||||||
server.copyTo();
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,120 +0,0 @@
|
|||||||
package org.leocoder.thin.monitor.pojo.server;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.RoundingMode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Leocoder
|
|
||||||
* @description [CPU相关信息]
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class Cpu {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 核心数
|
|
||||||
*/
|
|
||||||
private int cpuNum;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CPU总的使用率
|
|
||||||
*/
|
|
||||||
private double total;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CPU系统使用率
|
|
||||||
*/
|
|
||||||
private double sys;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CPU用户使用率
|
|
||||||
*/
|
|
||||||
private double used;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CPU当前等待率
|
|
||||||
*/
|
|
||||||
private double wait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CPU当前空闲率
|
|
||||||
*/
|
|
||||||
private double free;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取CPU使用率]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public double getCpuUsage() {
|
|
||||||
if (total > 0) {
|
|
||||||
return multiply(divide(total - free, total, 4), 100);
|
|
||||||
}
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取CPU系统使用率]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public double getSysUsage() {
|
|
||||||
if (total > 0) {
|
|
||||||
return multiply(divide(sys, total, 4), 100);
|
|
||||||
}
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取CPU用户使用率]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public double getUserUsage() {
|
|
||||||
if (total > 0) {
|
|
||||||
return multiply(divide(used, total, 4), 100);
|
|
||||||
}
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取CPU等待率]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public double getWaitUsage() {
|
|
||||||
if (total > 0) {
|
|
||||||
return multiply(divide(wait, total, 4), 100);
|
|
||||||
}
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取CPU空闲率]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public double getFreeUsage() {
|
|
||||||
if (total > 0) {
|
|
||||||
return multiply(divide(free, total, 4), 100);
|
|
||||||
}
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 精确的除法运算
|
|
||||||
*/
|
|
||||||
private static double divide(double v1, double v2, int scale) {
|
|
||||||
if (scale < 0) {
|
|
||||||
throw new IllegalArgumentException("精确度不能小于0");
|
|
||||||
}
|
|
||||||
BigDecimal b1 = BigDecimal.valueOf(v1);
|
|
||||||
BigDecimal b2 = BigDecimal.valueOf(v2);
|
|
||||||
return b1.divide(b2, scale, RoundingMode.HALF_UP).doubleValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 精确的乘法运算
|
|
||||||
*/
|
|
||||||
private static double multiply(double v1, double v2) {
|
|
||||||
BigDecimal b1 = BigDecimal.valueOf(v1);
|
|
||||||
BigDecimal b2 = BigDecimal.valueOf(v2);
|
|
||||||
return b1.multiply(b2).doubleValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,155 +0,0 @@
|
|||||||
package org.leocoder.thin.monitor.pojo.server;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.lang.management.ManagementFactory;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.RoundingMode;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Leocoder
|
|
||||||
* @description [JVM相关信息]
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class Jvm {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 当前JVM占用的内存总数(M)
|
|
||||||
*/
|
|
||||||
private long total;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JVM最大可用内存总数(M)
|
|
||||||
*/
|
|
||||||
private long max;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JVM空闲内存(M)
|
|
||||||
*/
|
|
||||||
private long free;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JDK版本
|
|
||||||
*/
|
|
||||||
private String version;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JDK路径
|
|
||||||
*/
|
|
||||||
private String home;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取JVM已用内存]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public long getUsed() {
|
|
||||||
return total - free;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取JVM内存使用率]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public double getUsage() {
|
|
||||||
if (total > 0) {
|
|
||||||
return multiply(divide(getUsed(), total, 4), 100);
|
|
||||||
}
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取总内存(格式化)]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public String getTotalStr() {
|
|
||||||
return convertFileSize(total);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取已用内存(格式化)]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public String getUsedStr() {
|
|
||||||
return convertFileSize(getUsed());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取剩余内存(格式化)]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public String getFreeStr() {
|
|
||||||
return convertFileSize(free);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取最大内存(格式化)]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public String getMaxStr() {
|
|
||||||
return convertFileSize(max);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取JVM启动时间]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public String getStartTime() {
|
|
||||||
long startTime = ManagementFactory.getRuntimeMXBean().getStartTime();
|
|
||||||
return new Date(startTime).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取JVM运行时间]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public String getRunTime() {
|
|
||||||
long runTime = ManagementFactory.getRuntimeMXBean().getUptime();
|
|
||||||
long day = runTime / (24 * 60 * 60 * 1000);
|
|
||||||
long hour = (runTime / (60 * 60 * 1000)) - (day * 24);
|
|
||||||
long minute = (runTime / (60 * 1000)) - (day * 24 * 60) - (hour * 60);
|
|
||||||
long second = (runTime / 1000) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
|
|
||||||
return String.format("%d天%d小时%d分钟%d秒", day, hour, minute, second);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 字节转换
|
|
||||||
*/
|
|
||||||
private String convertFileSize(long size) {
|
|
||||||
long kb = 1024;
|
|
||||||
long mb = kb * 1024;
|
|
||||||
long gb = mb * 1024;
|
|
||||||
if (size >= gb) {
|
|
||||||
return String.format("%.1f GB", (float) size / gb);
|
|
||||||
} else if (size >= mb) {
|
|
||||||
float f = (float) size / mb;
|
|
||||||
return String.format(f > 100 ? "%.0f MB" : "%.1f MB", f);
|
|
||||||
} else if (size >= kb) {
|
|
||||||
float f = (float) size / kb;
|
|
||||||
return String.format(f > 100 ? "%.0f KB" : "%.1f KB", f);
|
|
||||||
} else {
|
|
||||||
return String.format("%d B", size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 精确的除法运算
|
|
||||||
*/
|
|
||||||
private static double divide(long v1, long v2, int scale) {
|
|
||||||
if (scale < 0) {
|
|
||||||
throw new IllegalArgumentException("精确度不能小于0");
|
|
||||||
}
|
|
||||||
BigDecimal b1 = BigDecimal.valueOf(v1);
|
|
||||||
BigDecimal b2 = BigDecimal.valueOf(v2);
|
|
||||||
return b1.divide(b2, scale, RoundingMode.HALF_UP).doubleValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 精确的乘法运算
|
|
||||||
*/
|
|
||||||
private static double multiply(double v1, double v2) {
|
|
||||||
BigDecimal b1 = BigDecimal.valueOf(v1);
|
|
||||||
BigDecimal b2 = BigDecimal.valueOf(v2);
|
|
||||||
return b1.multiply(b2).doubleValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,105 +0,0 @@
|
|||||||
package org.leocoder.thin.monitor.pojo.server;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.RoundingMode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Leocoder
|
|
||||||
* @description [内存相关信息]
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class Mem {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 内存总量
|
|
||||||
*/
|
|
||||||
private long total;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 已用内存
|
|
||||||
*/
|
|
||||||
private long used;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 剩余内存
|
|
||||||
*/
|
|
||||||
private long free;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取内存使用率]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public double getUsage() {
|
|
||||||
if (total > 0) {
|
|
||||||
return multiply(divide(used, total, 4), 100);
|
|
||||||
}
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取总内存(格式化)]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public String getTotalStr() {
|
|
||||||
return convertFileSize(total);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取已用内存(格式化)]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public String getUsedStr() {
|
|
||||||
return convertFileSize(used);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取剩余内存(格式化)]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public String getFreeStr() {
|
|
||||||
return convertFileSize(free);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 字节转换
|
|
||||||
*/
|
|
||||||
private String convertFileSize(long size) {
|
|
||||||
long kb = 1024;
|
|
||||||
long mb = kb * 1024;
|
|
||||||
long gb = mb * 1024;
|
|
||||||
if (size >= gb) {
|
|
||||||
return String.format("%.1f GB", (float) size / gb);
|
|
||||||
} else if (size >= mb) {
|
|
||||||
float f = (float) size / mb;
|
|
||||||
return String.format(f > 100 ? "%.0f MB" : "%.1f MB", f);
|
|
||||||
} else if (size >= kb) {
|
|
||||||
float f = (float) size / kb;
|
|
||||||
return String.format(f > 100 ? "%.0f KB" : "%.1f KB", f);
|
|
||||||
} else {
|
|
||||||
return String.format("%d B", size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 精确的除法运算
|
|
||||||
*/
|
|
||||||
private static double divide(long v1, long v2, int scale) {
|
|
||||||
if (scale < 0) {
|
|
||||||
throw new IllegalArgumentException("精确度不能小于0");
|
|
||||||
}
|
|
||||||
BigDecimal b1 = BigDecimal.valueOf(v1);
|
|
||||||
BigDecimal b2 = BigDecimal.valueOf(v2);
|
|
||||||
return b1.divide(b2, scale, RoundingMode.HALF_UP).doubleValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 精确的乘法运算
|
|
||||||
*/
|
|
||||||
private static double multiply(double v1, double v2) {
|
|
||||||
BigDecimal b1 = BigDecimal.valueOf(v1);
|
|
||||||
BigDecimal b2 = BigDecimal.valueOf(v2);
|
|
||||||
return b1.multiply(b2).doubleValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,202 +0,0 @@
|
|||||||
package org.leocoder.thin.monitor.pojo.server;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.leocoder.thin.common.utils.ip.IpUtil;
|
|
||||||
import oshi.SystemInfo;
|
|
||||||
import oshi.hardware.CentralProcessor;
|
|
||||||
import oshi.hardware.CentralProcessor.TickType;
|
|
||||||
import oshi.hardware.GlobalMemory;
|
|
||||||
import oshi.hardware.HardwareAbstractionLayer;
|
|
||||||
import oshi.software.os.FileSystem;
|
|
||||||
import oshi.software.os.OSFileStore;
|
|
||||||
import oshi.software.os.OperatingSystem;
|
|
||||||
import oshi.util.Util;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.RoundingMode;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Leocoder
|
|
||||||
* @description [服务器相关信息]
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class Server {
|
|
||||||
|
|
||||||
private static final int OSHI_WAIT_SECOND = 1000;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CPU相关信息
|
|
||||||
*/
|
|
||||||
private Cpu cpu = new Cpu();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 内存相关信息
|
|
||||||
*/
|
|
||||||
private Mem mem = new Mem();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JVM相关信息
|
|
||||||
*/
|
|
||||||
private Jvm jvm = new Jvm();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 服务器相关信息
|
|
||||||
*/
|
|
||||||
private Sys sys = new Sys();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 磁盘相关信息
|
|
||||||
*/
|
|
||||||
private List<SysFile> sysFiles = new LinkedList<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description [获取服务器信息]
|
|
||||||
* @author Leocoder
|
|
||||||
*/
|
|
||||||
public void copyTo() {
|
|
||||||
try {
|
|
||||||
SystemInfo si = new SystemInfo();
|
|
||||||
HardwareAbstractionLayer hal = si.getHardware();
|
|
||||||
|
|
||||||
setCpuInfo(hal.getProcessor());
|
|
||||||
setMemInfo(hal.getMemory());
|
|
||||||
setSysInfo();
|
|
||||||
setJvmInfo();
|
|
||||||
setSysFiles(si.getOperatingSystem());
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.err.println("获取服务器信息失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置CPU信息
|
|
||||||
*/
|
|
||||||
private void setCpuInfo(CentralProcessor processor) {
|
|
||||||
// CPU信息
|
|
||||||
long[] prevTicks = processor.getSystemCpuLoadTicks();
|
|
||||||
Util.sleep(OSHI_WAIT_SECOND);
|
|
||||||
long[] ticks = processor.getSystemCpuLoadTicks();
|
|
||||||
long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
|
|
||||||
long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()];
|
|
||||||
long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()];
|
|
||||||
long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()];
|
|
||||||
long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
|
|
||||||
long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
|
|
||||||
long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()];
|
|
||||||
long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
|
|
||||||
long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
|
|
||||||
|
|
||||||
cpu.setCpuNum(processor.getLogicalProcessorCount());
|
|
||||||
cpu.setTotal(totalCpu);
|
|
||||||
cpu.setSys(cSys);
|
|
||||||
cpu.setUsed(user);
|
|
||||||
cpu.setWait(iowait);
|
|
||||||
cpu.setFree(idle);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置内存信息
|
|
||||||
*/
|
|
||||||
private void setMemInfo(GlobalMemory memory) {
|
|
||||||
mem.setTotal(memory.getTotal());
|
|
||||||
mem.setUsed(memory.getTotal() - memory.getAvailable());
|
|
||||||
mem.setFree(memory.getAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置服务器信息
|
|
||||||
*/
|
|
||||||
private void setSysInfo() {
|
|
||||||
Properties props = System.getProperties();
|
|
||||||
sys.setComputerName(IpUtil.getHostName());
|
|
||||||
sys.setComputerIp(IpUtil.getHostIp());
|
|
||||||
sys.setOsName(props.getProperty("os.name"));
|
|
||||||
sys.setOsArch(props.getProperty("os.arch"));
|
|
||||||
sys.setUserDir(props.getProperty("user.dir"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置Java虚拟机
|
|
||||||
*/
|
|
||||||
private void setJvmInfo() {
|
|
||||||
Properties props = System.getProperties();
|
|
||||||
jvm.setTotal(Runtime.getRuntime().totalMemory());
|
|
||||||
jvm.setMax(Runtime.getRuntime().maxMemory());
|
|
||||||
jvm.setFree(Runtime.getRuntime().freeMemory());
|
|
||||||
jvm.setVersion(props.getProperty("java.version"));
|
|
||||||
jvm.setHome(props.getProperty("java.home"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置磁盘信息
|
|
||||||
*/
|
|
||||||
private void setSysFiles(OperatingSystem os) {
|
|
||||||
FileSystem fileSystem = os.getFileSystem();
|
|
||||||
List<OSFileStore> fsArray = fileSystem.getFileStores();
|
|
||||||
for (OSFileStore fs : fsArray) {
|
|
||||||
long free = fs.getUsableSpace();
|
|
||||||
long total = fs.getTotalSpace();
|
|
||||||
long used = total - free;
|
|
||||||
SysFile sysFile = new SysFile();
|
|
||||||
sysFile.setDirName(fs.getMount());
|
|
||||||
sysFile.setSysTypeName(fs.getType());
|
|
||||||
sysFile.setTypeName(fs.getName());
|
|
||||||
sysFile.setTotal(convertFileSize(total));
|
|
||||||
sysFile.setFree(convertFileSize(free));
|
|
||||||
sysFile.setUsed(convertFileSize(used));
|
|
||||||
if (total > 0) {
|
|
||||||
sysFile.setUsage(multiply(divide(used, total, 4), 100));
|
|
||||||
} else {
|
|
||||||
sysFile.setUsage(0.0);
|
|
||||||
}
|
|
||||||
sysFiles.add(sysFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 字节转换
|
|
||||||
*
|
|
||||||
* @param size 字节大小
|
|
||||||
* @return 转换后值
|
|
||||||
*/
|
|
||||||
public String convertFileSize(long size) {
|
|
||||||
long kb = 1024;
|
|
||||||
long mb = kb * 1024;
|
|
||||||
long gb = mb * 1024;
|
|
||||||
if (size >= gb) {
|
|
||||||
return String.format("%.1f GB", (float) size / gb);
|
|
||||||
} else if (size >= mb) {
|
|
||||||
float f = (float) size / mb;
|
|
||||||
return String.format(f > 100 ? "%.0f MB" : "%.1f MB", f);
|
|
||||||
} else if (size >= kb) {
|
|
||||||
float f = (float) size / kb;
|
|
||||||
return String.format(f > 100 ? "%.0f KB" : "%.1f KB", f);
|
|
||||||
} else {
|
|
||||||
return String.format("%d B", size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 精确的除法运算
|
|
||||||
*/
|
|
||||||
private static double divide(long v1, long v2, int scale) {
|
|
||||||
if (scale < 0) {
|
|
||||||
throw new IllegalArgumentException("精确度不能小于0");
|
|
||||||
}
|
|
||||||
BigDecimal b1 = BigDecimal.valueOf(v1);
|
|
||||||
BigDecimal b2 = BigDecimal.valueOf(v2);
|
|
||||||
return b1.divide(b2, scale, RoundingMode.HALF_UP).doubleValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 精确的乘法运算
|
|
||||||
*/
|
|
||||||
private static double multiply(double v1, double v2) {
|
|
||||||
BigDecimal b1 = BigDecimal.valueOf(v1);
|
|
||||||
BigDecimal b2 = BigDecimal.valueOf(v2);
|
|
||||||
return b1.multiply(b2).doubleValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
package org.leocoder.thin.monitor.pojo.server;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Leocoder
|
|
||||||
* @description [系统相关信息]
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class Sys {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 服务器名称
|
|
||||||
*/
|
|
||||||
private String computerName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 服务器IP
|
|
||||||
*/
|
|
||||||
private String computerIp;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 项目路径
|
|
||||||
*/
|
|
||||||
private String userDir;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 操作系统
|
|
||||||
*/
|
|
||||||
private String osName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统架构
|
|
||||||
*/
|
|
||||||
private String osArch;
|
|
||||||
}
|
|
||||||
@ -1,52 +0,0 @@
|
|||||||
package org.leocoder.thin.monitor.pojo.server;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Leocoder
|
|
||||||
* @description [缓存信息]
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class SysCache {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存名称
|
|
||||||
*/
|
|
||||||
private String cacheName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存键名
|
|
||||||
*/
|
|
||||||
private String cacheKey;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存内容
|
|
||||||
*/
|
|
||||||
private String cacheValue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存过期时间
|
|
||||||
*/
|
|
||||||
private String expireTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 备注信息
|
|
||||||
*/
|
|
||||||
private String remark;
|
|
||||||
|
|
||||||
public SysCache(String cacheName, String remark) {
|
|
||||||
this.cacheName = cacheName;
|
|
||||||
this.remark = remark;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SysCache(String cacheName, String cacheKey, String cacheValue, String expireTime) {
|
|
||||||
this.cacheName = cacheName;
|
|
||||||
this.cacheKey = cacheKey;
|
|
||||||
this.cacheValue = cacheValue;
|
|
||||||
this.expireTime = expireTime;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,46 +0,0 @@
|
|||||||
package org.leocoder.thin.monitor.pojo.server;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Leocoder
|
|
||||||
* @description [系统文件相关信息]
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class SysFile {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 盘符路径
|
|
||||||
*/
|
|
||||||
private String dirName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 盘符类型
|
|
||||||
*/
|
|
||||||
private String sysTypeName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件类型
|
|
||||||
*/
|
|
||||||
private String typeName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 总大小
|
|
||||||
*/
|
|
||||||
private String total;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 剩余大小
|
|
||||||
*/
|
|
||||||
private String free;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 已经使用量
|
|
||||||
*/
|
|
||||||
private String used;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 资源的使用率
|
|
||||||
*/
|
|
||||||
private double usage;
|
|
||||||
}
|
|
||||||
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>coder-common-thin-system</module>
|
<module>coder-common-thin-system</module>
|
||||||
<module>coder-common-thin-monitor</module>
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@ -56,11 +56,11 @@
|
|||||||
<!-- <version>${revision}</version> -->
|
<!-- <version>${revision}</version> -->
|
||||||
<!-- </dependency> -->
|
<!-- </dependency> -->
|
||||||
<!-- 监控模块 -->
|
<!-- 监控模块 -->
|
||||||
<dependency>
|
<!-- <dependency> -->
|
||||||
<groupId>org.leocoder.thin</groupId>
|
<!-- <groupId>org.leocoder.thin</groupId> -->
|
||||||
<artifactId>coder-common-thin-monitor</artifactId>
|
<!-- <artifactId>coder-common-thin-monitor</artifactId> -->
|
||||||
<version>${revision}</version>
|
<!-- <version>${revision}</version> -->
|
||||||
</dependency>
|
<!-- </dependency> -->
|
||||||
<!-- 热榜API模块 -->
|
<!-- 热榜API模块 -->
|
||||||
<!-- <dependency> -->
|
<!-- <dependency> -->
|
||||||
<!-- <groupId>org.leocoder.thin</groupId> -->
|
<!-- <groupId>org.leocoder.thin</groupId> -->
|
||||||
|
|||||||
@ -1,181 +0,0 @@
|
|||||||
-- ============================================================================
|
|
||||||
-- 系统监控模块权限菜单配置 SQL 脚本
|
|
||||||
-- 作者: Leocoder
|
|
||||||
-- 创建时间: 2025-09-27
|
|
||||||
-- 描述: 为系统监控功能配置完整的菜单权限系统
|
|
||||||
-- ============================================================================
|
|
||||||
|
|
||||||
-- ----------------------------
|
|
||||||
-- 系统监控菜单结构
|
|
||||||
-- ----------------------------
|
|
||||||
|
|
||||||
-- 1. 系统监控顶级菜单(如果不存在)
|
|
||||||
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`)
|
|
||||||
SELECT 2000, '系统监控', 'System Monitor', 0, '1', '/monitor', 'monitorPage', '', 'Monitor', 'monitor:auth', '0', NULL, '1', '', '0', '1', '1', '1', 8, 'system', NOW(), 'system', NOW()
|
|
||||||
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `menu_id` = 2000);
|
|
||||||
|
|
||||||
-- 2. 服务器监控菜单
|
|
||||||
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`)
|
|
||||||
VALUES (2010, '服务器监控', 'Server Monitor', 2000, '2', '/monitor/server', 'serverMonitorPage', 'monitor/server/index', 'Platform', 'monitor:server:list', '0', NULL, '1', '', '1', '1', '1', '1', 1, 'system', NOW(), 'system', NOW());
|
|
||||||
|
|
||||||
-- 3. Redis监控菜单
|
|
||||||
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`)
|
|
||||||
VALUES (2011, 'Redis监控', 'Redis Monitor', 2000, '2', '/monitor/redis', 'redisMonitorPage', 'monitor/redis/index', 'Connection', 'monitor:redis:list', '0', NULL, '1', '', '1', '1', '1', '1', 2, 'system', NOW(), 'system', NOW());
|
|
||||||
|
|
||||||
-- 4. 缓存管理菜单
|
|
||||||
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`)
|
|
||||||
VALUES (2012, '缓存管理', 'Cache Management', 2000, '2', '/monitor/cache', 'cacheManagePage', 'monitor/cache/index', 'Coin', 'monitor:cache:list', '0', NULL, '1', '', '1', '1', '1', '1', 3, 'system', NOW(), 'system', NOW());
|
|
||||||
|
|
||||||
-- 5. 操作日志菜单(如果需要)
|
|
||||||
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`)
|
|
||||||
SELECT 2013, '操作日志', 'Operation Logs', 2000, '2', '/monitor/operlog', 'operLogPage', 'monitor/operlog/index', 'Document', 'monitor:operlog:list', '0', NULL, '1', '', '1', '1', '1', '1', 4, 'system', NOW(), 'system', NOW()
|
|
||||||
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `menu_id` = 2013);
|
|
||||||
|
|
||||||
-- 6. 登录日志菜单(如果需要)
|
|
||||||
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`)
|
|
||||||
SELECT 2014, '登录日志', 'Login Logs', 2000, '2', '/monitor/loginlog', 'loginLogPage', 'monitor/loginlog/index', 'Key', 'monitor:loginlog:list', '0', NULL, '1', '', '1', '1', '1', '1', 5, 'system', NOW(), 'system', NOW()
|
|
||||||
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `menu_id` = 2014);
|
|
||||||
|
|
||||||
-- 7. 定时任务菜单(如果需要)
|
|
||||||
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`)
|
|
||||||
SELECT 2015, '定时任务', 'Scheduled Jobs', 2000, '2', '/monitor/job', 'jobPage', 'monitor/job/index', 'Timer', 'monitor:job:list', '0', NULL, '1', '', '1', '1', '1', '1', 6, 'system', NOW(), 'system', NOW()
|
|
||||||
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `menu_id` = 2015);
|
|
||||||
|
|
||||||
-- ----------------------------
|
|
||||||
-- 服务器监控按钮权限
|
|
||||||
-- ----------------------------
|
|
||||||
-- 服务器监控-查看
|
|
||||||
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`)
|
|
||||||
VALUES (2101, '查看', 'View', 2010, '3', '', NULL, NULL, '', 'monitor:server:list', '0', NULL, '0', '', '0', '1', '1', '1', 1, 'system', NOW(), 'system', NOW());
|
|
||||||
|
|
||||||
-- ----------------------------
|
|
||||||
-- Redis监控按钮权限
|
|
||||||
-- ----------------------------
|
|
||||||
-- Redis监控-查看
|
|
||||||
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`)
|
|
||||||
VALUES (2102, '查看', 'View', 2011, '3', '', NULL, NULL, '', 'monitor:redis:list', '0', NULL, '0', '', '0', '1', '1', '1', 1, 'system', NOW(), 'system', NOW());
|
|
||||||
|
|
||||||
-- ----------------------------
|
|
||||||
-- 缓存管理按钮权限
|
|
||||||
-- ----------------------------
|
|
||||||
-- 缓存管理-查看
|
|
||||||
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`)
|
|
||||||
VALUES (2103, '查看', 'View', 2012, '3', '', NULL, NULL, '', 'monitor:cache:list', '0', NULL, '0', '', '0', '1', '1', '1', 1, 'system', NOW(), 'system', NOW());
|
|
||||||
|
|
||||||
-- 缓存管理-删除
|
|
||||||
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`)
|
|
||||||
VALUES (2104, '删除', 'Delete', 2012, '3', '', NULL, NULL, '', 'monitor:cache:delete', '0', NULL, '0', '', '0', '1', '1', '1', 2, 'system', NOW(), 'system', NOW());
|
|
||||||
|
|
||||||
-- 缓存管理-清空
|
|
||||||
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`)
|
|
||||||
VALUES (2105, '清空', 'Clear', 2012, '3', '', NULL, NULL, '', 'monitor:cache:clear', '0', NULL, '0', '', '0', '1', '1', '1', 3, 'system', NOW(), 'system', NOW());
|
|
||||||
|
|
||||||
-- ----------------------------
|
|
||||||
-- 操作日志按钮权限(如果需要)
|
|
||||||
-- ----------------------------
|
|
||||||
-- 操作日志-查看
|
|
||||||
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`)
|
|
||||||
SELECT 2106, '查看', 'View', 2013, '3', '', NULL, NULL, '', 'monitor:operlog:list', '0', NULL, '0', '', '0', '1', '1', '1', 1, 'system', NOW(), 'system', NOW()
|
|
||||||
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `menu_id` = 2106);
|
|
||||||
|
|
||||||
-- 操作日志-删除
|
|
||||||
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`)
|
|
||||||
SELECT 2107, '删除', 'Delete', 2013, '3', '', NULL, NULL, '', 'monitor:operlog:delete', '0', NULL, '0', '', '0', '1', '1', '1', 2, 'system', NOW(), 'system', NOW()
|
|
||||||
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `menu_id` = 2107);
|
|
||||||
|
|
||||||
-- 操作日志-清空
|
|
||||||
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`)
|
|
||||||
SELECT 2108, '清空', 'Clear', 2013, '3', '', NULL, NULL, '', 'monitor:operlog:clear', '0', NULL, '0', '', '0', '1', '1', '1', 3, 'system', NOW(), 'system', NOW()
|
|
||||||
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `menu_id` = 2108);
|
|
||||||
|
|
||||||
-- ----------------------------
|
|
||||||
-- 角色权限关联(管理员角色拥有监控权限)
|
|
||||||
-- ----------------------------
|
|
||||||
|
|
||||||
-- 给管理员角色分配监控菜单权限
|
|
||||||
-- 注意:这里假设管理员角色ID为1,请根据实际情况调整
|
|
||||||
|
|
||||||
-- 系统监控顶级菜单
|
|
||||||
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
|
|
||||||
SELECT 1, 2000 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2000);
|
|
||||||
|
|
||||||
-- 服务器监控
|
|
||||||
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
|
|
||||||
SELECT 1, 2010 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2010);
|
|
||||||
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
|
|
||||||
SELECT 1, 2101 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2101);
|
|
||||||
|
|
||||||
-- Redis监控
|
|
||||||
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
|
|
||||||
SELECT 1, 2011 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2011);
|
|
||||||
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
|
|
||||||
SELECT 1, 2102 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2102);
|
|
||||||
|
|
||||||
-- 缓存管理
|
|
||||||
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
|
|
||||||
SELECT 1, 2012 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2012);
|
|
||||||
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
|
|
||||||
SELECT 1, 2103 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2103);
|
|
||||||
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
|
|
||||||
SELECT 1, 2104 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2104);
|
|
||||||
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
|
|
||||||
SELECT 1, 2105 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2105);
|
|
||||||
|
|
||||||
-- 操作日志
|
|
||||||
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
|
|
||||||
SELECT 1, 2013 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2013);
|
|
||||||
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
|
|
||||||
SELECT 1, 2106 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2106);
|
|
||||||
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
|
|
||||||
SELECT 1, 2107 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2107);
|
|
||||||
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
|
|
||||||
SELECT 1, 2108 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2108);
|
|
||||||
|
|
||||||
-- 登录日志
|
|
||||||
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
|
|
||||||
SELECT 1, 2014 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2014);
|
|
||||||
|
|
||||||
-- 定时任务
|
|
||||||
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
|
|
||||||
SELECT 1, 2015 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2015);
|
|
||||||
|
|
||||||
-- ----------------------------
|
|
||||||
-- 执行说明
|
|
||||||
-- ----------------------------
|
|
||||||
|
|
||||||
/*
|
|
||||||
执行此脚本后,系统将具备以下监控菜单结构:
|
|
||||||
|
|
||||||
📊 系统监控 (/monitor)
|
|
||||||
├── 🖥️ 服务器监控 (/monitor/server)
|
|
||||||
│ └── 👀 查看 [monitor:server:list]
|
|
||||||
├── 🔗 Redis监控 (/monitor/redis)
|
|
||||||
│ └── 👀 查看 [monitor:redis:list]
|
|
||||||
├── 💾 缓存管理 (/monitor/cache)
|
|
||||||
│ ├── 👀 查看 [monitor:cache:list]
|
|
||||||
│ ├── 🗑️ 删除 [monitor:cache:delete]
|
|
||||||
│ └── 🧹 清空 [monitor:cache:clear]
|
|
||||||
├── 📋 操作日志 (/monitor/operlog)
|
|
||||||
│ ├── 👀 查看 [monitor:operlog:list]
|
|
||||||
│ ├── 🗑️ 删除 [monitor:operlog:delete]
|
|
||||||
│ └── 🧹 清空 [monitor:operlog:clear]
|
|
||||||
├── 🔑 登录日志 (/monitor/loginlog)
|
|
||||||
│ └── 👀 查看 [monitor:loginlog:list]
|
|
||||||
└── ⏰ 定时任务 (/monitor/job)
|
|
||||||
└── 👀 查看 [monitor:job:list]
|
|
||||||
|
|
||||||
🔐 权限说明:
|
|
||||||
- 所有菜单默认分配给管理员角色(role_id=1)
|
|
||||||
- 使用Sa-Token权限验证
|
|
||||||
- 支持细粒度按钮权限控制
|
|
||||||
|
|
||||||
📝 注意事项:
|
|
||||||
- 菜单ID范围:2000-2999(避免冲突)
|
|
||||||
- 所有SQL使用防重复执行机制
|
|
||||||
- 可根据实际需要调整管理员角色ID
|
|
||||||
- 执行前请备份相关表数据
|
|
||||||
*/
|
|
||||||
|
|
||||||
-- ============================================================================
|
|
||||||
-- SQL 脚本执行完成
|
|
||||||
-- ============================================================================
|
|
||||||
Loading…
Reference in New Issue
Block a user