Add disk speeds to disk usage data
This commit is contained in:
@@ -26,6 +26,7 @@ const apps = require('./apps.js'),
|
||||
volumes = require('./volumes.js');
|
||||
|
||||
const DU_CMD = path.join(__dirname, 'scripts/du.sh');
|
||||
const HDPARM_CMD = path.join(__dirname, 'scripts/hdparm.sh');
|
||||
|
||||
async function du(file) {
|
||||
assert.strictEqual(typeof file, 'string');
|
||||
@@ -36,6 +37,22 @@ async function du(file) {
|
||||
return parseInt(stdoutResult.trim(), 10);
|
||||
}
|
||||
|
||||
async function hdparm(file) {
|
||||
assert.strictEqual(typeof file, 'string');
|
||||
|
||||
const [error, stdoutResult] = await safe(shell.promises.sudo('system', [ HDPARM_CMD, file ], {}));
|
||||
if (error) throw new BoxError(BoxError.FS_ERROR, error);
|
||||
|
||||
const lines = stdoutResult.split('\n');
|
||||
|
||||
if (lines.length != 4) return -1;
|
||||
if (lines[2].split('=').length !== 2) return -1;
|
||||
|
||||
const speed = lines[2].split('=')[1].slice(0, 'MB/sec'.length).trim();
|
||||
|
||||
return Number(speed);
|
||||
}
|
||||
|
||||
async function getSwaps() {
|
||||
const stdout = safe.child_process.execSync('swapon --noheadings --raw --bytes --show=type,size,used,name', { encoding: 'utf8' });
|
||||
if (!stdout) return {};
|
||||
@@ -194,6 +211,11 @@ async function updateDiskUsage(progressCallback) {
|
||||
for (const filesystem of filesystems) {
|
||||
const disk = disks[filesystem];
|
||||
|
||||
const [speedError, speed] = await safe(hdparm(filesystem));
|
||||
if (speedError) progressCallback({ message: `hdparm error: ${speedError.message}`});
|
||||
|
||||
disk.speed = speed;
|
||||
|
||||
percent += (100/filesystems.length);
|
||||
progressCallback({ percent, message: `Checking contents of ${filesystem}`});
|
||||
|
||||
@@ -205,6 +227,7 @@ async function updateDiskUsage(progressCallback) {
|
||||
const [error, usage] = await safe(du(content.path));
|
||||
if (error) progressCallback({ message: `du error: ${error.message}`}); // can happen if app is installing etc
|
||||
content.usage = usage || 0;
|
||||
|
||||
}
|
||||
progressCallback({ message: `du of ${JSON.stringify(content)}: ${content.usage}`});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user