Last active
June 6, 2022 19:03
-
-
Save jonmaim/eff4f6308c55c48ed97c83e390504625 to your computer and use it in GitHub Desktop.
NodeJS: check disk usage and output remaining space if under 10%
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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