diff --git a/lib/God.js b/lib/God.js index c01afe4a..1e9a89ba 100644 --- a/lib/God.js +++ b/lib/God.js @@ -11,6 +11,7 @@ var util = require('util'); var log = require('debug')('pm2:god'); var fs = require('fs'); var Common = require('./Common'); +var os = require('os'); var EventEmitter2 = require('eventemitter2').EventEmitter2; @@ -303,9 +304,9 @@ God.prepare = function(env, cb) { }; /** - * Allows an app to be prepared using the same json format as the CLI, instead + * Allows an app to be prepared using the same json format as the CLI, instead * of the internal PM2 format. - * An array of applications is not currently supported. Call this method + * An array of applications is not currently supported. Call this method * multiple times with individual app objects if you have several to start. * @param app {Object} * @param [cwd] {string} Optional string to specify the cwd for the script. @@ -317,11 +318,11 @@ God.prepareJson = function (app, cwd, cb) { cb = cwd; cwd = undefined; } - + app = Common.resolveAppPaths(app, cwd); if (app instanceof Error) return cb(app); - + return God.prepare(app, cb); }; @@ -400,6 +401,24 @@ God.getMonitorData = function(env, cb) { ex(processes.length - 1); }; +God.getSystemData = function(env, cb) { + God.getMonitorData(env, function(err, processes) { + cb(err, { + system: { + hostname: os.hostname(), + uptime: os.uptime(), + cpus: os.cpus(), + load: os.loadavg(), + memory: { + free: os.freemem(), + total: os.totalmem() + } + }, + processes: processes + }); + }); +}; + God.getFormatedProcesses = function() { var db = God.clusters_db; var arr = []; diff --git a/lib/Satan.js b/lib/Satan.js index c8729b9f..87a40c9b 100644 --- a/lib/Satan.js +++ b/lib/Satan.js @@ -109,6 +109,7 @@ Satan.remoteWrapper = function() { prepare : God.prepare, prepareJson : God.prepareJson, getMonitorData : God.getMonitorData, + getSystemData : God.getSystemData, startProcessId : God.startProcessId, stopProcessId : God.stopProcessId, stopProcessName : God.stopProcessName, diff --git a/test/god.mocha.js b/test/god.mocha.js index 88a713d3..a370074e 100644 --- a/test/god.mocha.js +++ b/test/god.mocha.js @@ -21,6 +21,7 @@ describe('God', function() { God.should.have.property('prepare'); God.should.have.property('getProcesses'); God.should.have.property('getMonitorData'); + God.should.have.property('getSystemData'); God.should.have.property('getFormatedProcesses'); God.should.have.property('checkProcess'); God.should.have.property('stopAll'); diff --git a/test/satan.mocha.js b/test/satan.mocha.js index e2c77685..33d5758a 100644 --- a/test/satan.mocha.js +++ b/test/satan.mocha.js @@ -52,6 +52,7 @@ describe('Satan', function() { assert(err == null); methods.should.have.property('prepare'); methods.should.have.property('getMonitorData'); + methods.should.have.property('getSystemData'); methods.should.have.property('stopProcessId'); methods.should.have.property('stopAll'); methods.should.have.property('stopProcessName'); @@ -67,6 +68,13 @@ describe('Satan', function() { }); }); + it('should get an empty process list from system data', function(done) { + Satan.executeRemote('getSystemData', {}, function(err, res) { + assert(res.processes.length === 0); + done(); + }); + }); + it('should launch a process', function(done) { Satan.executeRemote('prepare', { pm_exec_path : path.resolve(process.cwd(), 'test/fixtures/echo.js'), @@ -87,5 +95,12 @@ describe('Satan', function() { done(); }); }); + + it('should list 4 processes via system data', function(done) { + Satan.executeRemote('getSystemData', {}, function(err, res) { + assert(res.processes.length === 4); + done(); + }); + }); }); });