fix: use POSIX df for Alpine compatibility

Alpine's df doesn't support --output flag, use df -k instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
le king fu 2026-02-26 21:52:51 -05:00
parent d6eb06302c
commit 0e168d5323

View file

@ -35,13 +35,13 @@ function getCpuPercent() {
function getDisk() {
try {
const out = execSync("df / --output=size,used,avail -B1", {
encoding: "utf-8",
});
const parts = out.trim().split("\n")[1].trim().split(/\s+/).map(Number);
const totalGB = +(parts[0] / 1e9).toFixed(1);
const usedGB = +(parts[1] / 1e9).toFixed(1);
const freeGB = +(parts[2] / 1e9).toFixed(1);
// Alpine df doesn't support --output, use standard POSIX format
const out = execSync("df -k /", { encoding: "utf-8" });
const parts = out.trim().split("\n")[1].trim().split(/\s+/);
// df -k columns: Filesystem, 1K-blocks, Used, Available, Use%, Mounted
const totalGB = +(parseInt(parts[1], 10) / 1e6).toFixed(1);
const usedGB = +(parseInt(parts[2], 10) / 1e6).toFixed(1);
const freeGB = +(parseInt(parts[3], 10) / 1e6).toFixed(1);
const usagePercent = totalGB > 0 ? Math.round((usedGB / totalGB) * 100) : 0;
return { totalGB, usedGB, freeGB, usagePercent };
} catch {