compute docker df only once

This commit is contained in:
Girish Ramakrishnan
2024-11-30 12:01:25 +01:00
parent 40febc8ef2
commit 320ddfda2e

View File

@@ -91,14 +91,14 @@ async function getSwaps() {
// this gets information based on mounted filesystems
async function getFilesystems() {
const FS_TYPES = [ 'ext4', 'xfs', 'cifs', 'nfs', 'fuse.sshfs' ]; // we don't show size of contents in untracked disk types
const [dfError, dfEntries] = await safe(df.filesystems());
if (dfError) throw new BoxError(BoxError.FS_ERROR, `Error running df: ${dfError.message}`);
const filesystems = {}; // by file system
let rootDisk;
const FS_TYPES = [ 'ext4', 'xfs', 'cifs', 'nfs', 'fuse.sshfs' ]; // we don't show size of contents in untracked disk types
for (const dfEntry of dfEntries) {
if (!FS_TYPES.includes(dfEntry.type)) continue;
if (dfEntry.mountpoint === '/') rootDisk = dfEntry;
@@ -233,25 +233,25 @@ async function updateDiskUsage(progressCallback) {
let percent = 1;
const dockerDf = await docker.df();
const fsCount = Object.keys(filesystems).length;
for (const fsPath in filesystems) {
const filesystem = filesystems[fsPath];
if (filesystem.type === 'ext4' || filesystem.type === 'xfs') {
const [speedError, speed] = await safe(hdparm(filesystem));
if (filesystem.type === 'ext4' || filesystem.type === 'xfs') { // hdparm only works with block devices
const [speedError, speed] = await safe(hdparm(fsPath));
if (speedError) progressCallback({ message: `hdparm error: ${speedError.message}`});
filesystem.speed = speedError ? -1 : speed;
} else {
filesystem.speed = -1;
}
percent += (100/filesystems.length);
progressCallback({ percent, message: `Checking contents of ${filesystem}`});
const dockerDf = await docker.df();
percent += (100/fsCount);
progressCallback({ percent, message: `Checking contents of ${fsPath}`});
for (const content of filesystem.contents) {
progressCallback({ message: `Checking du of ${JSON.stringify(content)}`});
progressCallback({ message: `Checking du of ${content.id} ${content.path}`});
if (content.id === 'docker') {
content.usage = dockerDf.LayersSize;
} else if (content.id === 'docker-volumes') {