Fix disk usage when using lvm

This commit is contained in:
ko1N 2025-06-10 19:25:58 +02:00
parent 4d002df118
commit a2531a588f

View file

@ -97,19 +97,39 @@ Singleton {
id: storage
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 {
splitMarker: ""
onRead: data => {
let used = 0;
let avail = 0;
const deviceMap = new Map();
for (const line of data.trim().split("\n")) {
const [u, a] = line.split(" ");
used += parseInt(u, 10);
avail += parseInt(a, 10);
if (line.trim() === "") continue;
const parts = line.trim().split(/\s+/);
if (parts.length >= 3) {
const device = parts[0];
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 });
}
root.storageUsed = used;
root.storageTotal = used + 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;
}
}
}