Fix disk usage when using lvm
This commit is contained in:
parent
4d002df118
commit
a2531a588f
1 changed files with 30 additions and 10 deletions
|
|
@ -97,19 +97,39 @@ Singleton {
|
||||||
id: storage
|
id: storage
|
||||||
|
|
||||||
running: true
|
running: true
|
||||||
command: ["sh", "-c", "df | grep '^/dev/' | awk '{print $3, $4}'"]
|
command: ["sh", "-c", "df | grep '^/dev/' | awk '{print $1, $3, $4}'"]
|
||||||
stdout: SplitParser {
|
stdout: SplitParser {
|
||||||
splitMarker: ""
|
splitMarker: ""
|
||||||
onRead: data => {
|
onRead: data => {
|
||||||
let used = 0;
|
const deviceMap = new Map();
|
||||||
let avail = 0;
|
|
||||||
for (const line of data.trim().split("\n")) {
|
for (const line of data.trim().split("\n")) {
|
||||||
const [u, a] = line.split(" ");
|
if (line.trim() === "") continue;
|
||||||
used += parseInt(u, 10);
|
|
||||||
avail += parseInt(a, 10);
|
const parts = line.trim().split(/\s+/);
|
||||||
}
|
if (parts.length >= 3) {
|
||||||
root.storageUsed = used;
|
const device = parts[0];
|
||||||
root.storageTotal = used + avail;
|
const used = parseInt(parts[1], 10) || 0;
|
||||||
|
const avail = parseInt(parts[2], 10) || 0;
|
||||||
|
|
||||||
|
// only keep the entry with the largest total space for each device
|
||||||
|
if (!deviceMap.has(device) ||
|
||||||
|
(used + avail) > (deviceMap.get(device).used + deviceMap.get(device).avail)) {
|
||||||
|
deviceMap.set(device, { used: used, avail: avail });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let totalUsed = 0;
|
||||||
|
let totalAvail = 0;
|
||||||
|
|
||||||
|
for (const [device, stats] of deviceMap) {
|
||||||
|
totalUsed += stats.used;
|
||||||
|
totalAvail += stats.avail;
|
||||||
|
}
|
||||||
|
|
||||||
|
root.storageUsed = totalUsed;
|
||||||
|
root.storageTotal = totalUsed + totalAvail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue