Skip to content

Commit

Permalink
feat: allow pm2 to install and enable event-loop-inspector data colle…
Browse files Browse the repository at this point in the history
…cting
  • Loading branch information
wallet77 committed Feb 2, 2018
1 parent 4660690 commit e6b0c47
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions bin/pm2
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ commander.version(pkg.version)
.option('--attach', 'attach logging after your start/restart/stop/reload')
.option('--sort <field_name:sort>', 'sort process according to field\'s name')
.option('--v8', 'enable v8 data collecting')
.option('--event-loop-inspector', 'enable event-loop-inspector dump in pmx')
.usage('[cmd] app');

commander.on('--help', function() {
Expand Down
13 changes: 13 additions & 0 deletions lib/API/Modules/Modularizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ Modularizer.install = function(CLI, module_name, opts, cb) {
return false;
}

if (module_name === 'event-loop-inspector') {
installLangModule('event-loop-inspector', function(err) {
if (err) {
Common.printError(cst.PREFIX_MSG_MOD_ERR + chalk.bold.green('event-loop-inspector installation has FAILED (checkout previous logs)'));
return cb(err);
}

Common.printOut(cst.PREFIX_MSG + chalk.bold.green('event-loop-inspector ENABLED'));
return cb();
});
return false;
}

if (module_name.indexOf('typescript') > -1) {
// Special dependency install
return installLangModule(module_name, function(e) {
Expand Down
5 changes: 5 additions & 0 deletions lib/API/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@
"boolean"
]
},
"event-loop-inspector": {
"type": [
"boolean"
]
},
"increment_var": {
"type": "string"
},
Expand Down
11 changes: 6 additions & 5 deletions lib/ProcessContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ delete process.env.pm2_env;
(function ProcessContainer() {
var fs = require('fs');

if (process.env.pmx !== 'false')
if (process.env.pmx !== 'false') {
require('pmx').init({
transactions: process.env.km_link == 'true' && process.env.trace == 'true' || false,
http: process.env.km_link == 'true' || false,
v8: process.env.v8 === 'true' || false
transactions: (process.env.km_link === 'true' && process.env.trace === 'true') || false,
http: process.env.km_link === 'true' || false,
v8: process.env.v8 === 'true' || false,
event_loop_dump: process.env['event-loop-inspector'] === 'true' || false
});
}

var stdFile = pm2_env.pm_log_path;
var outFile = pm2_env.pm_out_log_path;
var errFile = pm2_env.pm_err_log_path;
var pmId = pm2_env.pm_id;
var pidFile = pm2_env.pm_pid_path;
var script = pm2_env.pm_exec_path;
var cronRestart = pm2_env.cron_restart;
Expand Down
9 changes: 5 additions & 4 deletions lib/ProcessContainerFork.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* can be found in the LICENSE file.
*/
// Inject custom modules
if (process.env.pmx !== "false") {
if (process.env.pmx !== 'false') {
require('pmx').init({
transactions: process.env.km_link == 'true' && process.env.trace == 'true' || false,
http: process.env.km_link == 'true' || false,
v8: process.env.v8 === 'true' || false
transactions: (process.env.km_link === 'true' && process.env.trace === 'true') || false,
http: process.env.km_link === 'true' || false,
v8: process.env.v8 === 'true' || false,
event_loop_dump: process.env['event-loop-inspector'] === 'true' || false
});
}

Expand Down

0 comments on commit e6b0c47

Please sign in to comment.