mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 02:12:58 +08:00
fix: memory parsing error (#284)
This commit is contained in:
@@ -142,6 +142,7 @@ class SystemInformationVisualWindow(tab: SSHTerminalTab, visualWindowManager: Vi
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val regex = """\d+\.?\d*""".toRegex()
|
||||||
val lines = pair.second.split(StringUtils.LF)
|
val lines = pair.second.split(StringUtils.LF)
|
||||||
for (line in lines) {
|
for (line in lines) {
|
||||||
val isCPU = line.startsWith("%Cpu(s):", true)
|
val isCPU = line.startsWith("%Cpu(s):", true)
|
||||||
@@ -154,22 +155,23 @@ class SystemInformationVisualWindow(tab: SSHTerminalTab, visualWindowManager: Vi
|
|||||||
if (isCPU) {
|
if (isCPU) {
|
||||||
val parts = StringUtils.removeStartIgnoreCase(line, "%Cpu(s):").split(",").map { it.trim() }
|
val parts = StringUtils.removeStartIgnoreCase(line, "%Cpu(s):").split(",").map { it.trim() }
|
||||||
for (part in parts) {
|
for (part in parts) {
|
||||||
if (part.endsWith("us")) {
|
val value = regex.find(part)?.value?.toDoubleOrNull() ?: 0.0
|
||||||
cpu.us = StringUtils.removeEnd(part, "us").trim().toDoubleOrNull() ?: 0.0
|
if (part.contains("us")) {
|
||||||
} else if (part.endsWith("sy")) {
|
cpu.us = value
|
||||||
cpu.sy = StringUtils.removeEnd(part, "sy").trim().toDoubleOrNull() ?: 0.0
|
} else if (part.contains("sy")) {
|
||||||
} else if (part.endsWith("ni")) {
|
cpu.sy = value
|
||||||
cpu.ni = StringUtils.removeEnd(part, "ni").trim().toDoubleOrNull() ?: 0.0
|
} else if (part.contains("ni")) {
|
||||||
} else if (part.endsWith("id")) {
|
cpu.ni = value
|
||||||
cpu.id = StringUtils.removeEnd(part, "id").trim().toDoubleOrNull() ?: 0.0
|
} else if (part.contains("id")) {
|
||||||
} else if (part.endsWith("wa")) {
|
cpu.id = value
|
||||||
cpu.wa = StringUtils.removeEnd(part, "wa").trim().toDoubleOrNull() ?: 0.0
|
} else if (part.contains("wa")) {
|
||||||
} else if (part.endsWith("hi")) {
|
cpu.wa = value
|
||||||
cpu.hi = StringUtils.removeEnd(part, "hi").trim().toDoubleOrNull() ?: 0.0
|
} else if (part.contains("hi")) {
|
||||||
} else if (part.endsWith("si")) {
|
cpu.hi = value
|
||||||
cpu.si = StringUtils.removeEnd(part, "si").trim().toDoubleOrNull() ?: 0.0
|
} else if (part.contains("si")) {
|
||||||
} else if (part.endsWith("st")) {
|
cpu.si = value
|
||||||
cpu.st = StringUtils.removeEnd(part, "st").trim().toDoubleOrNull() ?: 0.0
|
} else if (part.contains("st")) {
|
||||||
|
cpu.st = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (isMibMem || isKibMem) {
|
} else if (isMibMem || isKibMem) {
|
||||||
@@ -177,14 +179,15 @@ class SystemInformationVisualWindow(tab: SSHTerminalTab, visualWindowManager: Vi
|
|||||||
.split(",")
|
.split(",")
|
||||||
.map { it.trim() }
|
.map { it.trim() }
|
||||||
for (part in parts) {
|
for (part in parts) {
|
||||||
if (part.endsWith("total")) {
|
val value = regex.find(part)?.value?.toDoubleOrNull() ?: 0.0
|
||||||
mem.total = StringUtils.removeEnd(part, "total").trim().toDoubleOrNull() ?: 0.0
|
if (part.contains("total")) {
|
||||||
} else if (part.endsWith("free")) {
|
mem.total = value
|
||||||
mem.free = StringUtils.removeEnd(part, "free").trim().toDoubleOrNull() ?: 0.0
|
} else if (part.contains("free")) {
|
||||||
} else if (part.endsWith("used")) {
|
mem.free = value
|
||||||
mem.used = StringUtils.removeEnd(part, "used").trim().toDoubleOrNull() ?: 0.0
|
} else if (part.contains("used")) {
|
||||||
} else if (part.endsWith("buff/cache")) {
|
mem.used = value
|
||||||
mem.buffCache = StringUtils.removeEnd(part, "buff/cache").trim().toDoubleOrNull() ?: 0.0
|
} else if (part.contains("buff/cache")) {
|
||||||
|
mem.buffCache = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,12 +203,13 @@ class SystemInformationVisualWindow(tab: SSHTerminalTab, visualWindowManager: Vi
|
|||||||
.map { it.trim() }
|
.map { it.trim() }
|
||||||
|
|
||||||
for (part in parts) {
|
for (part in parts) {
|
||||||
|
val value = regex.find(part)?.value?.toDoubleOrNull() ?: 0.0
|
||||||
if (part.contains("total")) {
|
if (part.contains("total")) {
|
||||||
swap.total = StringUtils.removeEnd(part, "total").trim().toDoubleOrNull() ?: 0.0
|
swap.total = value
|
||||||
} else if (part.contains("free")) {
|
} else if (part.contains("free")) {
|
||||||
swap.free = StringUtils.removeEnd(part, "free").trim().toDoubleOrNull() ?: 0.0
|
swap.free = value
|
||||||
} else if (part.contains("used.")) {
|
} else if (part.contains("used.")) {
|
||||||
swap.used = part.substringBefore("used.").trim().toDoubleOrNull() ?: 0.0
|
swap.used = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user