notifications: do not jump json blob for out of disk space

This commit is contained in:
Girish Ramakrishnan
2021-06-23 23:38:39 -07:00
parent 54dec7ae08
commit 7d3270e51a

View File

@@ -121,7 +121,7 @@ function getDisks(callback) {
function checkDiskSpace(callback) {
assert.strictEqual(typeof callback, 'function');
debug('Checking disk space');
debug('checkDiskSpace: checking disk space');
getDisks(async function (error, disks) {
if (error) {
@@ -129,7 +129,9 @@ function checkDiskSpace(callback) {
return callback();
}
const oos = disks.disks.some(function (entry) {
let markdownMessage = '';
disks.disks.forEach(function (entry) {
// ignore other filesystems but where box, app and platform data is
if (entry.filesystem !== disks.boxDataDisk
&& entry.filesystem !== disks.platformDataDisk
@@ -137,12 +139,16 @@ function checkDiskSpace(callback) {
&& entry.filesystem !== disks.backupsDisk
&& entry.filesystem !== disks.dockerDataDisk) return false;
return (entry.available <= (1.25 * 1024 * 1024 * 1024)); // 1.5G
if (entry.available <= (1.25 * 1024 * 1024 * 1024)) { // 1.5G
markdownMessage += `* ${entry.filesystem} is at ${entry.capacity*100}% capacity.\n`;
}
});
debug('checkDiskSpace: disk space checked. ok: %s', !oos);
debug(`checkDiskSpace: disk space checked. out of space: ${markdownMessage || 'no'}`);
await notifications.alert(notifications.ALERT_DISK_SPACE, 'Server is running out of disk space', oos ? JSON.stringify(disks.disks, null, 4) : '');
if (markdownMessage) markdownMessage = `One or more file systems are running out of space. Please increase the disk size at the earliest.\n\n${markdownMessage}`;
await notifications.alert(notifications.ALERT_DISK_SPACE, 'Server is running out of disk space', markdownMessage);
callback();
});