/**
 * Memory Usage sensor
 *
 * (c) 2014 James Hall
 */

var os = require('os-utils');

var plugin = {
	/**
	 * This appears in the title of the graph
	 */
	title: 'Memory Usage',
	/**
	 * The type of sensor
	 * @type {String}
	 */
	type: 'chart',
	/**
	 * The default interval time in ms that this plugin should be polled.
	 * More costly benchmarks should be polled less frequently.
	 */
	interval: 200,

	initialized: false,


	currentValue: 0,
	/**
	 * Grab the current value, from 0-100
	 */
	poll: function() {
		plugin.currentValue = (100 - Math.floor(os.freememPercentage() * 100));
		plugin.initialized = true;
	}
};

module.exports = exports = plugin;
@@ -80,16 +80,79 @@
 utils');
+%0Avar _os = require('os');%0Avar child = require('child_process');
 %0A%0Avar pl
@@ -486,17 +486,16 @@
 false,%0A%0A
-%0A
 %09current
@@ -504,16 +504,70 @@
 lue: 0,%0A
+%0A    isLinux: _os.platform().indexOf('linux') != -1,%0A%0A
 %09/**%0A%09 *
@@ -631,50 +631,560 @@
 ) %7B%0A
-%09%09plugin.currentValue = (100 - Math.floor(
+        var computeUsage = function(used, total) %7B%0A            return Math.round(100 * (used / total));%0A        %7D;%0A%0A%09%09if (plugin.isLinux) %7B%0A            child.exec('free -m', function(err, stdout, stderr) %7B%0A                var data = stdout.split('%5Cn')%5B1%5D.replace(/%5B%5Cs%5Cn%5Cr%5D+/g, ' ').split(' ');%0A                %0A                var used = parseInt(data%5B2%5D);%0A                var total = parseInt(data%5B1%5D);%0A                plugin.currentValue = computeUsage(used, total);%0A            %7D);%0A        %7D else %7B%0A            plugin.currentValue = Math.round((1 - 
 os.f
@@ -1205,18 +1205,29 @@
 ge()
+)
  * 100)
-)
 ;%0A
+        %7D%0A%0A
 %09%09pl
@@ -1257,17 +1257,16 @@
 ;%0A%09%7D%0A%7D;%0A
-%0A
 module.e
@@ -1291,8 +1291,9 @@
  plugin;
+%0A

Fix reported memory usage on Linux