Added config option to enable linux disk stats

The option is disabled by default.
Meaning you need to explicitly set it to true to restore
the old behavior.

The one that uses both "df" and "du" binaries.
I found them to be very slow with 100k+ uploads
on my ancient potato server.
This commit is contained in:
Bobby Wibowo 2020-04-08 07:08:18 +07:00
parent 456f63d0d8
commit 325ccfac81
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
2 changed files with 19 additions and 9 deletions

View File

@ -486,6 +486,14 @@ module.exports = {
*/
cacheControl: false,
/*
Enable Linux-only disk stats in Dashboard's Statistics.
This will use a combination of both "du" and "df" binaries.
Disabled by default as I personally found it to be very slow with +100k uploads
with my ancient potato server.
*/
linuxDiskStats: false,
/*
Folder where to store logs.
NOTE: This is currently unused.

View File

@ -40,11 +40,6 @@ const statsCache = {
generating: false,
generatedAt: 0
},
disk: {
cache: null,
generating: false,
generatedAt: 0
},
albums: {
cache: null,
generating: false,
@ -65,7 +60,15 @@ const statsCache = {
}
}
const cloudflareAuth = config.cloudflare && config.cloudflare.apiKey && config.cloudflare.email && config.cloudflare.zoneId
if (config.linuxDiskStats)
statsCache.disk = {
cache: null,
generating: false,
generatedAt: 0
}
const cloudflareAuth = config.cloudflare && config.cloudflare.apiKey &&
config.cloudflare.email && config.cloudflare.zoneId
self.mayGenerateThumb = extname => {
return (config.uploads.generateThumbs.image && self.imageExts.includes(extname)) ||
@ -624,7 +627,7 @@ self.stats = async (req, res, next) => {
}
// Disk usage, only for Linux platform
if (os.platform === 'linux')
if (config.linuxDiskStats && os.platform === 'linux')
if (!statsCache.disk.cache && statsCache.disk.generating) {
stats.disk = false
} else if (((Date.now() - statsCache.disk.generatedAt) <= 60000) || statsCache.disk.generating) {
@ -782,8 +785,7 @@ self.stats = async (req, res, next) => {
others: 0
}
if (os.platform !== 'linux') {
// If not Linux platform, rely on DB for total size
if (!config.linuxDiskStats || os.platform !== 'linux') {
const uploads = await db.table('files')
.select('size')
stats.uploads.total = uploads.length