Skip to content

Instantly share code, notes, and snippets.

@jonmaim
Last active June 6, 2022 19:03
Show Gist options
  • Save jonmaim/eff4f6308c55c48ed97c83e390504625 to your computer and use it in GitHub Desktop.
Save jonmaim/eff4f6308c55c48ed97c83e390504625 to your computer and use it in GitHub Desktop.
NodeJS: check disk usage and output remaining space if under 10%
var disk = require('diskusage');
disk.check('/', function(err, info) {
function toGB(x) { return (x / (1024 * 1024 * 1024)).toFixed(1); }
var percentAvailable = ((info.available / info.total) * 100);
if (percentAvailable < 10) { console.log('Warning only ' + toGB(info.available) + 'GB (' + percentAvailable.toFixed(1) + '%) space available!'); }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment