From 2ed111fa5e6264bf8de58a0ee1c299a1e5f70b93 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 20 Nov 2013 16:06:07 +0000 Subject: [PATCH] adds system data call to return load, cpus, etc along with process information --- lib/God.js | 19 +++++++++++++++++++ lib/Satan.js | 1 + test/god.mocha.js | 1 + test/satan.mocha.js | 15 +++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/lib/God.js b/lib/God.js index 386c3714..e9488a40 100644 --- a/lib/God.js +++ b/lib/God.js @@ -10,6 +10,7 @@ var cst = require('../constants.js'); var util = require('util'); var log = require('debug')('pm2:god'); var fs = require('fs'); +var os = require('os'); var EventEmitter2 = require('eventemitter2').EventEmitter2; @@ -376,6 +377,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 0aa5bb7a..a08088d0 100644 --- a/lib/Satan.js +++ b/lib/Satan.js @@ -108,6 +108,7 @@ Satan.remoteWrapper = function() { server.expose({ prepare : God.prepare, 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(); + }); + }); }); });