-
-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
Thank you for providing such a great library.
I am reporting an issue where the result of checkDiskSpace('/') could not be retrieved properly in the following environment:
Execution Environment:
- Machine: AWS AppRunner
- Node version: Node.js 18
Cause:
When executed in virtualized environments like AWS AppRunner (or Docker-based environments), there are cases where the Filesystem field in the df output is omitted. This causes the library to fail to parse the command output properly.
Example df output:
Filesystem 1024-blocks Used Available Capacity Mounted on
3355850 34 3179368 1% /
tmpfs 65536 0 65536 0% /dev
shm 530264 0 530264 0% /dev/shm
tmpfs 530264 0 530264 0% /sys/fs/cgroup
/dev/vdd 3355850 34 3179368 1% /etc/hosts
tmpfs 530264 0 530264 0% /sys/firmware
tmpfs 530264 0 530264 0% /proc/scsi
Workaround:
To address this issue, I implemented the following workaround by avoiding reliance on the Filesystem field:
const { exec } = require('child_process');
const util = require('util');
const execPromise = util.promisify(exec);
async function checkDiskFreeSpace(path) {
const { stdout, stderr } = await execPromise(`df -Pk -- ${path}`);
if (stderr) {
throw new Error(`Unexpected result from df command: ${stderr}`);
}
// Parse the output
const parsedLines = stdout
.split('\n') // Split lines
.map(line => line.trim()) // Trim all lines
.filter(line => line.length !== 0) // Remove empty lines
.slice(1) // Remove header
.map(line => line.split(/\s+(?=[\d/])/)); // Split columns by whitespace before numbers or "/"
if (parsedLines.length === 0) {
throw new Error(`Unexpected result from df command: ${stdout}`);
}
return parseInt(parsedLines[0][parsedLines[0].length - 3], 10) * 1024; // Convert to bytes
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels