Improved disk usage entry in statistics

Now will calculate usage as (total - avail).
In Linux, ext filesystems by default reserves 5% of the space to be
usable by root, making them essentially already "used" space.
Originally we didn't take that into account.

Disk usage percentage will now round down: Math.round() -> Math.floor().
The general behavior in other tools such as "df".
This commit is contained in:
Bobby Wibowo 2020-09-08 19:04:12 +07:00
parent 0cac4a947f
commit c113184385
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
2 changed files with 6 additions and 4 deletions

View File

@ -746,7 +746,7 @@ self.stats = async (req, res, next) => {
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
const proc = spawn('df', [ const proc = spawn('df', [
'--block-size=1', '--block-size=1',
'--output=used,size', '--output=size,avail',
paths.uploads paths.uploads
]) ])
@ -764,9 +764,11 @@ self.stats = async (req, res, next) => {
// Skip lines that have non-number chars // Skip lines that have non-number chars
if (columns.some(w => !/^\d+$/.test(w))) continue if (columns.some(w => !/^\d+$/.test(w))) continue
const total = parseInt(columns[0])
const avail = parseInt(columns[1])
stats.disk.drive = { stats.disk.drive = {
used: parseInt(columns[0]), total,
total: parseInt(columns[1]) used: total - avail
} }
} }
}) })

View File

@ -2860,7 +2860,7 @@ page.getStatistics = (params = {}) => {
if ((types.byte || []).includes(valKeys[j])) if ((types.byte || []).includes(valKeys[j]))
parsed = page.getPrettyBytes(value) parsed = page.getPrettyBytes(value)
if ((types.byteUsage || []).includes(valKeys[j])) if ((types.byteUsage || []).includes(valKeys[j]))
parsed = `${page.getPrettyBytes(value.used)} / ${page.getPrettyBytes(value.total)} (${Math.round(value.used / value.total * 100)}%)` parsed = `${page.getPrettyBytes(value.used)} / ${page.getPrettyBytes(value.total)} (${Math.floor(value.used / value.total * 100)}%)`
if ((types.uptime || []).includes(valKeys[j])) if ((types.uptime || []).includes(valKeys[j]))
parsed = page.getPrettyUptime(value) parsed = page.getPrettyUptime(value)