15 changed files with 414 additions and 970 deletions
@ -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; |
|||
|
|||
//
|
|||
// 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); |
|||
|
|||
} |
|||
|
|||
} |
|||
//package org.nl.common.utils;
|
|||
//
|
|||
////
|
|||
//// 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);
|
|||
//
|
|||
// }
|
|||
//
|
|||
//}
|
|||
|
@ -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,30 +1,132 @@ |
|||
server: |
|||
port: 8011 |
|||
# 项目配置 |
|||
nl: |
|||
config: |
|||
mysql: |
|||
ip: 192.168.81.251 |
|||
port: 3306 |
|||
port: 8099 |
|||
max-http-header-size: 65536 |
|||
#配置数据源 |
|||
spring: |
|||
datasource: |
|||
druid: |
|||
db-type: com.alibaba.druid.pool.DruidDataSource |
|||
driverClassName: com.mysql.cj.jdbc.Driver |
|||
# url: jdbc:mysql://${DB_HOST:192.168.8.218}:${DB_PORT:3306}/${DB_NAME:wms}?serverTimxezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true&useSSL=false |
|||
url: jdbc:mysql://192.168.81.251:3306/wms_oulun?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true&useSSL=false |
|||
username: root |
|||
password: 123456 |
|||
database: wms_oulun |
|||
redis: |
|||
ip: 127.0.0.1 |
|||
port: 6379 |
|||
password: null |
|||
database: 1 |
|||
oracle: |
|||
ip: 172.27.37.66 |
|||
port: 1521 |
|||
scheme: RTMES |
|||
username: LMSTELCOM |
|||
password: LMSTELCOM_6463 |
|||
sqlserver: |
|||
ip: 10.93.41.2 |
|||
port: WINCC |
|||
username: sa |
|||
password: 123 |
|||
database: 马钢_RH |
|||
logging-path: C:\log\wms |
|||
dynamic-log-path: C:\log\lms |
|||
# 初始连接数 |
|||
initial-size: 15 |
|||
# 最小连接数 |
|||
min-idle: 25 |
|||
# 最大连接数 |
|||
max-active: 40 |
|||
# 是否自动回收超时连接 |
|||
remove-abandoned: true |
|||
# 超时时间(以秒数为单位) |
|||
remove-abandoned-timeout: 20 |
|||
# 获取连接超时时间 |
|||
max-wait: 9000 |
|||
# 连接有效性检测时间 |
|||
time-between-eviction-runs-millis: 60000 |
|||
# 连接在池中最小生存的时间 |
|||
min-evictable-idle-time-millis: 300000 |
|||
# 连接在池中最大生存的时间 |
|||
max-evictable-idle-time-millis: 900000 |
|||
# 指明连接是否被空闲连接回收器(如果有)进行检验.如果检测失败,则连接将被从池中去除 |
|||
test-while-idle: true |
|||
# 指明是否在从池中取出连接前进行检验,如果检验失败, 则从池中去除连接并尝试取出另一个 |
|||
test-on-borrow: true |
|||
# 是否在归还到池中前进行检验 |
|||
test-on-return: false |
|||
# 检测连接是否有效 |
|||
validation-query: select 1 |
|||
# 配置监控统计 |
|||
webStatFilter: |
|||
enabled: true |
|||
stat-view-servlet: |
|||
enabled: true |
|||
url-pattern: /druid/* |
|||
reset-enable: false |
|||
filters: |
|||
DruidFilter,stat |
|||
|
|||
redis: |
|||
#数据库索引 |
|||
database: ${REDIS_DB:1} |
|||
#host: ${REDIS_HOST:127.0.0.1} |
|||
host: ${REDIS_HOST:localhost} |
|||
port: ${REDIS_PORT:6379} |
|||
password: ${REDIS_PWD:} |
|||
#连接超时时间 |
|||
timeout: 5000 |
|||
redisson: |
|||
config: | |
|||
threads: 4 |
|||
nettyThreads: 4 |
|||
singleServerConfig: |
|||
connectionMinimumIdleSize: 8 |
|||
connectionPoolSize: 8 |
|||
address: redis://127.0.0.1:6379 |
|||
idleConnectionTimeout: 10000 |
|||
timeout: 3000 |
|||
# 登录相关配置 |
|||
login: |
|||
# 登录缓存 |
|||
cache-enable: true |
|||
# 是否限制单用户登录 |
|||
single-login: false |
|||
# 验证码 |
|||
login-code: |
|||
# 验证码类型配置 查看 LoginProperties 类 |
|||
code-type: arithmetic |
|||
# 登录图形验证码有效时间/分钟 |
|||
expiration: 2 |
|||
# 验证码高度 |
|||
width: 111 |
|||
# 验证码宽度 |
|||
heigth: 36 |
|||
# 内容长度 |
|||
length: 2 |
|||
# 字体名称,为空则使用默认字体 |
|||
font-name: |
|||
# 字体大小 |
|||
font-size: 25 |
|||
|
|||
#jwt |
|||
jwt: |
|||
header: Authorization |
|||
# 令牌前缀 |
|||
token-start-with: Bearer |
|||
# 必须使用最少88位的Base64对该令牌进行编码 |
|||
base64-secret: ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI= |
|||
# 令牌过期时间 此处单位/毫秒 ,默认4小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html |
|||
token-validity-in-seconds: 14400000 |
|||
# 在线用户key |
|||
online-key: online-token- |
|||
# 验证码 |
|||
code-key: code-key- |
|||
# token 续期检查时间范围(默认30分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期 |
|||
detect: 1800000 |
|||
# 续期时间范围,默认1小时,单位毫秒 |
|||
renew: 3600000 |
|||
|
|||
sa-token: |
|||
# token 名称 (同时也是cookie名称) |
|||
token-name: Authorization |
|||
# token 有效期,单位s 默认30天, -1代表永不过期 |
|||
timeout: 2592000 |
|||
# token 临时有效期 (指定时间内无操作就视为token过期) 单位: 秒 |
|||
activity-timeout: -1 |
|||
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录) |
|||
is-concurrent: true |
|||
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token) |
|||
is-share: false |
|||
# token风格 |
|||
token-style: random-128 |
|||
# 是否输出操作日志 |
|||
is-log: false |
|||
jwt-secret-key: opsjajisdnnca0sdkksdfaaasdfwwq |
|||
# token 前缀 |
|||
token-prefix: |
|||
is-read-cookie: false |
|||
is-print: false |
|||
lucene: |
|||
index: |
|||
path: D:\lms\lucene\index |
|||
|
Loading…
Reference in new issue