From 3e3033c29e6962ec2c41716c48d75e8ba52e97fc Mon Sep 17 00:00:00 2001 From: Van Nguyen Date: Wed, 1 Aug 2012 15:16:28 -0700 Subject: [PATCH] fix hd used/total bug discovered by ben n --- lib/monitor/os.js | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/monitor/os.js b/lib/monitor/os.js index 812ef16ad..499822af6 100755 --- a/lib/monitor/os.js +++ b/lib/monitor/os.js @@ -166,23 +166,34 @@ OSMonitor.prototype.disk = function (filesystem, callback) { filesystem = filesystem || '/'; - ChildProcess.exec('df -m ' + filesystem + ' | tail -1 | awk \'{print $2 \",\" $3}\'', function (err, stdout, stderr) { - + ChildProcess.exec('df -m ' + filesystem + ' | tail -1 | tr -s " "', function (err, stdout, stderr) { + if (err || stderr !== '') { - + return callback(err || stderr); } - - // require('util').debug(stdout); - var values = stdout.replace(/\s/g, '').split(',') + + var values = stdout.replace(/^\s+/g, '').split(' ') + + if (isNaN(parseInt(values[0]))) { + + var total = values[1]; + var used = values[2]; + } else { + + var total = values[0]; + var used = values[1] + } + + var output = { - - total: parseInt(values[0]), - used: parseInt(values[1]) + + total: parseInt(total), + used: parseInt(used) }; - + return callback(null, output); - + // return callback(null, stdout.replace(/\s/g, '').replace('%', '')); }); };