|
@@ -132,6 +132,36 @@ public class SshUtil {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取 cpu 总量
|
|
|
+ */
|
|
|
+ public static long cpuTotal(ClientSession session) throws IOException, InterruptedException {
|
|
|
+
|
|
|
+ Map<?, ?> map1 = cpuInfo(session);
|
|
|
+ Thread.sleep(5 * 1000);
|
|
|
+ Map<?, ?> map2 = cpuInfo(session);
|
|
|
+
|
|
|
+ long user1 = Long.parseLong(map1.get("user").toString());
|
|
|
+ long nice1 = Long.parseLong(map1.get("nice").toString());
|
|
|
+ long system1 = Long.parseLong(map1.get("system").toString());
|
|
|
+ long idle1 = Long.parseLong(map1.get("idle").toString());
|
|
|
+
|
|
|
+ long user2 = Long.parseLong(map2.get("user").toString());
|
|
|
+ long nice2 = Long.parseLong(map2.get("nice").toString());
|
|
|
+ long system2 = Long.parseLong(map2.get("system").toString());
|
|
|
+ long idle2 = Long.parseLong(map2.get("idle").toString());
|
|
|
+
|
|
|
+ long total1 = user1 + system1 + nice1;
|
|
|
+ long total2 = user2 + system2 + nice2;
|
|
|
+ double total = total2 - total1;
|
|
|
+
|
|
|
+ long totalIdle1 = user1 + nice1 + system1 + idle1;
|
|
|
+ long totalIdle2 = user2 + nice2 + system2 + idle2;
|
|
|
+
|
|
|
+ return totalIdle2 - totalIdle1;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 功能:CPU使用信息
|
|
@@ -164,6 +194,20 @@ public class SshUtil {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 显存使用率
|
|
|
+ *
|
|
|
+ * @param session 会话
|
|
|
+ * @return 显存总量,单位 MB
|
|
|
+ */
|
|
|
+ public static double gpuUsage(ClientSession session) throws DocumentException, IOException {
|
|
|
+ List<GpuDTO> gpuDTOList = SshUtil.gpuInfo(session);
|
|
|
+ int used = gpuDTOList.stream().mapToInt(gpu -> Integer.parseInt(gpu.getUsedMemory().split(" ")[0])).sum();
|
|
|
+ int total = gpuDTOList.stream().mapToInt(gpu -> Integer.parseInt(gpu.getTotalMemory().split(" ")[0])).sum();
|
|
|
+ return used * 1.0 / total;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 显存总量
|
|
|
*
|
|
@@ -347,7 +391,7 @@ public class SshUtil {
|
|
|
* @param session 会话
|
|
|
* @return 剩余可用磁盘(kb)
|
|
|
*/
|
|
|
- public static double diskAvailable(ClientSession session) throws IOException {
|
|
|
+ public static long diskAvailable(ClientSession session) throws IOException {
|
|
|
String execute = execute(session, "df --total");
|
|
|
String[] split = execute.split("\n");
|
|
|
String[] split1 = split[split.length - 1].split("\\s+");
|
|
@@ -364,7 +408,7 @@ public class SshUtil {
|
|
|
* @param session 会话
|
|
|
* @return 总磁盘(kb)
|
|
|
*/
|
|
|
- public static double diskTotal(ClientSession session) throws IOException {
|
|
|
+ public static long diskTotal(ClientSession session) throws IOException {
|
|
|
String execute = execute(session, "df --total");
|
|
|
String[] split = execute.split("\n");
|
|
|
String[] split1 = split[split.length - 1].split("\\s+");
|