<!-- 获取内存等 -->
<!-- https://mvnrepository.com/artifact/com.github.oshi/oshi-core -->
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>6.1.2</version>
</dependency>
采用oshi,主要 API
oshi.SystemInfo;
oshi.hardware.CentralProcessor;
oshi.hardware.GlobalMemory;
oshi.software.os.FileSystem;
oshi.software.os.OSFileStore;
SystemInfo systemInfo = new SystemInfo();
# 获取CPU个数
CentralProcessor processor = systemInfo.getHardware().getProcessor();
int cpuNum = processor.getLogicalProcessorCount();
# 获取内存信息
GlobalMemory globalMemory = systemInfo.getHardware().getMemory();
long total = globalMemory.getTotal();
long available = globalMemory.getAvailable();
# 获取文件信息
FileSystem fileSystem = systemInfo.getOperatingSystem().getFileSystem();
List<OSFileStore> osFileStores = fileSystem.getFileStores();
List<FileStoreModel> fileStores = osFileStores.stream().map(osFileStore -> {
String mount = osFileStore.getMount(); // 盘符
String type = osFileStore.getType(); // 盘符类型
String name = osFileStore.getName(); // 文件类型
long totalSpace = osFileStore.getTotalSpace(); // 磁盘总大小
long usableSpace = osFileStore.getUsableSpace(); // 磁盘剩余大小
return xxx;
}).collect(Collectors.toList());