代码提交
parent
49c0bfdd0c
commit
5d57935f0e
@ -1,56 +1,56 @@
|
||||
package com.docus.server;
|
||||
|
||||
import oshi.SystemInfo;
|
||||
import oshi.hardware.CentralProcessor;
|
||||
import oshi.hardware.GlobalMemory;
|
||||
import oshi.hardware.HardwareAbstractionLayer;
|
||||
import oshi.hardware.NetworkIF;
|
||||
import oshi.software.os.FileSystem;
|
||||
import oshi.software.os.OSFileStore;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Example {
|
||||
public static void main(String[] args) {
|
||||
SystemInfo systemInfo = new SystemInfo();
|
||||
CentralProcessor processor = systemInfo.getHardware().getProcessor();
|
||||
int logicalProcessorCount = processor.getLogicalProcessorCount();
|
||||
String cpuModel = processor.getProcessorIdentifier().getName();
|
||||
long[] systemCpuLoadTicks = processor.getSystemCpuLoadTicks();
|
||||
|
||||
System.out.println(logicalProcessorCount);
|
||||
System.out.println(cpuModel);
|
||||
System.out.println(Arrays.asList(systemCpuLoadTicks));
|
||||
|
||||
GlobalMemory memory = systemInfo.getHardware().getMemory();
|
||||
long totalMemorySize = memory.getTotal();
|
||||
long availableMemorySize = memory.getAvailable();
|
||||
double memoryUsage = (totalMemorySize - availableMemorySize) * 100.0 / totalMemorySize;
|
||||
System.out.println(totalMemorySize);
|
||||
System.out.println(availableMemorySize);
|
||||
System.out.println(memoryUsage);
|
||||
|
||||
HardwareAbstractionLayer hal = systemInfo.getHardware();
|
||||
FileSystem fileSystem = systemInfo.getOperatingSystem().getFileSystem();
|
||||
List<OSFileStore> fileStores = fileSystem.getFileStores();
|
||||
for (OSFileStore store : fileStores) {
|
||||
long totalSpace = store.getTotalSpace();
|
||||
long usableSpace = store.getUsableSpace();
|
||||
double usage = (totalSpace - usableSpace) * 100.0 / totalSpace;
|
||||
System.out.println(totalSpace);
|
||||
System.out.println(usableSpace);
|
||||
System.out.println(usage);
|
||||
}
|
||||
|
||||
List<NetworkIF> networkIFs = systemInfo.getHardware().getNetworkIFs();
|
||||
for (NetworkIF networkIF : networkIFs) {
|
||||
String name = networkIF.getName();
|
||||
long receiveBytes = networkIF.getBytesRecv();
|
||||
long transmitBytes = networkIF.getBytesSent();
|
||||
System.out.println(name);
|
||||
System.out.println(receiveBytes);
|
||||
System.out.println(transmitBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
//package com.docus.server;
|
||||
//
|
||||
//import oshi.SystemInfo;
|
||||
//import oshi.hardware.CentralProcessor;
|
||||
//import oshi.hardware.GlobalMemory;
|
||||
//import oshi.hardware.HardwareAbstractionLayer;
|
||||
//import oshi.hardware.NetworkIF;
|
||||
//import oshi.software.os.FileSystem;
|
||||
//import oshi.software.os.OSFileStore;
|
||||
//
|
||||
//import java.util.Arrays;
|
||||
//import java.util.List;
|
||||
//
|
||||
//public class Example {
|
||||
// public static void main(String[] args) {
|
||||
// SystemInfo systemInfo = new SystemInfo();
|
||||
// CentralProcessor processor = systemInfo.getHardware().getProcessor();
|
||||
// int logicalProcessorCount = processor.getLogicalProcessorCount();
|
||||
// String cpuModel = processor.getProcessorIdentifier().getName();
|
||||
// long[] systemCpuLoadTicks = processor.getSystemCpuLoadTicks();
|
||||
//
|
||||
// System.out.println(logicalProcessorCount);
|
||||
// System.out.println(cpuModel);
|
||||
// System.out.println(Arrays.asList(systemCpuLoadTicks));
|
||||
//
|
||||
// GlobalMemory memory = systemInfo.getHardware().getMemory();
|
||||
// long totalMemorySize = memory.getTotal();
|
||||
// long availableMemorySize = memory.getAvailable();
|
||||
// double memoryUsage = (totalMemorySize - availableMemorySize) * 100.0 / totalMemorySize;
|
||||
// System.out.println(totalMemorySize);
|
||||
// System.out.println(availableMemorySize);
|
||||
// System.out.println(memoryUsage);
|
||||
//
|
||||
// HardwareAbstractionLayer hal = systemInfo.getHardware();
|
||||
// FileSystem fileSystem = systemInfo.getOperatingSystem().getFileSystem();
|
||||
// List<OSFileStore> fileStores = fileSystem.getFileStores();
|
||||
// for (OSFileStore store : fileStores) {
|
||||
// long totalSpace = store.getTotalSpace();
|
||||
// long usableSpace = store.getUsableSpace();
|
||||
// double usage = (totalSpace - usableSpace) * 100.0 / totalSpace;
|
||||
// System.out.println(totalSpace);
|
||||
// System.out.println(usableSpace);
|
||||
// System.out.println(usage);
|
||||
// }
|
||||
//
|
||||
// List<NetworkIF> networkIFs = systemInfo.getHardware().getNetworkIFs();
|
||||
// for (NetworkIF networkIF : networkIFs) {
|
||||
// String name = networkIF.getName();
|
||||
// long receiveBytes = networkIF.getBytesRecv();
|
||||
// long transmitBytes = networkIF.getBytesSent();
|
||||
// System.out.println(name);
|
||||
// System.out.println(receiveBytes);
|
||||
// System.out.println(transmitBytes);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
@ -1,83 +1,83 @@
|
||||
package com.docus.server;
|
||||
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文件上传下载 API
|
||||
*
|
||||
* @author AutoGenerator
|
||||
* @since 2023-07-15
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class FileController {
|
||||
|
||||
|
||||
|
||||
|
||||
public static void test1() throws Exception {
|
||||
ZipUtil.unzip("/Users/linruifeng/Desktop/collector_packages/collector.zip", "/Users/linruifeng/Desktop/collector_packages");
|
||||
// ZipUtil.unGzip(new GZIPInputStream(new FileInputStream(new File("/Users/linruifeng/Desktop/collector_packages/index.tar.gz"))));
|
||||
// FileUtils.unTarGz("/Users/linruifeng/Desktop/collector_packages/", "/Users/linruifeng/Desktop/collector_packages/test");
|
||||
}
|
||||
|
||||
@ApiOperation("test")
|
||||
@PostMapping("/test")
|
||||
public void test2() throws Exception {
|
||||
File file = new File("D:\\docus\\cut\\segmentation\\20230822\\c6b03e5767814895a2c155c32f174051\\麻醉.jpg");
|
||||
File file1 = new File("D:\\docus\\cut\\segmentation\\20230822\\c6b03e5767814895a2c155c32f174052\\麻醉.jpg");
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("files", file);
|
||||
data.put("filetype", "jpg");
|
||||
|
||||
ArrayList<File> files = Lists.newArrayList(file, file1);
|
||||
|
||||
String body = HttpRequest.post("http://localhost:9115/file/upload")
|
||||
.form("files", files.toArray(new File[files.size()]))
|
||||
.form("pathKey", "{\n" +
|
||||
" \"success\": true,\n" +
|
||||
" \"datas\": [\n" +
|
||||
" {\n" +
|
||||
" \"index\": 0,\n" +
|
||||
" \"file_type\": \"string\",\n" +
|
||||
" \"angle\": \"string\",\n" +
|
||||
" \"decline\": true,\n" +
|
||||
" \"hand_shadow\": true,\n" +
|
||||
" \"sort\": [\n" +
|
||||
" \"string\"\n" +
|
||||
" ],\n" +
|
||||
" \"data\": [\n" +
|
||||
" {\n" +
|
||||
" \"boxes\": {\n" +
|
||||
" \"left\": 0,\n" +
|
||||
" \"right\": 0,\n" +
|
||||
" \"top\": 0,\n" +
|
||||
" \"bottom\": 0\n" +
|
||||
" },\n" +
|
||||
" \"text\": \"string\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"time\": 0,\n" +
|
||||
" \"message\": \"string\"\n" +
|
||||
"}")
|
||||
.contentType("multipart/form-data")
|
||||
.execute()
|
||||
.body();
|
||||
|
||||
System.out.println(body);
|
||||
|
||||
}
|
||||
}
|
||||
//package com.docus.server;
|
||||
//
|
||||
//import cn.hutool.core.util.ZipUtil;
|
||||
//import cn.hutool.http.HttpRequest;
|
||||
//
|
||||
//import com.google.common.collect.Lists;
|
||||
//import io.swagger.annotations.ApiOperation;
|
||||
//import org.springframework.boot.test.context.SpringBootTest;
|
||||
//import org.springframework.web.bind.annotation.PostMapping;
|
||||
//
|
||||
//import java.io.File;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Map;
|
||||
//
|
||||
///**
|
||||
// * 文件上传下载 API
|
||||
// *
|
||||
// * @author AutoGenerator
|
||||
// * @since 2023-07-15
|
||||
// */
|
||||
//@SpringBootTest
|
||||
//public class FileController {
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// public static void test1() throws Exception {
|
||||
// ZipUtil.unzip("/Users/linruifeng/Desktop/collector_packages/collector.zip", "/Users/linruifeng/Desktop/collector_packages");
|
||||
//// ZipUtil.unGzip(new GZIPInputStream(new FileInputStream(new File("/Users/linruifeng/Desktop/collector_packages/index.tar.gz"))));
|
||||
//// FileUtils.unTarGz("/Users/linruifeng/Desktop/collector_packages/", "/Users/linruifeng/Desktop/collector_packages/test");
|
||||
// }
|
||||
//
|
||||
// @ApiOperation("test")
|
||||
// @PostMapping("/test")
|
||||
// public void test2() throws Exception {
|
||||
// File file = new File("D:\\docus\\cut\\segmentation\\20230822\\c6b03e5767814895a2c155c32f174051\\麻醉.jpg");
|
||||
// File file1 = new File("D:\\docus\\cut\\segmentation\\20230822\\c6b03e5767814895a2c155c32f174052\\麻醉.jpg");
|
||||
//
|
||||
// Map<String, Object> data = new HashMap<>();
|
||||
// data.put("files", file);
|
||||
// data.put("filetype", "jpg");
|
||||
//
|
||||
// ArrayList<File> files = Lists.newArrayList(file, file1);
|
||||
//
|
||||
// String body = HttpRequest.post("http://localhost:9115/file/upload")
|
||||
// .form("files", files.toArray(new File[files.size()]))
|
||||
// .form("pathKey", "{\n" +
|
||||
// " \"success\": true,\n" +
|
||||
// " \"datas\": [\n" +
|
||||
// " {\n" +
|
||||
// " \"index\": 0,\n" +
|
||||
// " \"file_type\": \"string\",\n" +
|
||||
// " \"angle\": \"string\",\n" +
|
||||
// " \"decline\": true,\n" +
|
||||
// " \"hand_shadow\": true,\n" +
|
||||
// " \"sort\": [\n" +
|
||||
// " \"string\"\n" +
|
||||
// " ],\n" +
|
||||
// " \"data\": [\n" +
|
||||
// " {\n" +
|
||||
// " \"boxes\": {\n" +
|
||||
// " \"left\": 0,\n" +
|
||||
// " \"right\": 0,\n" +
|
||||
// " \"top\": 0,\n" +
|
||||
// " \"bottom\": 0\n" +
|
||||
// " },\n" +
|
||||
// " \"text\": \"string\"\n" +
|
||||
// " }\n" +
|
||||
// " ]\n" +
|
||||
// " }\n" +
|
||||
// " ],\n" +
|
||||
// " \"time\": 0,\n" +
|
||||
// " \"message\": \"string\"\n" +
|
||||
// "}")
|
||||
// .contentType("multipart/form-data")
|
||||
// .execute()
|
||||
// .body();
|
||||
//
|
||||
// System.out.println(body);
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
@ -1,162 +1,162 @@
|
||||
package com.docus.server;
|
||||
|
||||
import org.apache.tools.tar.TarInputStream;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
* @program: JavaCode
|
||||
* @ClassName FileUtils
|
||||
* @description:
|
||||
* @author: ltcz99
|
||||
* @create: 2023-04-16
|
||||
* @Version 1.0
|
||||
**/
|
||||
public class FileUtils {
|
||||
|
||||
|
||||
/**
|
||||
* 解压tar.gz文件到指定目录
|
||||
*
|
||||
* @param sourceDir 源文件夹
|
||||
* @param destDir 解压后的目标文件夹
|
||||
*/
|
||||
public static void unTarGz(String sourceDir, String destDir) throws Exception {
|
||||
File outFile = new File(sourceDir);
|
||||
File[] files = outFile.listFiles();
|
||||
try {
|
||||
//创建输出目录
|
||||
createDirectory(destDir, null);
|
||||
TarInputStream tarIn;
|
||||
int index = 1;
|
||||
for (File file : files) {
|
||||
if (file.getName().contains("tar.gz")) {
|
||||
tarIn = new TarInputStream(new GZIPInputStream(
|
||||
new BufferedInputStream(new FileInputStream(file))),
|
||||
1024 * 2);
|
||||
|
||||
String outFileName = destDir + "/" + file.getName();
|
||||
OutputStream out = new FileOutputStream(new File(outFileName));
|
||||
int length = 0;
|
||||
byte[] b = new byte[2048];
|
||||
while ((length = tarIn.read(b)) != -1) {
|
||||
out.write(b, 0, length);
|
||||
}
|
||||
out.close();
|
||||
tarIn.close();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 解压gz到指定的文件夹下面
|
||||
*
|
||||
* @param sourceDir
|
||||
* @param destDir
|
||||
*/
|
||||
public static void unGzipFile(String sourceDir, String destDir) {
|
||||
//创建输出目录
|
||||
createDirectory(destDir, null);
|
||||
File sourceFile = new File(sourceDir);
|
||||
File[] files = sourceFile.listFiles();
|
||||
try {
|
||||
int index = 1;
|
||||
for (File file : files) {
|
||||
if (file.getName().contains("gz")) {
|
||||
FileInputStream fin = new FileInputStream(file);
|
||||
//建立gzip解压工作流
|
||||
GZIPInputStream gzin = new GZIPInputStream(fin);
|
||||
//建立解压文件输出流
|
||||
File tmpFile = new File(destDir + "/" + index++ + ".log");
|
||||
FileOutputStream fout = new FileOutputStream(tmpFile);
|
||||
int length;
|
||||
byte[] buf = new byte[2048];
|
||||
while ((length = gzin.read(buf, 0, buf.length)) != -1) {
|
||||
fout.write(buf, 0, length);
|
||||
}
|
||||
gzin.close();
|
||||
fout.close();
|
||||
fin.close();
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.err.println(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取文件到指定的文件夹下面
|
||||
*
|
||||
* @param sourceLogPath
|
||||
* @param destLogPath
|
||||
*/
|
||||
public static void readFileToDestLogPath(String sourceLogPath, String destLogPath) {
|
||||
File sourceFile = new File(sourceLogPath);
|
||||
File[] files = sourceFile.listFiles();
|
||||
for (File file : files) {
|
||||
String fileName = destLogPath + "/" + file.getName();
|
||||
File destFile = new File(fileName);
|
||||
if (file.getName().contains("log") && !fileName.contains("gz")) {
|
||||
try {
|
||||
if (destFile.exists()) {
|
||||
destFile.delete();
|
||||
}
|
||||
String logFile = sourceFile + "/" + file.getName();
|
||||
FileInputStream fis = new FileInputStream(logFile);
|
||||
FileOutputStream fos = new FileOutputStream(destFile);
|
||||
BufferedInputStream bis = new BufferedInputStream(fis);
|
||||
BufferedOutputStream bos = new BufferedOutputStream(fos);
|
||||
int len = 0;
|
||||
while ((len = bis.read()) != -1) {
|
||||
bos.write(len);
|
||||
}
|
||||
bos.flush();
|
||||
// 关闭资源
|
||||
fis.close();
|
||||
bis.close();
|
||||
fos.close();
|
||||
bos.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建目录
|
||||
*
|
||||
* @param outputDir
|
||||
* @param subDir
|
||||
*/
|
||||
public static void createDirectory(String outputDir, String subDir) {
|
||||
File file = new File(outputDir);
|
||||
//子目录不为空
|
||||
if (!(subDir == null || subDir.trim().equals(""))) {
|
||||
file = new File(outputDir + "/" + subDir);
|
||||
}
|
||||
if (!file.exists()) {
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
file.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String sourceDir = "/Users/ltcz99/Downloads/templog";
|
||||
String destDir = "/Users/ltcz99/Downloads/unzip/";
|
||||
//解压.gz文件到指定的文件件下面
|
||||
unGzipFile(sourceDir, destDir);
|
||||
// 解压tar.gz文件到指定的文件夹下面
|
||||
unTarGz(sourceDir, destDir);
|
||||
//读取特定的文件到指定的文件夹下面
|
||||
readFileToDestLogPath(sourceDir, destDir);
|
||||
}
|
||||
}
|
||||
//package com.docus.server;
|
||||
//
|
||||
//import org.apache.tools.tar.TarInputStream;
|
||||
//
|
||||
//import java.io.*;
|
||||
//import java.util.zip.GZIPInputStream;
|
||||
//
|
||||
///**
|
||||
// * @program: JavaCode
|
||||
// * @ClassName FileUtils
|
||||
// * @description:
|
||||
// * @author: ltcz99
|
||||
// * @create: 2023-04-16
|
||||
// * @Version 1.0
|
||||
// **/
|
||||
//public class FileUtils {
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 解压tar.gz文件到指定目录
|
||||
// *
|
||||
// * @param sourceDir 源文件夹
|
||||
// * @param destDir 解压后的目标文件夹
|
||||
// */
|
||||
// public static void unTarGz(String sourceDir, String destDir) throws Exception {
|
||||
// File outFile = new File(sourceDir);
|
||||
// File[] files = outFile.listFiles();
|
||||
// try {
|
||||
// //创建输出目录
|
||||
// createDirectory(destDir, null);
|
||||
// TarInputStream tarIn;
|
||||
// int index = 1;
|
||||
// for (File file : files) {
|
||||
// if (file.getName().contains("tar.gz")) {
|
||||
// tarIn = new TarInputStream(new GZIPInputStream(
|
||||
// new BufferedInputStream(new FileInputStream(file))),
|
||||
// 1024 * 2);
|
||||
//
|
||||
// String outFileName = destDir + "/" + file.getName();
|
||||
// OutputStream out = new FileOutputStream(new File(outFileName));
|
||||
// int length = 0;
|
||||
// byte[] b = new byte[2048];
|
||||
// while ((length = tarIn.read(b)) != -1) {
|
||||
// out.write(b, 0, length);
|
||||
// }
|
||||
// out.close();
|
||||
// tarIn.close();
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 解压gz到指定的文件夹下面
|
||||
// *
|
||||
// * @param sourceDir
|
||||
// * @param destDir
|
||||
// */
|
||||
// public static void unGzipFile(String sourceDir, String destDir) {
|
||||
// //创建输出目录
|
||||
// createDirectory(destDir, null);
|
||||
// File sourceFile = new File(sourceDir);
|
||||
// File[] files = sourceFile.listFiles();
|
||||
// try {
|
||||
// int index = 1;
|
||||
// for (File file : files) {
|
||||
// if (file.getName().contains("gz")) {
|
||||
// FileInputStream fin = new FileInputStream(file);
|
||||
// //建立gzip解压工作流
|
||||
// GZIPInputStream gzin = new GZIPInputStream(fin);
|
||||
// //建立解压文件输出流
|
||||
// File tmpFile = new File(destDir + "/" + index++ + ".log");
|
||||
// FileOutputStream fout = new FileOutputStream(tmpFile);
|
||||
// int length;
|
||||
// byte[] buf = new byte[2048];
|
||||
// while ((length = gzin.read(buf, 0, buf.length)) != -1) {
|
||||
// fout.write(buf, 0, length);
|
||||
// }
|
||||
// gzin.close();
|
||||
// fout.close();
|
||||
// fin.close();
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception ex) {
|
||||
// System.err.println(ex);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 读取文件到指定的文件夹下面
|
||||
// *
|
||||
// * @param sourceLogPath
|
||||
// * @param destLogPath
|
||||
// */
|
||||
// public static void readFileToDestLogPath(String sourceLogPath, String destLogPath) {
|
||||
// File sourceFile = new File(sourceLogPath);
|
||||
// File[] files = sourceFile.listFiles();
|
||||
// for (File file : files) {
|
||||
// String fileName = destLogPath + "/" + file.getName();
|
||||
// File destFile = new File(fileName);
|
||||
// if (file.getName().contains("log") && !fileName.contains("gz")) {
|
||||
// try {
|
||||
// if (destFile.exists()) {
|
||||
// destFile.delete();
|
||||
// }
|
||||
// String logFile = sourceFile + "/" + file.getName();
|
||||
// FileInputStream fis = new FileInputStream(logFile);
|
||||
// FileOutputStream fos = new FileOutputStream(destFile);
|
||||
// BufferedInputStream bis = new BufferedInputStream(fis);
|
||||
// BufferedOutputStream bos = new BufferedOutputStream(fos);
|
||||
// int len = 0;
|
||||
// while ((len = bis.read()) != -1) {
|
||||
// bos.write(len);
|
||||
// }
|
||||
// bos.flush();
|
||||
// // 关闭资源
|
||||
// fis.close();
|
||||
// bis.close();
|
||||
// fos.close();
|
||||
// bos.close();
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 创建目录
|
||||
// *
|
||||
// * @param outputDir
|
||||
// * @param subDir
|
||||
// */
|
||||
// public static void createDirectory(String outputDir, String subDir) {
|
||||
// File file = new File(outputDir);
|
||||
// //子目录不为空
|
||||
// if (!(subDir == null || subDir.trim().equals(""))) {
|
||||
// file = new File(outputDir + "/" + subDir);
|
||||
// }
|
||||
// if (!file.exists()) {
|
||||
// if (!file.getParentFile().exists()) {
|
||||
// file.getParentFile().mkdirs();
|
||||
// }
|
||||
// file.mkdirs();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static void main(String[] args) throws Exception {
|
||||
// String sourceDir = "/Users/ltcz99/Downloads/templog";
|
||||
// String destDir = "/Users/ltcz99/Downloads/unzip/";
|
||||
// //解压.gz文件到指定的文件件下面
|
||||
// unGzipFile(sourceDir, destDir);
|
||||
// // 解压tar.gz文件到指定的文件夹下面
|
||||
// unTarGz(sourceDir, destDir);
|
||||
// //读取特定的文件到指定的文件夹下面
|
||||
// readFileToDestLogPath(sourceDir, destDir);
|
||||
// }
|
||||
//}
|
||||
|
@ -1,313 +1,313 @@
|
||||
package com.docus.server;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import oshi.SystemInfo;
|
||||
import oshi.hardware.CentralProcessor;
|
||||
import oshi.hardware.GlobalMemory;
|
||||
import oshi.hardware.HardwareAbstractionLayer;
|
||||
import oshi.hardware.NetworkIF;
|
||||
import oshi.software.os.FileSystem;
|
||||
import oshi.software.os.OSFileStore;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
import oshi.util.Util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Formatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* 系统消息工具类
|
||||
**/
|
||||
public class SystemInfoUtils {
|
||||
|
||||
private static final int OSHI_WAIT_SECOND = 1000;
|
||||
private static final int SLEEP_TIME = 2 * 1000;
|
||||
private static SystemInfo systemInfo = new SystemInfo();
|
||||
private static HardwareAbstractionLayer hardware = systemInfo.getHardware();
|
||||
private static OperatingSystem operatingSystem = systemInfo.getOperatingSystem();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
JSONObject info = getInfo();
|
||||
System.out.println(info);
|
||||
}
|
||||
|
||||
public static JSONObject getCpuInfo() {
|
||||
JSONObject cpuInfo = new JSONObject();
|
||||
CentralProcessor processor = hardware.getProcessor();
|
||||
// CPU信息
|
||||
long[] prevTicks = processor.getSystemCpuLoadTicks();
|
||||
Util.sleep(OSHI_WAIT_SECOND);
|
||||
long[] ticks = processor.getSystemCpuLoadTicks();
|
||||
long nice = ticks[CentralProcessor.TickType.NICE.getIndex()] - prevTicks[CentralProcessor.TickType.NICE.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 cSys = ticks[CentralProcessor.TickType.SYSTEM.getIndex()] - prevTicks[CentralProcessor.TickType.SYSTEM.getIndex()];
|
||||
long user = ticks[CentralProcessor.TickType.USER.getIndex()] - prevTicks[CentralProcessor.TickType.USER.getIndex()];
|
||||
long iowait = ticks[CentralProcessor.TickType.IOWAIT.getIndex()] - prevTicks[CentralProcessor.TickType.IOWAIT.getIndex()];
|
||||
long idle = ticks[CentralProcessor.TickType.IDLE.getIndex()] - prevTicks[CentralProcessor.TickType.IDLE.getIndex()];
|
||||
long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
|
||||
//cpu核数
|
||||
cpuInfo.put("cpuNum", processor.getLogicalProcessorCount());
|
||||
//cpu系统使用率
|
||||
cpuInfo.put("cSys", new DecimalFormat("#.##%").format(cSys * 1.0 / totalCpu));
|
||||
//cpu用户使用率
|
||||
cpuInfo.put("user", new DecimalFormat("#.##%").format(user * 1.0 / totalCpu));
|
||||
//cpu当前等待率
|
||||
cpuInfo.put("iowait", new DecimalFormat("#.##%").format(iowait * 1.0 / totalCpu));
|
||||
//cpu当前使用率
|
||||
cpuInfo.put("idle", new DecimalFormat("#.##%").format(1.0 - (idle * 1.0 / totalCpu)));
|
||||
return cpuInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统jvm信息
|
||||
*/
|
||||
public static JSONObject getJvmInfo() {
|
||||
JSONObject cpuInfo = new JSONObject();
|
||||
Properties props = System.getProperties();
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
long jvmTotalMemoryByte = runtime.totalMemory();
|
||||
long freeMemoryByte = runtime.freeMemory();
|
||||
//jvm总内存
|
||||
cpuInfo.put("total", formatByte(runtime.totalMemory()));
|
||||
//空闲空间
|
||||
cpuInfo.put("free", formatByte(runtime.freeMemory()));
|
||||
//jvm最大可申请
|
||||
cpuInfo.put("max", formatByte(runtime.maxMemory()));
|
||||
//vm已使用内存
|
||||
cpuInfo.put("user", formatByte(jvmTotalMemoryByte - freeMemoryByte));
|
||||
//jvm内存使用率
|
||||
cpuInfo.put("usageRate", new DecimalFormat("#.##%").format((jvmTotalMemoryByte - freeMemoryByte) * 1.0 / jvmTotalMemoryByte));
|
||||
//jdk版本
|
||||
cpuInfo.put("jdkVersion", props.getProperty("java.version"));
|
||||
//jdk路径
|
||||
cpuInfo.put("jdkHome", props.getProperty("java.home"));
|
||||
return cpuInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统内存信息
|
||||
*/
|
||||
public static JSONObject getMemInfo() {
|
||||
JSONObject cpuInfo = new JSONObject();
|
||||
GlobalMemory memory = systemInfo.getHardware().getMemory();
|
||||
//总内存
|
||||
long totalByte = memory.getTotal();
|
||||
//剩余
|
||||
long acaliableByte = memory.getAvailable();
|
||||
//总内存
|
||||
cpuInfo.put("total", formatByte(totalByte));
|
||||
//使用
|
||||
cpuInfo.put("used", formatByte(totalByte - acaliableByte));
|
||||
//剩余内存
|
||||
cpuInfo.put("free", formatByte(acaliableByte));
|
||||
//使用率
|
||||
cpuInfo.put("usageRate", new DecimalFormat("#.##%").format((totalByte - acaliableByte) * 1.0 / totalByte));
|
||||
return cpuInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 带宽
|
||||
*/
|
||||
public static JSONArray networkIFs() throws Exception {
|
||||
JSONObject cpuInfo;
|
||||
JSONArray sysFiles = new JSONArray();
|
||||
|
||||
List<NetworkIF> networkIFs = systemInfo.getHardware().getNetworkIFs();
|
||||
for (NetworkIF networkIF : networkIFs) {
|
||||
String name = networkIF.getName();
|
||||
long receiveBytes = networkIF.getBytesRecv();
|
||||
long transmitBytes = networkIF.getBytesSent();
|
||||
|
||||
cpuInfo = new JSONObject();
|
||||
//名称
|
||||
cpuInfo.put("name", name);
|
||||
//网络接收
|
||||
cpuInfo.put("receiveBytes", formatNumber(receiveBytes / (1024.0 * (2 * 1000 / 1000))));
|
||||
//网络发送
|
||||
cpuInfo.put("transmitBytes", formatNumber(transmitBytes / (1024.0 * (2 * 1000 / 1000))));
|
||||
|
||||
sysFiles.add(cpuInfo);
|
||||
}
|
||||
return sysFiles;
|
||||
}
|
||||
|
||||
public static JSONObject getNetWork() {
|
||||
JSONObject networkInfo = new JSONObject();
|
||||
Properties props = System.getProperties();
|
||||
String os = props.getProperty("os.name").toLowerCase();
|
||||
os = os.startsWith("win") ? "windows" : "linux";
|
||||
Map<String, String> result = new HashMap<>();
|
||||
Process pro = null;
|
||||
Runtime r = Runtime.getRuntime();
|
||||
BufferedReader input = null;
|
||||
try {
|
||||
String command = "windows".equals(os) ? "netstat -e" : "ifconfig";
|
||||
pro = r.exec(command);
|
||||
input = new BufferedReader(new InputStreamReader(pro.getInputStream()));
|
||||
long result1[] = readInLine(input, os);
|
||||
Thread.sleep(SLEEP_TIME);
|
||||
pro.destroy();
|
||||
input.close();
|
||||
pro = r.exec(command);
|
||||
input = new BufferedReader(new InputStreamReader(pro.getInputStream()));
|
||||
long result2[] = readInLine(input, os);
|
||||
String rxPercent = formatNumber((result2[0] - result1[0]) / (1024.0 * (SLEEP_TIME / 1000)));// 下行速率(kB/s)
|
||||
String txPercent = formatNumber((result2[1] - result1[1]) / (1024.0 * (SLEEP_TIME / 1000)));// 上行速率(kB/s)
|
||||
networkInfo.put("rxPercent", rxPercent);
|
||||
networkInfo.put("txPercent", txPercent);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (input != null) {
|
||||
try {
|
||||
input.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Optional.ofNullable(pro).ifPresent(p -> p.destroy());
|
||||
}
|
||||
return networkInfo;
|
||||
}
|
||||
|
||||
private static long[] readInLine(BufferedReader input, String osType) {
|
||||
long arr[] = new long[2];
|
||||
StringTokenizer tokenStat = null;
|
||||
try {
|
||||
if (osType.equals("linux")) { // 获取linux环境下的网口上下行速率
|
||||
long rx = 0, tx = 0;
|
||||
String line = null;
|
||||
//RX packets:4171603 errors:0 dropped:0 overruns:0 frame:0
|
||||
//TX packets:4171603 errors:0 dropped:0 overruns:0 carrier:0
|
||||
while ((line = input.readLine()) != null) {
|
||||
if (line.indexOf("RX packets") >= 0) {
|
||||
rx += Long.parseLong(line.substring(line.indexOf("RX packets") + 11, line.indexOf(" ", line.indexOf("RX packets") + 11)));
|
||||
} else if (line.indexOf("TX packets") >= 0) {
|
||||
tx += Long.parseLong(line.substring(line.indexOf("TX packets") + 11, line.indexOf(" ", line.indexOf("TX packets") + 11)));
|
||||
}
|
||||
}
|
||||
arr[0] = rx;
|
||||
arr[1] = tx;
|
||||
} else { // 获取windows环境下的网口上下行速率
|
||||
input.readLine();
|
||||
input.readLine();
|
||||
input.readLine();
|
||||
input.readLine();
|
||||
tokenStat = new StringTokenizer(input.readLine());
|
||||
tokenStat.nextToken();
|
||||
arr[0] = Long.parseLong(tokenStat.nextToken());
|
||||
arr[1] = Long.parseLong(tokenStat.nextToken());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
||||
private static String formatNumber(double f) {
|
||||
return new Formatter().format("%.2f", f).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统盘符信息
|
||||
*/
|
||||
public static JSONArray getSysFileInfo() {
|
||||
JSONObject cpuInfo;
|
||||
JSONArray sysFiles = new JSONArray();
|
||||
FileSystem fileSystem = operatingSystem.getFileSystem();
|
||||
List<OSFileStore> fsArray = fileSystem.getFileStores();
|
||||
for (OSFileStore fs : fsArray) {
|
||||
cpuInfo = new JSONObject();
|
||||
//盘符路径
|
||||
cpuInfo.put("dirName", fs.getMount());
|
||||
//盘符类型
|
||||
cpuInfo.put("sysTypeName", fs.getType());
|
||||
//文件类型
|
||||
cpuInfo.put("typeName", fs.getName());
|
||||
//总大小
|
||||
cpuInfo.put("total", formatByte(fs.getTotalSpace()));
|
||||
//剩余大小
|
||||
cpuInfo.put("free", formatByte(fs.getUsableSpace()));
|
||||
//已经使用量
|
||||
cpuInfo.put("used", formatByte(fs.getTotalSpace() - fs.getUsableSpace()));
|
||||
if (fs.getTotalSpace() == 0) {
|
||||
//资源的使用率
|
||||
cpuInfo.put("usage", 0);
|
||||
} else {
|
||||
cpuInfo.put("usage", new DecimalFormat("#.##%").format((fs.getTotalSpace() - fs.getUsableSpace()) * 1.0 / fs.getTotalSpace()));
|
||||
}
|
||||
sysFiles.add(cpuInfo);
|
||||
}
|
||||
return sysFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统信息
|
||||
*/
|
||||
public static JSONObject getSysInfo() throws UnknownHostException {
|
||||
JSONObject cpuInfo = new JSONObject();
|
||||
Properties props = System.getProperties();
|
||||
//操作系统名
|
||||
cpuInfo.put("osName", props.getProperty("os.name"));
|
||||
//系统架构
|
||||
cpuInfo.put("osArch", props.getProperty("os.arch"));
|
||||
//服务器名称
|
||||
cpuInfo.put("computerName", InetAddress.getLocalHost().getHostName());
|
||||
//服务器Ip
|
||||
cpuInfo.put("computerIp", InetAddress.getLocalHost().getHostAddress());
|
||||
//项目路径
|
||||
cpuInfo.put("userDir", props.getProperty("user.dir"));
|
||||
return cpuInfo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 所有系统信息
|
||||
*/
|
||||
public static JSONObject getInfo() throws Exception {
|
||||
JSONObject info = new JSONObject();
|
||||
info.put("cpuInfo", getCpuInfo());
|
||||
info.put("jvmInfo", getJvmInfo());
|
||||
info.put("memInfo", getMemInfo());
|
||||
info.put("sysInfo", getSysInfo());
|
||||
info.put("sysFileInfo", getSysFileInfo());
|
||||
info.put("networkInfo", getNetWork());
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单位转换
|
||||
*/
|
||||
private static String formatByte(long byteNumber) {
|
||||
//换算单位
|
||||
double FORMAT = 1024.0;
|
||||
double kbNumber = byteNumber / FORMAT;
|
||||
if (kbNumber < FORMAT) {
|
||||
return new DecimalFormat("#.##KB").format(kbNumber);
|
||||
}
|
||||
double mbNumber = kbNumber / FORMAT;
|
||||
if (mbNumber < FORMAT) {
|
||||
return new DecimalFormat("#.##MB").format(mbNumber);
|
||||
}
|
||||
double gbNumber = mbNumber / FORMAT;
|
||||
if (gbNumber < FORMAT) {
|
||||
return new DecimalFormat("#.##GB").format(gbNumber);
|
||||
}
|
||||
double tbNumber = gbNumber / FORMAT;
|
||||
return new DecimalFormat("#.##TB").format(tbNumber);
|
||||
}
|
||||
}
|
||||
//package com.docus.server;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSONArray;
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import oshi.SystemInfo;
|
||||
//import oshi.hardware.CentralProcessor;
|
||||
//import oshi.hardware.GlobalMemory;
|
||||
//import oshi.hardware.HardwareAbstractionLayer;
|
||||
//import oshi.hardware.NetworkIF;
|
||||
//import oshi.software.os.FileSystem;
|
||||
//import oshi.software.os.OSFileStore;
|
||||
//import oshi.software.os.OperatingSystem;
|
||||
//import oshi.util.Util;
|
||||
//
|
||||
//import java.io.BufferedReader;
|
||||
//import java.io.IOException;
|
||||
//import java.io.InputStreamReader;
|
||||
//import java.net.InetAddress;
|
||||
//import java.net.UnknownHostException;
|
||||
//import java.text.DecimalFormat;
|
||||
//import java.util.Formatter;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//import java.util.Optional;
|
||||
//import java.util.Properties;
|
||||
//import java.util.StringTokenizer;
|
||||
//
|
||||
///**
|
||||
// * 系统消息工具类
|
||||
// **/
|
||||
//public class SystemInfoUtils {
|
||||
//
|
||||
// private static final int OSHI_WAIT_SECOND = 1000;
|
||||
// private static final int SLEEP_TIME = 2 * 1000;
|
||||
// private static SystemInfo systemInfo = new SystemInfo();
|
||||
// private static HardwareAbstractionLayer hardware = systemInfo.getHardware();
|
||||
// private static OperatingSystem operatingSystem = systemInfo.getOperatingSystem();
|
||||
//
|
||||
// public static void main(String[] args) throws Exception {
|
||||
// JSONObject info = getInfo();
|
||||
// System.out.println(info);
|
||||
// }
|
||||
//
|
||||
// public static JSONObject getCpuInfo() {
|
||||
// JSONObject cpuInfo = new JSONObject();
|
||||
// CentralProcessor processor = hardware.getProcessor();
|
||||
// // CPU信息
|
||||
// long[] prevTicks = processor.getSystemCpuLoadTicks();
|
||||
// Util.sleep(OSHI_WAIT_SECOND);
|
||||
// long[] ticks = processor.getSystemCpuLoadTicks();
|
||||
// long nice = ticks[CentralProcessor.TickType.NICE.getIndex()] - prevTicks[CentralProcessor.TickType.NICE.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 cSys = ticks[CentralProcessor.TickType.SYSTEM.getIndex()] - prevTicks[CentralProcessor.TickType.SYSTEM.getIndex()];
|
||||
// long user = ticks[CentralProcessor.TickType.USER.getIndex()] - prevTicks[CentralProcessor.TickType.USER.getIndex()];
|
||||
// long iowait = ticks[CentralProcessor.TickType.IOWAIT.getIndex()] - prevTicks[CentralProcessor.TickType.IOWAIT.getIndex()];
|
||||
// long idle = ticks[CentralProcessor.TickType.IDLE.getIndex()] - prevTicks[CentralProcessor.TickType.IDLE.getIndex()];
|
||||
// long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
|
||||
// //cpu核数
|
||||
// cpuInfo.put("cpuNum", processor.getLogicalProcessorCount());
|
||||
// //cpu系统使用率
|
||||
// cpuInfo.put("cSys", new DecimalFormat("#.##%").format(cSys * 1.0 / totalCpu));
|
||||
// //cpu用户使用率
|
||||
// cpuInfo.put("user", new DecimalFormat("#.##%").format(user * 1.0 / totalCpu));
|
||||
// //cpu当前等待率
|
||||
// cpuInfo.put("iowait", new DecimalFormat("#.##%").format(iowait * 1.0 / totalCpu));
|
||||
// //cpu当前使用率
|
||||
// cpuInfo.put("idle", new DecimalFormat("#.##%").format(1.0 - (idle * 1.0 / totalCpu)));
|
||||
// return cpuInfo;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 系统jvm信息
|
||||
// */
|
||||
// public static JSONObject getJvmInfo() {
|
||||
// JSONObject cpuInfo = new JSONObject();
|
||||
// Properties props = System.getProperties();
|
||||
// Runtime runtime = Runtime.getRuntime();
|
||||
// long jvmTotalMemoryByte = runtime.totalMemory();
|
||||
// long freeMemoryByte = runtime.freeMemory();
|
||||
// //jvm总内存
|
||||
// cpuInfo.put("total", formatByte(runtime.totalMemory()));
|
||||
// //空闲空间
|
||||
// cpuInfo.put("free", formatByte(runtime.freeMemory()));
|
||||
// //jvm最大可申请
|
||||
// cpuInfo.put("max", formatByte(runtime.maxMemory()));
|
||||
// //vm已使用内存
|
||||
// cpuInfo.put("user", formatByte(jvmTotalMemoryByte - freeMemoryByte));
|
||||
// //jvm内存使用率
|
||||
// cpuInfo.put("usageRate", new DecimalFormat("#.##%").format((jvmTotalMemoryByte - freeMemoryByte) * 1.0 / jvmTotalMemoryByte));
|
||||
// //jdk版本
|
||||
// cpuInfo.put("jdkVersion", props.getProperty("java.version"));
|
||||
// //jdk路径
|
||||
// cpuInfo.put("jdkHome", props.getProperty("java.home"));
|
||||
// return cpuInfo;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 系统内存信息
|
||||
// */
|
||||
// public static JSONObject getMemInfo() {
|
||||
// JSONObject cpuInfo = new JSONObject();
|
||||
// GlobalMemory memory = systemInfo.getHardware().getMemory();
|
||||
// //总内存
|
||||
// long totalByte = memory.getTotal();
|
||||
// //剩余
|
||||
// long acaliableByte = memory.getAvailable();
|
||||
// //总内存
|
||||
// cpuInfo.put("total", formatByte(totalByte));
|
||||
// //使用
|
||||
// cpuInfo.put("used", formatByte(totalByte - acaliableByte));
|
||||
// //剩余内存
|
||||
// cpuInfo.put("free", formatByte(acaliableByte));
|
||||
// //使用率
|
||||
// cpuInfo.put("usageRate", new DecimalFormat("#.##%").format((totalByte - acaliableByte) * 1.0 / totalByte));
|
||||
// return cpuInfo;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 带宽
|
||||
// */
|
||||
// public static JSONArray networkIFs() throws Exception {
|
||||
// JSONObject cpuInfo;
|
||||
// JSONArray sysFiles = new JSONArray();
|
||||
//
|
||||
// List<NetworkIF> networkIFs = systemInfo.getHardware().getNetworkIFs();
|
||||
// for (NetworkIF networkIF : networkIFs) {
|
||||
// String name = networkIF.getName();
|
||||
// long receiveBytes = networkIF.getBytesRecv();
|
||||
// long transmitBytes = networkIF.getBytesSent();
|
||||
//
|
||||
// cpuInfo = new JSONObject();
|
||||
// //名称
|
||||
// cpuInfo.put("name", name);
|
||||
// //网络接收
|
||||
// cpuInfo.put("receiveBytes", formatNumber(receiveBytes / (1024.0 * (2 * 1000 / 1000))));
|
||||
// //网络发送
|
||||
// cpuInfo.put("transmitBytes", formatNumber(transmitBytes / (1024.0 * (2 * 1000 / 1000))));
|
||||
//
|
||||
// sysFiles.add(cpuInfo);
|
||||
// }
|
||||
// return sysFiles;
|
||||
// }
|
||||
//
|
||||
// public static JSONObject getNetWork() {
|
||||
// JSONObject networkInfo = new JSONObject();
|
||||
// Properties props = System.getProperties();
|
||||
// String os = props.getProperty("os.name").toLowerCase();
|
||||
// os = os.startsWith("win") ? "windows" : "linux";
|
||||
// Map<String, String> result = new HashMap<>();
|
||||
// Process pro = null;
|
||||
// Runtime r = Runtime.getRuntime();
|
||||
// BufferedReader input = null;
|
||||
// try {
|
||||
// String command = "windows".equals(os) ? "netstat -e" : "ifconfig";
|
||||
// pro = r.exec(command);
|
||||
// input = new BufferedReader(new InputStreamReader(pro.getInputStream()));
|
||||
// long result1[] = readInLine(input, os);
|
||||
// Thread.sleep(SLEEP_TIME);
|
||||
// pro.destroy();
|
||||
// input.close();
|
||||
// pro = r.exec(command);
|
||||
// input = new BufferedReader(new InputStreamReader(pro.getInputStream()));
|
||||
// long result2[] = readInLine(input, os);
|
||||
// String rxPercent = formatNumber((result2[0] - result1[0]) / (1024.0 * (SLEEP_TIME / 1000)));// 下行速率(kB/s)
|
||||
// String txPercent = formatNumber((result2[1] - result1[1]) / (1024.0 * (SLEEP_TIME / 1000)));// 上行速率(kB/s)
|
||||
// networkInfo.put("rxPercent", rxPercent);
|
||||
// networkInfo.put("txPercent", txPercent);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// } finally {
|
||||
// if (input != null) {
|
||||
// try {
|
||||
// input.close();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// Optional.ofNullable(pro).ifPresent(p -> p.destroy());
|
||||
// }
|
||||
// return networkInfo;
|
||||
// }
|
||||
//
|
||||
// private static long[] readInLine(BufferedReader input, String osType) {
|
||||
// long arr[] = new long[2];
|
||||
// StringTokenizer tokenStat = null;
|
||||
// try {
|
||||
// if (osType.equals("linux")) { // 获取linux环境下的网口上下行速率
|
||||
// long rx = 0, tx = 0;
|
||||
// String line = null;
|
||||
// //RX packets:4171603 errors:0 dropped:0 overruns:0 frame:0
|
||||
// //TX packets:4171603 errors:0 dropped:0 overruns:0 carrier:0
|
||||
// while ((line = input.readLine()) != null) {
|
||||
// if (line.indexOf("RX packets") >= 0) {
|
||||
// rx += Long.parseLong(line.substring(line.indexOf("RX packets") + 11, line.indexOf(" ", line.indexOf("RX packets") + 11)));
|
||||
// } else if (line.indexOf("TX packets") >= 0) {
|
||||
// tx += Long.parseLong(line.substring(line.indexOf("TX packets") + 11, line.indexOf(" ", line.indexOf("TX packets") + 11)));
|
||||
// }
|
||||
// }
|
||||
// arr[0] = rx;
|
||||
// arr[1] = tx;
|
||||
// } else { // 获取windows环境下的网口上下行速率
|
||||
// input.readLine();
|
||||
// input.readLine();
|
||||
// input.readLine();
|
||||
// input.readLine();
|
||||
// tokenStat = new StringTokenizer(input.readLine());
|
||||
// tokenStat.nextToken();
|
||||
// arr[0] = Long.parseLong(tokenStat.nextToken());
|
||||
// arr[1] = Long.parseLong(tokenStat.nextToken());
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return arr;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private static String formatNumber(double f) {
|
||||
// return new Formatter().format("%.2f", f).toString();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 系统盘符信息
|
||||
// */
|
||||
// public static JSONArray getSysFileInfo() {
|
||||
// JSONObject cpuInfo;
|
||||
// JSONArray sysFiles = new JSONArray();
|
||||
// FileSystem fileSystem = operatingSystem.getFileSystem();
|
||||
// List<OSFileStore> fsArray = fileSystem.getFileStores();
|
||||
// for (OSFileStore fs : fsArray) {
|
||||
// cpuInfo = new JSONObject();
|
||||
// //盘符路径
|
||||
// cpuInfo.put("dirName", fs.getMount());
|
||||
// //盘符类型
|
||||
// cpuInfo.put("sysTypeName", fs.getType());
|
||||
// //文件类型
|
||||
// cpuInfo.put("typeName", fs.getName());
|
||||
// //总大小
|
||||
// cpuInfo.put("total", formatByte(fs.getTotalSpace()));
|
||||
// //剩余大小
|
||||
// cpuInfo.put("free", formatByte(fs.getUsableSpace()));
|
||||
// //已经使用量
|
||||
// cpuInfo.put("used", formatByte(fs.getTotalSpace() - fs.getUsableSpace()));
|
||||
// if (fs.getTotalSpace() == 0) {
|
||||
// //资源的使用率
|
||||
// cpuInfo.put("usage", 0);
|
||||
// } else {
|
||||
// cpuInfo.put("usage", new DecimalFormat("#.##%").format((fs.getTotalSpace() - fs.getUsableSpace()) * 1.0 / fs.getTotalSpace()));
|
||||
// }
|
||||
// sysFiles.add(cpuInfo);
|
||||
// }
|
||||
// return sysFiles;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 系统信息
|
||||
// */
|
||||
// public static JSONObject getSysInfo() throws UnknownHostException {
|
||||
// JSONObject cpuInfo = new JSONObject();
|
||||
// Properties props = System.getProperties();
|
||||
// //操作系统名
|
||||
// cpuInfo.put("osName", props.getProperty("os.name"));
|
||||
// //系统架构
|
||||
// cpuInfo.put("osArch", props.getProperty("os.arch"));
|
||||
// //服务器名称
|
||||
// cpuInfo.put("computerName", InetAddress.getLocalHost().getHostName());
|
||||
// //服务器Ip
|
||||
// cpuInfo.put("computerIp", InetAddress.getLocalHost().getHostAddress());
|
||||
// //项目路径
|
||||
// cpuInfo.put("userDir", props.getProperty("user.dir"));
|
||||
// return cpuInfo;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 所有系统信息
|
||||
// */
|
||||
// public static JSONObject getInfo() throws Exception {
|
||||
// JSONObject info = new JSONObject();
|
||||
// info.put("cpuInfo", getCpuInfo());
|
||||
// info.put("jvmInfo", getJvmInfo());
|
||||
// info.put("memInfo", getMemInfo());
|
||||
// info.put("sysInfo", getSysInfo());
|
||||
// info.put("sysFileInfo", getSysFileInfo());
|
||||
// info.put("networkInfo", getNetWork());
|
||||
// return info;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 单位转换
|
||||
// */
|
||||
// private static String formatByte(long byteNumber) {
|
||||
// //换算单位
|
||||
// double FORMAT = 1024.0;
|
||||
// double kbNumber = byteNumber / FORMAT;
|
||||
// if (kbNumber < FORMAT) {
|
||||
// return new DecimalFormat("#.##KB").format(kbNumber);
|
||||
// }
|
||||
// double mbNumber = kbNumber / FORMAT;
|
||||
// if (mbNumber < FORMAT) {
|
||||
// return new DecimalFormat("#.##MB").format(mbNumber);
|
||||
// }
|
||||
// double gbNumber = mbNumber / FORMAT;
|
||||
// if (gbNumber < FORMAT) {
|
||||
// return new DecimalFormat("#.##GB").format(gbNumber);
|
||||
// }
|
||||
// double tbNumber = gbNumber / FORMAT;
|
||||
// return new DecimalFormat("#.##TB").format(tbNumber);
|
||||
// }
|
||||
//}
|
||||
|
@ -1,87 +1,87 @@
|
||||
package com.docus.server;
|
||||
|
||||
import cn.smallbun.screw.core.Configuration;
|
||||
import cn.smallbun.screw.core.engine.EngineConfig;
|
||||
import cn.smallbun.screw.core.engine.EngineFileType;
|
||||
import cn.smallbun.screw.core.engine.EngineTemplateType;
|
||||
import cn.smallbun.screw.core.execute.DocumentationExecute;
|
||||
import cn.smallbun.screw.core.process.ProcessConfig;
|
||||
import com.docus.server.api.ocr.OcrApi;
|
||||
import com.docus.server.vo.ocr.OcrResponse;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.sql.DataSource;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SpringBootTest
|
||||
class ScrewTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
@Resource
|
||||
private OcrApi ocrApi;
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
|
||||
HikariConfig hikariConfig = new HikariConfig();
|
||||
hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
|
||||
hikariConfig.setJdbcUrl("jdbc:mysql://db.docus.cn:3306/docus-collector-scheduling?autoReconnect=true&allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai");
|
||||
hikariConfig.setUsername("docus");
|
||||
hikariConfig.setPassword("docus702");
|
||||
//设置可以获取tables remarks信息
|
||||
hikariConfig.addDataSourceProperty("useInformationSchema", "true");
|
||||
hikariConfig.setMinimumIdle(2);
|
||||
hikariConfig.setMaximumPoolSize(5);
|
||||
DataSource dataSource = new HikariDataSource(hikariConfig);
|
||||
|
||||
//生成文件配置
|
||||
EngineConfig engineConfig = EngineConfig
|
||||
.builder()
|
||||
//文件生成路径
|
||||
.fileOutputDir("h:\\file")
|
||||
//打开目录
|
||||
.openOutputDir(false)
|
||||
//文件类型
|
||||
.fileType(EngineFileType.HTML)
|
||||
//生成模板实现
|
||||
.produceType(EngineTemplateType.freemarker)
|
||||
.build();
|
||||
//配置想要生成的表
|
||||
ProcessConfig processConfig = ProcessConfig
|
||||
.builder()
|
||||
//根据名称指定表生成
|
||||
.designatedTableName(new ArrayList<>())
|
||||
//根据表前缀生成
|
||||
.designatedTablePrefix(new ArrayList<>())
|
||||
//根据表后缀生成
|
||||
.designatedTableSuffix(new ArrayList<>())
|
||||
//忽略表名
|
||||
.ignoreTableName(new ArrayList<>())
|
||||
//忽略表前缀
|
||||
.ignoreTablePrefix(new ArrayList<>())
|
||||
//忽略表后缀
|
||||
.ignoreTableSuffix(new ArrayList<>())
|
||||
.build();
|
||||
//生成文档配置
|
||||
Configuration configuration = Configuration.builder()
|
||||
.version("1.0.0")
|
||||
.description("描述")
|
||||
.dataSource(dataSource)
|
||||
.engineConfig(engineConfig)
|
||||
.produceConfig(processConfig)
|
||||
.build();
|
||||
|
||||
//生成
|
||||
new DocumentationExecute(configuration).execute();
|
||||
}
|
||||
}
|
||||
//package com.docus.server;
|
||||
//
|
||||
//import cn.smallbun.screw.core.Configuration;
|
||||
//import cn.smallbun.screw.core.engine.EngineConfig;
|
||||
//import cn.smallbun.screw.core.engine.EngineFileType;
|
||||
//import cn.smallbun.screw.core.engine.EngineTemplateType;
|
||||
//import cn.smallbun.screw.core.execute.DocumentationExecute;
|
||||
//import cn.smallbun.screw.core.process.ProcessConfig;
|
||||
//import com.docus.server.api.ocr.OcrApi;
|
||||
//import com.docus.server.vo.ocr.OcrResponse;
|
||||
//import com.zaxxer.hikari.HikariConfig;
|
||||
//import com.zaxxer.hikari.HikariDataSource;
|
||||
//import org.junit.jupiter.api.Test;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.boot.test.context.SpringBootTest;
|
||||
//import org.springframework.context.ApplicationContext;
|
||||
//
|
||||
//import javax.annotation.Resource;
|
||||
//import javax.sql.DataSource;
|
||||
//import java.io.File;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Map;
|
||||
//
|
||||
//@SpringBootTest
|
||||
//class ScrewTests {
|
||||
//
|
||||
// @Autowired
|
||||
// private ApplicationContext applicationContext;
|
||||
// @Resource
|
||||
// private OcrApi ocrApi;
|
||||
//
|
||||
// @Test
|
||||
// void test() {
|
||||
//
|
||||
// HikariConfig hikariConfig = new HikariConfig();
|
||||
// hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
|
||||
// hikariConfig.setJdbcUrl("jdbc:mysql://db.docus.cn:3306/docus-collector-scheduling?autoReconnect=true&allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai");
|
||||
// hikariConfig.setUsername("docus");
|
||||
// hikariConfig.setPassword("docus702");
|
||||
// //设置可以获取tables remarks信息
|
||||
// hikariConfig.addDataSourceProperty("useInformationSchema", "true");
|
||||
// hikariConfig.setMinimumIdle(2);
|
||||
// hikariConfig.setMaximumPoolSize(5);
|
||||
// DataSource dataSource = new HikariDataSource(hikariConfig);
|
||||
//
|
||||
// //生成文件配置
|
||||
// EngineConfig engineConfig = EngineConfig
|
||||
// .builder()
|
||||
// //文件生成路径
|
||||
// .fileOutputDir("h:\\file")
|
||||
// //打开目录
|
||||
// .openOutputDir(false)
|
||||
// //文件类型
|
||||
// .fileType(EngineFileType.HTML)
|
||||
// //生成模板实现
|
||||
// .produceType(EngineTemplateType.freemarker)
|
||||
// .build();
|
||||
// //配置想要生成的表
|
||||
// ProcessConfig processConfig = ProcessConfig
|
||||
// .builder()
|
||||
// //根据名称指定表生成
|
||||
// .designatedTableName(new ArrayList<>())
|
||||
// //根据表前缀生成
|
||||
// .designatedTablePrefix(new ArrayList<>())
|
||||
// //根据表后缀生成
|
||||
// .designatedTableSuffix(new ArrayList<>())
|
||||
// //忽略表名
|
||||
// .ignoreTableName(new ArrayList<>())
|
||||
// //忽略表前缀
|
||||
// .ignoreTablePrefix(new ArrayList<>())
|
||||
// //忽略表后缀
|
||||
// .ignoreTableSuffix(new ArrayList<>())
|
||||
// .build();
|
||||
// //生成文档配置
|
||||
// Configuration configuration = Configuration.builder()
|
||||
// .version("1.0.0")
|
||||
// .description("描述")
|
||||
// .dataSource(dataSource)
|
||||
// .engineConfig(engineConfig)
|
||||
// .produceConfig(processConfig)
|
||||
// .build();
|
||||
//
|
||||
// //生成
|
||||
// new DocumentationExecute(configuration).execute();
|
||||
// }
|
||||
//}
|
||||
|
Loading…
Reference in New Issue