Skip to content

Commit

Permalink
Unitech#2998 pm2 report for automated reports
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Jul 4, 2017
1 parent 05f0768 commit 8245db8
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 2.6

- #2144 #1060 #2957 #2033 #1872 #2938 #971 Select application uid/gid via --uid --gid (CLI+JSON) + display user via pm2 ls
- #2998 pm2 report command for automated system inspection
- #2997 --disable-logs option to suppress error
- #2290 allow to declare apps under "pm2" attribute (eq "apps"). Nicer in package.json
- pm2 install module-name --uid <uid> --gid <gid> possible
Expand Down
6 changes: 6 additions & 0 deletions bin/pm2
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,12 @@ commander.command('unset <key>')
pm2.unset(key);
});

commander.command('report')
.description('give a full pm2 report for https://github.com/Unitech/pm2/issues')
.action(function(key) {
pm2.report();
});

//
// Keymetrics CLI integratio
//
Expand Down
74 changes: 74 additions & 0 deletions lib/API/Extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ var chalk = require('chalk');
var async = require('async');
var path = require('path');
var fs = require('fs');
var fmt = require('../tools/fmt.js');
var moment = require('moment');
var pkg = require('../../package.json');

module.exports = function(CLI) {

Expand All @@ -28,6 +31,77 @@ module.exports = function(CLI) {
});
};

/**
* Get version of the daemonized PM2
* @method getVersion
* @callback cb
*/
CLI.prototype.report = function(cb) {
var that = this;

var Log = require('./Log');

that.Client.executeRemote('getReport', {}, function(err, report) {
fmt.sep();
fmt.title('PM2 REPORT (' + new Date() + ')');
fmt.sep();
fmt.title(chalk.bold.blue('Daemon'));
fmt.field('pm2d version', report.pm2_version);
fmt.field('node version', report.node_version);
fmt.field('node path', report.node_path);
fmt.field('argv', report.argv);
fmt.field('argv0', report.argv0);
fmt.field('user', report.user);
fmt.field('uid', report.uid);
fmt.field('gid', report.gid);
fmt.field('uptime', moment(new Date()).diff(report.started_at, 'minute') + 'min');

fmt.sep();
fmt.title(chalk.bold.blue('CLI'));
fmt.field('local pm2', pkg.version);
fmt.field('node version', process.versions.node);
fmt.field('node path', process.env['_']);
fmt.field('argv', process.argv);
fmt.field('argv0', process.argv0);
fmt.field('user', process.env.USER);
fmt.field('uid', process.geteuid());
fmt.field('gid', process.getegid());

var os = require('os');

fmt.sep();
fmt.title(chalk.bold.blue('System info'));
fmt.field('arch', os.arch());
fmt.field('platform', os.platform());
fmt.field('type', os.type());
fmt.field('cpus', os.cpus()[0].model);
fmt.field('cpus nb', Object.keys(os.cpus()).length);
fmt.field('freemem', os.freemem());
fmt.field('totalmem', os.totalmem());
fmt.field('home', os.homedir());

that.Client.executeRemote('getMonitorData', {}, function(err, list) {

fmt.sep();
fmt.title(chalk.bold.blue('PM2 list'));
that.list();

UX.dispAsTable(list, that.gl_interact_infos);

fmt.sep();
fmt.title(chalk.bold.blue('Daemon logs'));
Log.tail([{
path : cst.PM2_LOG_FILE_PATH,
app_name : 'PM2',
type : 'PM2'
}], 20, false, function() {
console.log(chalk.bold.green('Please copy/paste the above report in your issue on https://github.com/Unitech/pm2/issues'));
that.exitCli(cst.SUCCESS_EXIT);
});
});
});
};

/**
* Create PM2 memory snapshot
* @method getVersion
Expand Down
2 changes: 1 addition & 1 deletion lib/API/LogManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ module.exports = function(CLI) {
// Get the list of all running apps
that.Client.executeRemote('getMonitorData', {}, function(err, list) {
var regexList = [];

if (err) {
Common.printError(err);
that.exitCli(cst.ERROR_EXIT);
Expand Down
1 change: 1 addition & 0 deletions lib/Daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ Daemon.prototype.innerStart = function(cb) {

ping : God.ping,
getVersion : God.getVersion,
getReport : God.getReport,
reloadLogs : God.reloadLogs
});

Expand Down
1 change: 1 addition & 0 deletions lib/God.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ cluster.setupMaster({
var God = module.exports = {
next_id : 0,
clusters_db : {},
started_at : Date.now(),
bus : new EventEmitter2({
wildcard: true,
delimiter: ':',
Expand Down
23 changes: 23 additions & 0 deletions lib/God/ActionMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,4 +764,27 @@ module.exports = function(God) {
});
};

God.getReport = function(arg, cb) {
var report = {
pm2_version : pkg.version,
node_version : 'N/A',
node_path : process.env['_'],
argv0 : process.argv0,
argv : process.argv,
user : process.env.USER,
uid : process.geteuid ? process.geteuid() : 'N/A',
gid : process.getegid ? process.getegid() : 'N/A',
env : process.env,
managed_apps : Object.keys(God.clusters_db).length,
started_at : God.started_at
};

if (process.versions && process.versions.node) {
report.node_version = process.versions.node;
}

process.nextTick(function() {
return cb(null, report);
});
};
};

0 comments on commit 8245db8

Please sign in to comment.