notifications: add low disk space notification

This commit is contained in:
Girish Ramakrishnan
2025-05-07 13:15:08 +02:00
parent 5489237f11
commit 0cf0c7a27c
9 changed files with 73 additions and 18 deletions
+7 -4
View File
@@ -189,15 +189,18 @@ async function checkDiskSpace() {
const filesystem = filesystems[fsPath];
if (filesystem.contents.length === 0) continue; // ignore if nothing interesting here
if (filesystem.available <= (1.25 * 1024 * 1024 * 1024)) { // 1.5G
markdownMessage += `* ${filesystem.filesystem} is at ${filesystem.capacity*100}% capacity.\n`;
if (filesystem.capacity >= 0.90) { // > 90%
const prettyUsed = df.prettyBytes(filesystem.used),
prettyAvailable = df.prettyBytes(filesystem.available),
prettySize = df.prettySize(filesystem.size);
markdownMessage += `* ${filesystem.filesystem}(${filesystem.type}) is at ${filesystem.capacity*100}% capacity. Used: ${prettyUsed} Available: ${prettyAvailable} Size: ${prettySize}\n`;
}
}
debug(`checkDiskSpace: disk space checked. out of space: ${markdownMessage || 'no'}`);
debug(`checkDiskSpace: disk space checked. low disk space: ${markdownMessage || 'no'}`);
if (markdownMessage) {
const finalMessage = `One or more file systems are running out of space. Please increase the disk size at the earliest.\n\n${markdownMessage}`;
const finalMessage = `One or more file systems are running low on space. Please increase the disk size at the earliest.\n\n${markdownMessage}`;
await notifications.pin(notifications.TYPE_DISK_SPACE, 'Server is running out of disk space', finalMessage, {});
} else {
await notifications.unpin(notifications.TYPE_DISK_SPACE, {});