statistics.js
* Inter-cluster Communication Statistics
* @module greppy/app/cluster/master/ipc/statistics
* @author Hermann Mayer <hermann.mayer92@gmail.com>
var Statistics = function(options)
* Notification of an worker metric change.
* @param {Object} msg - IPC message object
* @param {Mixed} options - Options/arguments passed to the IPC request
Statistics.prototype.notifyMetric = function(msg, options)
var value = this.master.stats.metrics[options];
this.master.stats.metrics[options] = ++value;
* Notification of an worker metric change.
* @param {Object} msg - IPC message object
* @param {Mixed} options - Options/arguments passed to the IPC request
* @param {Function} callback - Method for responses
Statistics.prototype.getMetric = function(msg, options, callback)
var value = this.master.stats.metrics[options];
callback && callback('No metric information found for "' + options + '"');
callback && callback(null, value);
* Get all statistics in as object.
* @param {Object} msg - IPC message object
* @param {Mixed} options - Options/arguments passed to the IPC request
* @param {Function} callback - Method for responses
Statistics.prototype.get = function(msg, options, callback)
name : this.master.cliArgs.options.context,
metrics : this.master.stats.metics,
crashProtocol : this.master.stats.crashs,
deployment : this.getModuleDeployment()
var l = fs.readFileSync('/proc/loadavg', 'ascii').split(' ');
memory : this.getMemoryUsage(),
* Get deployment information from projects
* package.json and the greppy version file.
Statistics.prototype.getModuleDeployment = function()
var package = require(process.cwd() + '/package.json');
var deployment = require(process.cwd() + '/var/cache/version');
deployment.version = package.version;
* Get total cluster memory usage.
Statistics.prototype.getMemoryUsage = function()
var cluster = this.master.getCluster();
var l = fs.readFileSync('/proc/meminfo', 'ascii').split("\n");
var getValue = function(str) {
return str.replace(/ +(?= )/g,'').split(' ')[1] * 1024;
rss : process.memoryUsage().rss
for (var procId in cluster.workers) {
var proc = cluster.workers[procId];
var status = fs.readFileSync('/proc/' + proc.process.pid + '/status', 'ascii');
var rss = (new RegExp('^VmRSS:(.+)', 'mgi')).exec(status)[1]