init:项目初始化删除无用依赖
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package org.nl;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
|
||||
import com.alicp.jetcache.anno.config.EnableMethodCache;
|
||||
import org.dromara.dynamictp.core.spring.EnableDynamicTp;
|
||||
//import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
|
||||
//import com.alicp.jetcache.anno.config.EnableMethodCache;
|
||||
//import org.dromara.dynamictp.core.spring.EnableDynamicTp;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
@@ -24,14 +24,11 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@EnableAsync
|
||||
@RestController
|
||||
@EnableDynamicTp
|
||||
@SpringBootApplication(exclude = {
|
||||
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
|
||||
})
|
||||
@ServletComponentScan
|
||||
@EnableTransactionManagement
|
||||
@EnableMethodCache(basePackages = "org.nl")
|
||||
@EnableCreateCacheAnnotation
|
||||
@MapperScan("org.nl.**.mapper")
|
||||
public class AppRun implements ApplicationRunner {
|
||||
|
||||
|
||||
@@ -1,105 +1,105 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.common.mnt.util;
|
||||
|
||||
import ch.ethz.ssh2.Connection;
|
||||
import ch.ethz.ssh2.SCPClient;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* 远程执行linux命令
|
||||
* @author: ZhangHouYing
|
||||
* @date: 2019-08-10 10:06
|
||||
*/
|
||||
public class ScpClientUtil {
|
||||
|
||||
static private Map<String,ScpClientUtil> instance = Maps.newHashMap();
|
||||
|
||||
static synchronized public ScpClientUtil getInstance(String ip, int port, String username, String password) {
|
||||
if (instance.get(ip) == null) {
|
||||
instance.put(ip, new ScpClientUtil(ip, port, username, password));
|
||||
}
|
||||
return instance.get(ip);
|
||||
}
|
||||
|
||||
public ScpClientUtil(String ip, int port, String username, String password) {
|
||||
this.ip = ip;
|
||||
this.port = port;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void getFile(String remoteFile, String localTargetDirectory) {
|
||||
Connection conn = new Connection(ip, port);
|
||||
try {
|
||||
conn.connect();
|
||||
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
|
||||
if (!isAuthenticated) {
|
||||
System.err.println("authentication failed");
|
||||
}
|
||||
SCPClient client = new SCPClient(conn);
|
||||
client.get(remoteFile, localTargetDirectory);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(SCPClient.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}finally{
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void putFile(String localFile, String remoteTargetDirectory) {
|
||||
putFile(localFile, null, remoteTargetDirectory);
|
||||
}
|
||||
|
||||
public void putFile(String localFile, String remoteFileName, String remoteTargetDirectory) {
|
||||
putFile(localFile, remoteFileName, remoteTargetDirectory,null);
|
||||
}
|
||||
|
||||
public void putFile(String localFile, String remoteFileName, String remoteTargetDirectory, String mode) {
|
||||
Connection conn = new Connection(ip, port);
|
||||
try {
|
||||
conn.connect();
|
||||
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
|
||||
if (!isAuthenticated) {
|
||||
System.err.println("authentication failed");
|
||||
}
|
||||
SCPClient client = new SCPClient(conn);
|
||||
if ((mode == null) || (mode.length() == 0)) {
|
||||
mode = "0600";
|
||||
}
|
||||
if (remoteFileName == null) {
|
||||
client.put(localFile, remoteTargetDirectory);
|
||||
} else {
|
||||
client.put(localFile, remoteFileName, remoteTargetDirectory, mode);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(ScpClientUtil.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}finally{
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
private String ip;
|
||||
private int port;
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
|
||||
}
|
||||
///*
|
||||
// * Copyright 2019-2020 Zheng Jie
|
||||
// *
|
||||
// * Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// * you may not use this file except in compliance with the License.
|
||||
// * You may obtain a copy of the License at
|
||||
// *
|
||||
// * http://www.apache.org/licenses/LICENSE-2.0
|
||||
// *
|
||||
// * Unless required by applicable law or agreed to in writing, software
|
||||
// * distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// * See the License for the specific language governing permissions and
|
||||
// * limitations under the License.
|
||||
// */
|
||||
//package org.nl.common.mnt.util;
|
||||
//
|
||||
//import ch.ethz.ssh2.Connection;
|
||||
//import ch.ethz.ssh2.SCPClient;
|
||||
//import com.google.common.collect.Maps;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.util.Map;
|
||||
//import java.util.logging.Level;
|
||||
//import java.util.logging.Logger;
|
||||
//
|
||||
///**
|
||||
// * 远程执行linux命令
|
||||
// * @author: ZhangHouYing
|
||||
// * @date: 2019-08-10 10:06
|
||||
// */
|
||||
//public class ScpClientUtil {
|
||||
//
|
||||
// static private Map<String,ScpClientUtil> instance = Maps.newHashMap();
|
||||
//
|
||||
// static synchronized public ScpClientUtil getInstance(String ip, int port, String username, String password) {
|
||||
// if (instance.get(ip) == null) {
|
||||
// instance.put(ip, new ScpClientUtil(ip, port, username, password));
|
||||
// }
|
||||
// return instance.get(ip);
|
||||
// }
|
||||
//
|
||||
// public ScpClientUtil(String ip, int port, String username, String password) {
|
||||
// this.ip = ip;
|
||||
// this.port = port;
|
||||
// this.username = username;
|
||||
// this.password = password;
|
||||
// }
|
||||
//
|
||||
// public void getFile(String remoteFile, String localTargetDirectory) {
|
||||
// Connection conn = new Connection(ip, port);
|
||||
// try {
|
||||
// conn.connect();
|
||||
// boolean isAuthenticated = conn.authenticateWithPassword(username, password);
|
||||
// if (!isAuthenticated) {
|
||||
// System.err.println("authentication failed");
|
||||
// }
|
||||
// SCPClient client = new SCPClient(conn);
|
||||
// client.get(remoteFile, localTargetDirectory);
|
||||
// } catch (IOException ex) {
|
||||
// Logger.getLogger(SCPClient.class.getName()).log(Level.SEVERE, null, ex);
|
||||
// }finally{
|
||||
// conn.close();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void putFile(String localFile, String remoteTargetDirectory) {
|
||||
// putFile(localFile, null, remoteTargetDirectory);
|
||||
// }
|
||||
//
|
||||
// public void putFile(String localFile, String remoteFileName, String remoteTargetDirectory) {
|
||||
// putFile(localFile, remoteFileName, remoteTargetDirectory,null);
|
||||
// }
|
||||
//
|
||||
// public void putFile(String localFile, String remoteFileName, String remoteTargetDirectory, String mode) {
|
||||
// Connection conn = new Connection(ip, port);
|
||||
// try {
|
||||
// conn.connect();
|
||||
// boolean isAuthenticated = conn.authenticateWithPassword(username, password);
|
||||
// if (!isAuthenticated) {
|
||||
// System.err.println("authentication failed");
|
||||
// }
|
||||
// SCPClient client = new SCPClient(conn);
|
||||
// if ((mode == null) || (mode.length() == 0)) {
|
||||
// mode = "0600";
|
||||
// }
|
||||
// if (remoteFileName == null) {
|
||||
// client.put(localFile, remoteTargetDirectory);
|
||||
// } else {
|
||||
// client.put(localFile, remoteFileName, remoteTargetDirectory, mode);
|
||||
// }
|
||||
// } catch (IOException ex) {
|
||||
// Logger.getLogger(ScpClientUtil.class.getName()).log(Level.SEVERE, null, ex);
|
||||
// }finally{
|
||||
// conn.close();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private String ip;
|
||||
// private int port;
|
||||
// private String username;
|
||||
// private String password;
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -1,138 +1,138 @@
|
||||
package org.nl.common.utils;
|
||||
|
||||
//package org.nl.common.utils;
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
////
|
||||
//// Source code recreated from a .class file by IntelliJ IDEA
|
||||
//// (powered by FernFlower decompiler)
|
||||
////
|
||||
//
|
||||
|
||||
|
||||
import sun.misc.BASE64Decoder;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.SecretKeyFactory;
|
||||
import javax.crypto.spec.DESKeySpec;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import java.io.IOException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Des加密解密算法工具类
|
||||
* </p>
|
||||
*
|
||||
* @author lyd
|
||||
* @since 2023-05-03
|
||||
*/
|
||||
public class DesUtil {
|
||||
/**
|
||||
* 加密算法是des
|
||||
*/
|
||||
private static final String ALGORITHM = "DES";
|
||||
/**
|
||||
* 转换格式
|
||||
*/
|
||||
private static final String TRANSFORMATION = "DES/CBC/PKCS5Padding";
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*
|
||||
* @param src 数据源
|
||||
* @param key 密钥,长度必须是8的倍数
|
||||
* @return 返回加密后的数据
|
||||
* @throws Exception 出错
|
||||
*/
|
||||
public static byte[] encrypt(byte[] src, byte[] key) throws Exception {
|
||||
// DES算法要求有一个可信任的随机数源
|
||||
SecureRandom sr = new SecureRandom();
|
||||
// 从原始密匙数据建立 DESKeySpec对象
|
||||
DESKeySpec dks = new DESKeySpec(key);
|
||||
// 建立一个密匙工厂,然后用它把DESKeySpec转换成
|
||||
// 一个SecretKey对象
|
||||
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
|
||||
SecretKey securekey = keyFactory.generateSecret(dks);
|
||||
// Cipher对象实际完成加密操作
|
||||
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
|
||||
// 用密匙原始化Cipher对象
|
||||
cipher.init(Cipher.ENCRYPT_MODE, securekey, new IvParameterSpec(key));
|
||||
// 现在,获取数据并加密
|
||||
// 正式执行加密操作
|
||||
return cipher.doFinal(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
*
|
||||
* @param src 数据源
|
||||
* @param key 密钥,长度必须是8的倍数
|
||||
* @return 返回解密后的原始数据
|
||||
* @throws Exception 出错
|
||||
*/
|
||||
public static byte[] decrypt(byte[] src, byte[] key) throws Exception {
|
||||
// DES算法要求有一个可信任的随机数源
|
||||
SecureRandom sr = new SecureRandom();
|
||||
// 从原始密匙数据建立一个DESKeySpec对象
|
||||
DESKeySpec dks = new DESKeySpec(key);
|
||||
// 建立一个密匙工厂,然后用它把DESKeySpec对象转换成
|
||||
// 一个SecretKey对象
|
||||
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
|
||||
SecretKey securekey = keyFactory.generateSecret(dks);
|
||||
// Cipher对象实际完成解密操作
|
||||
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
|
||||
// 用密匙原始化Cipher对象
|
||||
cipher.init(Cipher.DECRYPT_MODE, securekey, new IvParameterSpec(key));
|
||||
// 现在,获取数据并解密
|
||||
// 正式执行解密操作
|
||||
return cipher.doFinal(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description 根据键值进行加密
|
||||
*
|
||||
* @param data
|
||||
* @param key 加密键byte数组
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String encrypt(String data, String key) throws Exception {
|
||||
byte[] bt = encrypt(data.getBytes("UTF-8"), key.getBytes("UTF-8"));
|
||||
|
||||
BASE64Encoder encoder = new BASE64Encoder();
|
||||
return encoder.encode(bt);
|
||||
|
||||
//return new String(Base64.encodeBase64(bt), "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* Description 根据键值进行解密
|
||||
*
|
||||
* @param data
|
||||
* @param key 加密键byte数组
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String decrypt(String data, String key) throws Exception {
|
||||
if (data == null)
|
||||
return null;
|
||||
BASE64Decoder decoder = new BASE64Decoder();
|
||||
byte[] buf = decoder.decodeBuffer(data);
|
||||
|
||||
byte[] bt = decrypt(buf, key.getBytes("UTF-8"));
|
||||
return new String(bt, "UTF-8");
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
//uL8fXioyU2M=
|
||||
String key = "11111111";
|
||||
String pp = encrypt("123456", key);
|
||||
System.out.println("加密:" + pp);
|
||||
|
||||
String mm2 = decrypt(pp, key);
|
||||
System.out.println("解密:" + mm2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//
|
||||
//import sun.misc.BASE64Decoder;
|
||||
//import sun.misc.BASE64Encoder;
|
||||
//
|
||||
//import javax.crypto.Cipher;
|
||||
//import javax.crypto.SecretKey;
|
||||
//import javax.crypto.SecretKeyFactory;
|
||||
//import javax.crypto.spec.DESKeySpec;
|
||||
//import javax.crypto.spec.IvParameterSpec;
|
||||
//import java.io.IOException;
|
||||
//import java.security.SecureRandom;
|
||||
//
|
||||
///**
|
||||
// * <p>
|
||||
// * Des加密解密算法工具类
|
||||
// * </p>
|
||||
// *
|
||||
// * @author lyd
|
||||
// * @since 2023-05-03
|
||||
// */
|
||||
//public class DesUtil {
|
||||
// /**
|
||||
// * 加密算法是des
|
||||
// */
|
||||
// private static final String ALGORITHM = "DES";
|
||||
// /**
|
||||
// * 转换格式
|
||||
// */
|
||||
// private static final String TRANSFORMATION = "DES/CBC/PKCS5Padding";
|
||||
//
|
||||
// /**
|
||||
// * 加密
|
||||
// *
|
||||
// * @param src 数据源
|
||||
// * @param key 密钥,长度必须是8的倍数
|
||||
// * @return 返回加密后的数据
|
||||
// * @throws Exception 出错
|
||||
// */
|
||||
// public static byte[] encrypt(byte[] src, byte[] key) throws Exception {
|
||||
// // DES算法要求有一个可信任的随机数源
|
||||
// SecureRandom sr = new SecureRandom();
|
||||
// // 从原始密匙数据建立 DESKeySpec对象
|
||||
// DESKeySpec dks = new DESKeySpec(key);
|
||||
// // 建立一个密匙工厂,然后用它把DESKeySpec转换成
|
||||
// // 一个SecretKey对象
|
||||
// SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
|
||||
// SecretKey securekey = keyFactory.generateSecret(dks);
|
||||
// // Cipher对象实际完成加密操作
|
||||
// Cipher cipher = Cipher.getInstance(TRANSFORMATION);
|
||||
// // 用密匙原始化Cipher对象
|
||||
// cipher.init(Cipher.ENCRYPT_MODE, securekey, new IvParameterSpec(key));
|
||||
// // 现在,获取数据并加密
|
||||
// // 正式执行加密操作
|
||||
// return cipher.doFinal(src);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 解密
|
||||
// *
|
||||
// * @param src 数据源
|
||||
// * @param key 密钥,长度必须是8的倍数
|
||||
// * @return 返回解密后的原始数据
|
||||
// * @throws Exception 出错
|
||||
// */
|
||||
// public static byte[] decrypt(byte[] src, byte[] key) throws Exception {
|
||||
// // DES算法要求有一个可信任的随机数源
|
||||
// SecureRandom sr = new SecureRandom();
|
||||
// // 从原始密匙数据建立一个DESKeySpec对象
|
||||
// DESKeySpec dks = new DESKeySpec(key);
|
||||
// // 建立一个密匙工厂,然后用它把DESKeySpec对象转换成
|
||||
// // 一个SecretKey对象
|
||||
// SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
|
||||
// SecretKey securekey = keyFactory.generateSecret(dks);
|
||||
// // Cipher对象实际完成解密操作
|
||||
// Cipher cipher = Cipher.getInstance(TRANSFORMATION);
|
||||
// // 用密匙原始化Cipher对象
|
||||
// cipher.init(Cipher.DECRYPT_MODE, securekey, new IvParameterSpec(key));
|
||||
// // 现在,获取数据并解密
|
||||
// // 正式执行解密操作
|
||||
// return cipher.doFinal(src);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Description 根据键值进行加密
|
||||
// *
|
||||
// * @param data
|
||||
// * @param key 加密键byte数组
|
||||
// * @return
|
||||
// * @throws Exception
|
||||
// */
|
||||
// public static String encrypt(String data, String key) throws Exception {
|
||||
// byte[] bt = encrypt(data.getBytes("UTF-8"), key.getBytes("UTF-8"));
|
||||
//
|
||||
// BASE64Encoder encoder = new BASE64Encoder();
|
||||
// return encoder.encode(bt);
|
||||
//
|
||||
// //return new String(Base64.encodeBase64(bt), "UTF-8");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Description 根据键值进行解密
|
||||
// *
|
||||
// * @param data
|
||||
// * @param key 加密键byte数组
|
||||
// * @return
|
||||
// * @throws IOException
|
||||
// * @throws Exception
|
||||
// */
|
||||
// public static String decrypt(String data, String key) throws Exception {
|
||||
// if (data == null)
|
||||
// return null;
|
||||
// BASE64Decoder decoder = new BASE64Decoder();
|
||||
// byte[] buf = decoder.decodeBuffer(data);
|
||||
//
|
||||
// byte[] bt = decrypt(buf, key.getBytes("UTF-8"));
|
||||
// return new String(bt, "UTF-8");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static void main(String[] args) throws Exception {
|
||||
// //uL8fXioyU2M=
|
||||
// String key = "11111111";
|
||||
// String pp = encrypt("123456", key);
|
||||
// System.out.println("加密:" + pp);
|
||||
//
|
||||
// String mm2 = decrypt(pp, key);
|
||||
// System.out.println("解密:" + mm2);
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -21,8 +21,6 @@ import cn.hutool.json.JSONUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dreamlu.mica.ip2region.core.Ip2regionSearcher;
|
||||
import net.dreamlu.mica.ip2region.core.IpInfo;
|
||||
import nl.basjes.parse.useragent.UserAgent;
|
||||
import nl.basjes.parse.useragent.UserAgentAnalyzer;
|
||||
import org.nl.config.ElAdminProperties;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
|
||||
@@ -50,13 +48,6 @@ public class StringUtils {
|
||||
private final static Ip2regionSearcher IP_SEARCHER = SpringContextHolder.getBean(Ip2regionSearcher.class);
|
||||
|
||||
|
||||
private static final UserAgentAnalyzer USER_AGENT_ANALYZER = UserAgentAnalyzer
|
||||
.newBuilder()
|
||||
.hideMatcherLoadStats()
|
||||
.withCache(10000)
|
||||
.withField(UserAgent.AGENT_NAME_VERSION)
|
||||
.build();
|
||||
|
||||
/**
|
||||
* 驼峰命名法工具
|
||||
*
|
||||
@@ -209,10 +200,9 @@ public class StringUtils {
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
//浏览器信息
|
||||
public static String getBrowser(HttpServletRequest request) {
|
||||
UserAgent.ImmutableUserAgent userAgent = USER_AGENT_ANALYZER.parse(request.getHeader("User-Agent"));
|
||||
return userAgent.get(UserAgent.AGENT_NAME_VERSION).getValue();
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package org.nl.config.redis;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import org.nl.system.service.redis.vo.RedisMonitorRespVO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description: redis---Spring Boot 对象转换 MapStruct
|
||||
* @Date: 2022-08-04
|
||||
*/
|
||||
@Mapper
|
||||
public interface RedisConvert {
|
||||
|
||||
RedisConvert INSTANCE = Mappers.getMapper(RedisConvert.class);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param info
|
||||
* @param dbSize
|
||||
* @param commandStats
|
||||
* @return RedisMonitorRespVO
|
||||
*/
|
||||
default RedisMonitorRespVO build(Properties info, Long dbSize, Properties commandStats) {
|
||||
RedisMonitorRespVO respVO = RedisMonitorRespVO.builder().info(info).dbSize(dbSize)
|
||||
.commandStats(new ArrayList<>(commandStats.size())).build();
|
||||
commandStats.forEach((key, value) -> {
|
||||
respVO.getCommandStats().add(RedisMonitorRespVO.CommandStat.builder()
|
||||
.command(StrUtil.subAfter((String) key, "cmdstat_", false))
|
||||
.calls(Integer.valueOf(StrUtil.subBetween((String) value, "calls=", ",")))
|
||||
.usec(Long.valueOf(StrUtil.subBetween((String) value, "usec=", ",")))
|
||||
.build());
|
||||
});
|
||||
return respVO;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +1,30 @@
|
||||
package org.nl.config.thread;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.dynamictp.common.entity.ThreadPoolStats;
|
||||
import org.dromara.dynamictp.core.monitor.collector.AbstractCollector;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description: 线程监控
|
||||
* @Date: 2023/12/25
|
||||
*/
|
||||
@Slf4j
|
||||
public class ThreadMonitorCollector extends AbstractCollector {
|
||||
public static ThreadPoolStats TOMCAT_THREAD;
|
||||
public static ThreadPoolStats EL_THREAD;
|
||||
@Override
|
||||
public void collect(ThreadPoolStats threadPoolStats) {
|
||||
if ("tomcatTp".equals(threadPoolStats.getPoolName())) {
|
||||
ThreadMonitorCollector.TOMCAT_THREAD = threadPoolStats;
|
||||
} else {
|
||||
ThreadMonitorCollector.EL_THREAD = threadPoolStats;
|
||||
}
|
||||
log.info("线程池数据:{}", threadPoolStats);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type() {
|
||||
return "test_collect";
|
||||
}
|
||||
}
|
||||
//package org.nl.config.thread;
|
||||
//
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.dromara.dynamictp.common.entity.ThreadPoolStats;
|
||||
//import org.dromara.dynamictp.core.monitor.collector.AbstractCollector;
|
||||
//
|
||||
///**
|
||||
// * @Author: lyd
|
||||
// * @Description: 线程监控
|
||||
// * @Date: 2023/12/25
|
||||
// */
|
||||
//@Slf4j
|
||||
//public class ThreadMonitorCollector extends AbstractCollector {
|
||||
// public static ThreadPoolStats TOMCAT_THREAD;
|
||||
// public static ThreadPoolStats EL_THREAD;
|
||||
// @Override
|
||||
// public void collect(ThreadPoolStats threadPoolStats) {
|
||||
// if ("tomcatTp".equals(threadPoolStats.getPoolName())) {
|
||||
// ThreadMonitorCollector.TOMCAT_THREAD = threadPoolStats;
|
||||
// } else {
|
||||
// ThreadMonitorCollector.EL_THREAD = threadPoolStats;
|
||||
// }
|
||||
// log.info("线程池数据:{}", threadPoolStats);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String type() {
|
||||
// return "test_collect";
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.system.controller.monitor;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.system.service.monitor.MonitorService;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2020-05-02
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/monitor")
|
||||
public class MonitorController {
|
||||
|
||||
private final MonitorService serverService;
|
||||
|
||||
@GetMapping
|
||||
|
||||
@SaCheckPermission("monitor:list")
|
||||
public ResponseEntity<Object> query() {
|
||||
return new ResponseEntity<>(serverService.getServers(),HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.system.service.monitor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2020-05-02
|
||||
*/
|
||||
public interface MonitorService {
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
Map<String,Object> getServers();
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.system.service.monitor.impl;
|
||||
|
||||
import cn.hutool.core.date.BetweenFormatter;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import org.nl.common.utils.ElAdminConstant;
|
||||
import org.nl.common.utils.FileUtil;
|
||||
import org.nl.common.utils.StringUtils;
|
||||
import org.nl.system.service.monitor.MonitorService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import oshi.SystemInfo;
|
||||
import oshi.hardware.CentralProcessor;
|
||||
import oshi.hardware.GlobalMemory;
|
||||
import oshi.hardware.HardwareAbstractionLayer;
|
||||
import oshi.hardware.VirtualMemory;
|
||||
import oshi.software.os.FileSystem;
|
||||
import oshi.software.os.OSFileStore;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
import oshi.util.FormatUtil;
|
||||
import oshi.util.Util;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2020-05-02
|
||||
*/
|
||||
@Service
|
||||
public class MonitorServiceImpl implements MonitorService {
|
||||
|
||||
private final DecimalFormat df = new DecimalFormat("0.00");
|
||||
|
||||
@Override
|
||||
public Map<String,Object> getServers(){
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>(8);
|
||||
try {
|
||||
SystemInfo si = new SystemInfo();
|
||||
OperatingSystem os = si.getOperatingSystem();
|
||||
HardwareAbstractionLayer hal = si.getHardware();
|
||||
// 系统信息
|
||||
resultMap.put("sys", getSystemInfo(os));
|
||||
// cpu 信息
|
||||
resultMap.put("cpu", getCpuInfo(hal.getProcessor()));
|
||||
// 内存信息
|
||||
resultMap.put("memory", getMemoryInfo(hal.getMemory()));
|
||||
// 交换区信息
|
||||
resultMap.put("swap", getSwapInfo(hal.getMemory()));
|
||||
// 磁盘
|
||||
resultMap.put("disk", getDiskInfo(os));
|
||||
resultMap.put("time", DateUtil.format(new Date(), "HH:mm:ss"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取磁盘信息
|
||||
* @return /
|
||||
*/
|
||||
private Map<String,Object> getDiskInfo(OperatingSystem os) {
|
||||
Map<String,Object> diskInfo = new LinkedHashMap<>();
|
||||
FileSystem fileSystem = os.getFileSystem();
|
||||
List<OSFileStore> fsArray = fileSystem.getFileStores();
|
||||
String osName = System.getProperty("os.name");
|
||||
long available = 0, total = 0;
|
||||
for (OSFileStore fs : fsArray){
|
||||
// windows 需要将所有磁盘分区累加,linux 和 mac 直接累加会出现磁盘重复的问题,待修复
|
||||
if(osName.toLowerCase().startsWith(ElAdminConstant.WIN)) {
|
||||
available += fs.getUsableSpace();
|
||||
total += fs.getTotalSpace();
|
||||
} else {
|
||||
available = fs.getUsableSpace();
|
||||
total = fs.getTotalSpace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
long used = total - available;
|
||||
diskInfo.put("total", total > 0 ? FileUtil.getSize(total) : "?");
|
||||
diskInfo.put("available", FileUtil.getSize(available));
|
||||
diskInfo.put("used", FileUtil.getSize(used));
|
||||
diskInfo.put("usageRate", df.format(used/(double)total * 100));
|
||||
return diskInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取交换区信息
|
||||
* @param memory /
|
||||
* @return /
|
||||
*/
|
||||
private Map<String,Object> getSwapInfo(GlobalMemory memory) {
|
||||
Map<String,Object> swapInfo = new LinkedHashMap<>();
|
||||
VirtualMemory virtualMemory = memory.getVirtualMemory();
|
||||
long total = virtualMemory.getSwapTotal();
|
||||
long used = virtualMemory.getSwapUsed();
|
||||
swapInfo.put("total", FormatUtil.formatBytes(total));
|
||||
swapInfo.put("used", FormatUtil.formatBytes(used));
|
||||
swapInfo.put("available", FormatUtil.formatBytes(total - used));
|
||||
if(used == 0){
|
||||
swapInfo.put("usageRate", 0);
|
||||
} else {
|
||||
swapInfo.put("usageRate", df.format(used/(double)total * 100));
|
||||
}
|
||||
return swapInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内存信息
|
||||
* @param memory /
|
||||
* @return /
|
||||
*/
|
||||
private Map<String,Object> getMemoryInfo(GlobalMemory memory) {
|
||||
Map<String,Object> memoryInfo = new LinkedHashMap<>();
|
||||
memoryInfo.put("total", FormatUtil.formatBytes(memory.getTotal()));
|
||||
memoryInfo.put("available", FormatUtil.formatBytes(memory.getAvailable()));
|
||||
memoryInfo.put("used", FormatUtil.formatBytes(memory.getTotal() - memory.getAvailable()));
|
||||
memoryInfo.put("usageRate", df.format((memory.getTotal() - memory.getAvailable())/(double)memory.getTotal() * 100));
|
||||
return memoryInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Cpu相关信息
|
||||
* @param processor /
|
||||
* @return /
|
||||
*/
|
||||
private Map<String,Object> getCpuInfo(CentralProcessor processor) {
|
||||
Map<String,Object> cpuInfo = new LinkedHashMap<>();
|
||||
cpuInfo.put("name", processor.getProcessorIdentifier().getName());
|
||||
cpuInfo.put("package", processor.getPhysicalPackageCount() + "个物理CPU");
|
||||
cpuInfo.put("core", processor.getPhysicalProcessorCount() + "个物理核心");
|
||||
cpuInfo.put("coreNumber", processor.getPhysicalProcessorCount());
|
||||
cpuInfo.put("logic", processor.getLogicalProcessorCount() + "个逻辑CPU");
|
||||
// CPU信息
|
||||
long[] prevTicks = processor.getSystemCpuLoadTicks();
|
||||
// 等待1秒...
|
||||
Util.sleep(1000);
|
||||
long[] ticks = processor.getSystemCpuLoadTicks();
|
||||
long user = ticks[CentralProcessor.TickType.USER.getIndex()] - prevTicks[CentralProcessor.TickType.USER.getIndex()];
|
||||
long nice = ticks[CentralProcessor.TickType.NICE.getIndex()] - prevTicks[CentralProcessor.TickType.NICE.getIndex()];
|
||||
long sys = ticks[CentralProcessor.TickType.SYSTEM.getIndex()] - prevTicks[CentralProcessor.TickType.SYSTEM.getIndex()];
|
||||
long idle = ticks[CentralProcessor.TickType.IDLE.getIndex()] - prevTicks[CentralProcessor.TickType.IDLE.getIndex()];
|
||||
long iowait = ticks[CentralProcessor.TickType.IOWAIT.getIndex()] - prevTicks[CentralProcessor.TickType.IOWAIT.getIndex()];
|
||||
long irq = ticks[CentralProcessor.TickType.IRQ.getIndex()] - prevTicks[CentralProcessor.TickType.IRQ.getIndex()];
|
||||
long softirq = ticks[CentralProcessor.TickType.SOFTIRQ.getIndex()] - prevTicks[CentralProcessor.TickType.SOFTIRQ.getIndex()];
|
||||
long steal = ticks[CentralProcessor.TickType.STEAL.getIndex()] - prevTicks[CentralProcessor.TickType.STEAL.getIndex()];
|
||||
long totalCpu = user + nice + sys + idle + iowait + irq + softirq + steal;
|
||||
cpuInfo.put("used", df.format(100d * user / totalCpu + 100d * sys / totalCpu));
|
||||
cpuInfo.put("idle", df.format(100d * idle / totalCpu));
|
||||
return cpuInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统相关信息,系统、运行天数、系统IP
|
||||
* @param os /
|
||||
* @return /
|
||||
*/
|
||||
private Map<String,Object> getSystemInfo(OperatingSystem os){
|
||||
Map<String,Object> systemInfo = new LinkedHashMap<>();
|
||||
// jvm 运行时间
|
||||
long time = ManagementFactory.getRuntimeMXBean().getStartTime();
|
||||
Date date = new Date(time);
|
||||
// 计算项目运行时间 5.4.3:BetweenFormater, 5.7.14改名为BetweenFormatter
|
||||
String formatBetween = DateUtil.formatBetween(date, new Date(), BetweenFormatter.Level.HOUR);
|
||||
// 系统信息
|
||||
systemInfo.put("os", os.toString());
|
||||
systemInfo.put("day", formatBetween);
|
||||
systemInfo.put("ip", StringUtils.getLocalIp());
|
||||
return systemInfo;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.nl.system.service.param;
|
||||
|
||||
import com.alicp.jetcache.anno.*;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.system.service.param.dao.Param;
|
||||
@@ -42,7 +40,6 @@ public interface ISysParamService extends IService<Param> {
|
||||
*
|
||||
* @param param
|
||||
*/
|
||||
@CacheUpdate(name = "paramDataCode.", key = "#param.code", value = "#param")
|
||||
void update(Param param);
|
||||
|
||||
/**
|
||||
@@ -58,6 +55,5 @@ public interface ISysParamService extends IService<Param> {
|
||||
* @param code
|
||||
* @return Param
|
||||
*/
|
||||
@Cached(name = "paramDataCode.", key = "#code", expire = 3600, cacheType = CacheType.REMOTE)
|
||||
Param findByCode(String code);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.nl.system.service.param.ISysParamService;
|
||||
import org.nl.system.service.param.dao.Param;
|
||||
import org.nl.system.service.param.dao.mapper.SysParamMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.system.service.redis.RedisService;
|
||||
import org.nl.config.redis.RedisConvert;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
import org.springframework.data.redis.connection.RedisServerCommands;
|
||||
@@ -40,7 +39,7 @@ public class RedisServiceImpl implements RedisService {
|
||||
// 拼接结果返回
|
||||
// 转成实体
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("info", RedisConvert.INSTANCE.build(info, dbSize, commandStats));
|
||||
json.put("info",json);
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user