Skip to content

Commit

Permalink
Merge pull request MrRio#56 from geomaster/master
Browse files Browse the repository at this point in the history
Fix reported memory usage on Linux
  • Loading branch information
MrRio committed Jan 4, 2016
2 parents f990f2c + aa6a325 commit 55dd839
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions sensors/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/

var os = require('os-utils');
var _os = require('os');
var child = require('child_process');

var plugin = {
/**
Expand All @@ -24,15 +26,33 @@ var plugin = {

initialized: false,


currentValue: 0,

isLinux: _os.platform().indexOf('linux') != -1,

/**
* Grab the current value, from 0-100
*/
poll: function() {
plugin.currentValue = (100 - Math.floor(os.freememPercentage() * 100));
var computeUsage = function(used, total) {
return Math.round(100 * (used / total));
};

if (plugin.isLinux) {
child.exec('free -m', function(err, stdout, stderr) {
var data = stdout.split('\n')[1].replace(/[\s\n\r]+/g, ' ').split(' ');

var used = parseInt(data[2]);
var total = parseInt(data[1]);
plugin.currentValue = computeUsage(used, total);
});
} else {
plugin.currentValue = Math.round((1 - os.freememPercentage()) * 100);
}

plugin.initialized = true;
}
};

module.exports = exports = plugin;
module.exports = exports = plugin;

0 comments on commit 55dd839

Please sign in to comment.