|
@@ -0,0 +1,215 @@
|
|
|
+package com.gyee.host.service;
|
|
|
+
|
|
|
+import cn.hutool.core.lang.Console;
|
|
|
+import cn.hutool.system.OsInfo;
|
|
|
+import cn.hutool.system.SystemUtil;
|
|
|
+import com.gyee.host.mode.CpuInfo;
|
|
|
+import com.gyee.host.mode.DiskInfo;
|
|
|
+import com.gyee.host.mode.GpuInfo;
|
|
|
+import com.gyee.host.mode.Memory;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import oshi.SystemInfo;
|
|
|
+import oshi.hardware.*;
|
|
|
+import oshi.software.os.OperatingSystem;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class HostparamService {
|
|
|
+
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(HostparamService.class);
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ShellService shellService;
|
|
|
+
|
|
|
+ public Map getHostParam(){
|
|
|
+
|
|
|
+ OsInfo osInfo = SystemUtil.getOsInfo();
|
|
|
+ Console.log("操作系统:{}", osInfo.getName());
|
|
|
+ Console.log("系统版本:{}", osInfo.getVersion());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Map map =new HashMap();
|
|
|
+ SystemInfo systemInfo = new SystemInfo();
|
|
|
+ HardwareAbstractionLayer hardware = systemInfo.getHardware();
|
|
|
+ OperatingSystem operatingSystem = systemInfo.getOperatingSystem();
|
|
|
+
|
|
|
+ Console.log("======= CPU信息 ======");
|
|
|
+ CentralProcessor cpu = hardware.getProcessor();
|
|
|
+ CentralProcessor.ProcessorIdentifier cpuInfo = cpu.getProcessorIdentifier();
|
|
|
+ CpuInfo info = new CpuInfo();
|
|
|
+
|
|
|
+ info.setCpuNum(cpu.getPhysicalPackageCount());
|
|
|
+
|
|
|
+ info.setCpuCoreNum(cpu.getPhysicalProcessorCount());
|
|
|
+
|
|
|
+ info.setCpuhreads(cpu.getLogicalProcessorCount());
|
|
|
+
|
|
|
+
|
|
|
+ info.setCpuName(cpuInfo.getName());
|
|
|
+
|
|
|
+ map.put("cpu",info);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Console.log("======= 内存信息 ======");
|
|
|
+ Memory m = new Memory();
|
|
|
+ GlobalMemory memory = hardware.getMemory();
|
|
|
+
|
|
|
+
|
|
|
+ m.setTotalMemory(format(memory.getTotal()));
|
|
|
+ m.setUseableMemory(format(memory.getAvailable()));
|
|
|
+ map.put("memory",m);
|
|
|
+ Console.log("==========");
|
|
|
+ List<PhysicalMemory> memoryList = memory.getPhysicalMemory();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Console.log("======= 物理磁盘信息 ======");
|
|
|
+ List<HWDiskStore> diskList = hardware.getDiskStores();
|
|
|
+
|
|
|
+ List<DiskInfo> diskInfos = new ArrayList<>();
|
|
|
+ diskList.forEach((disk) -> {
|
|
|
+ DiskInfo diskInfo = new DiskInfo();
|
|
|
+
|
|
|
+ diskInfo.setDiskName(disk.getName());
|
|
|
+
|
|
|
+ diskInfo.setDiskMode(disk.getModel());
|
|
|
+
|
|
|
+ diskInfo.setDiskId(disk.getSerial());
|
|
|
+
|
|
|
+ diskInfo.setDiskSize(format(disk.getSize()));
|
|
|
+
|
|
|
+ diskInfos.add(diskInfo);
|
|
|
+ });
|
|
|
+
|
|
|
+ map.put("disk",diskInfos);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static String format(long size) {
|
|
|
+ if (size < 1024) {
|
|
|
+ return size + "B";
|
|
|
+ } else {
|
|
|
+ size = size / 1024;
|
|
|
+ }
|
|
|
+ if (size < 1024) {
|
|
|
+ return size + "KB";
|
|
|
+ } else {
|
|
|
+ size = size / 1024;
|
|
|
+ }
|
|
|
+ if (size < 1024) {
|
|
|
+ size = size * 100;
|
|
|
+ return size / 100 + "." + size % 100 + "MB";
|
|
|
+ } else {
|
|
|
+ size = size * 100 / 1024;
|
|
|
+ return size / 100 + "." + size % 100 + "GB";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public List<GpuInfo> getGpuInfos() throws IOException {
|
|
|
+ String gpus = null;
|
|
|
+
|
|
|
+ gpus = shellService.getGPU();
|
|
|
+
|
|
|
+
|
|
|
+ "+-----------------------------------------------------------------------------+\n" +
|
|
|
+ "| NVIDIA-SMI 418.87.01 Driver Version: 418.87.01 CUDA Version: 10.1 |\n" +
|
|
|
+ "|-------------------------------+----------------------+----------------------+\n" +
|
|
|
+ "| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |\n" +
|
|
|
+ "| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |\n" +
|
|
|
+ "|===============================+======================+======================|\n" +
|
|
|
+ "| 0 TITAN V Off | 00000000:2D:00.0 On | N/A |\n" +
|
|
|
+ "| 29% 43C P8 27W / 250W | 1123MiB / 12035MiB | 0% Default |\n" +
|
|
|
+ "+-------------------------------+----------------------+----------------------+\n" +
|
|
|
+ "| 1 GeForce RTX 208... Off | 00000000:99:00.0 Off | N/A |\n" +
|
|
|
+ "| 0% 29C P8 20W / 260W | 11MiB / 10989MiB | 0% Default |\n" +
|
|
|
+ "+-------------------------------+----------------------+----------------------+\n" +
|
|
|
+ " \n" +
|
|
|
+ "+-----------------------------------------------------------------------------+\n" +
|
|
|
+ "| Processes: GPU Memory |\n" +
|
|
|
+ "| GPU PID Type Process name Usage |\n" +
|
|
|
+ "|=============================================================================|\n" +
|
|
|
+ "| 0 16841 C inference_worker 1077MiB |\n" +
|
|
|
+ "| 0 19996 G /usr/lib/xorg/Xorg 33MiB |\n" +
|
|
|
+ "+-----------------------------------------------------------------------------+\n";*/
|
|
|
+
|
|
|
+
|
|
|
+ String[] split = gpus.split("\\|===============================\\+======================\\+======================\\|");
|
|
|
+ String[] gpusInfo = split[1].split(" ");
|
|
|
+
|
|
|
+ String[] gpuInfo = gpusInfo[0].split("\\+-------------------------------\\+----------------------\\+----------------------\\+");
|
|
|
+
|
|
|
+ List<GpuInfo> gpuInfoList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < gpuInfo.length - 1; i++) {
|
|
|
+ GpuInfo gpuInfo1 = new GpuInfo();
|
|
|
+ String[] nameAndInfo = gpuInfo[i].split("\n");
|
|
|
+
|
|
|
+
|
|
|
+ *TITAN
|
|
|
+ *V
|
|
|
+ *Off
|
|
|
+ * */
|
|
|
+ String[] split1 = nameAndInfo[1].split("\\|")[1]
|
|
|
+ .split("\\s+");
|
|
|
+
|
|
|
+ gpuInfo1.setNumber(Integer.parseInt(split1[1]));
|
|
|
+ StringBuffer name = new StringBuffer();
|
|
|
+ for (int j = 0; j < split1.length - 1; j++) {
|
|
|
+ if (j > 1 && j != split1.length) {
|
|
|
+ name.append(split1[j] + " ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ gpuInfo1.setName(name.toString());
|
|
|
+
|
|
|
+ String[] info = nameAndInfo[2].split("\\|")[2].split("\\s+");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ gpuInfoList.add(gpuInfo1);
|
|
|
+
|
|
|
+ }
|
|
|
+ return gpuInfoList;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|