Skip to content

Commit b0fd46c

Browse files
committed
#2998 pm2 report for automated reports
1 parent 792e4aa commit b0fd46c

File tree

7 files changed

+107
-1
lines changed

7 files changed

+107
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 2.6
22

33
- #2144 #1060 #2957 #2033 #1872 #2938 #971 Select application uid/gid via --uid --gid (CLI+JSON) + display user via pm2 ls
4+
- #2998 pm2 report command for automated system inspection
45
- #2997 --disable-logs option to suppress error
56
- #2290 allow to declare apps under "pm2" attribute (eq "apps"). Nicer in package.json
67
- pm2 install module-name --uid <uid> --gid <gid> possible

bin/pm2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,12 @@ commander.command('unset <key>')
524524
pm2.unset(key);
525525
});
526526

527+
commander.command('report')
528+
.description('give a full pm2 report for https://github.com/Unitech/pm2/issues')
529+
.action(function(key) {
530+
pm2.report();
531+
});
532+
527533
//
528534
// Keymetrics CLI integratio
529535
//

lib/API/Extra.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ var chalk = require('chalk');
1212
var async = require('async');
1313
var path = require('path');
1414
var fs = require('fs');
15+
var fmt = require('../tools/fmt.js');
16+
var moment = require('moment');
17+
var pkg = require('../../package.json');
1518

1619
module.exports = function(CLI) {
1720

@@ -28,6 +31,77 @@ module.exports = function(CLI) {
2831
});
2932
};
3033

34+
/**
35+
* Get version of the daemonized PM2
36+
* @method getVersion
37+
* @callback cb
38+
*/
39+
CLI.prototype.report = function(cb) {
40+
var that = this;
41+
42+
var Log = require('./Log');
43+
44+
that.Client.executeRemote('getReport', {}, function(err, report) {
45+
fmt.sep();
46+
fmt.title('PM2 REPORT (' + new Date() + ')');
47+
fmt.sep();
48+
fmt.title(chalk.bold.blue('Daemon'));
49+
fmt.field('pm2d version', report.pm2_version);
50+
fmt.field('node version', report.node_version);
51+
fmt.field('node path', report.node_path);
52+
fmt.field('argv', report.argv);
53+
fmt.field('argv0', report.argv0);
54+
fmt.field('user', report.user);
55+
fmt.field('uid', report.uid);
56+
fmt.field('gid', report.gid);
57+
fmt.field('uptime', moment(new Date()).diff(report.started_at, 'minute') + 'min');
58+
59+
fmt.sep();
60+
fmt.title(chalk.bold.blue('CLI'));
61+
fmt.field('local pm2', pkg.version);
62+
fmt.field('node version', process.versions.node);
63+
fmt.field('node path', process.env['_']);
64+
fmt.field('argv', process.argv);
65+
fmt.field('argv0', process.argv0);
66+
fmt.field('user', process.env.USER);
67+
fmt.field('uid', process.geteuid());
68+
fmt.field('gid', process.getegid());
69+
70+
var os = require('os');
71+
72+
fmt.sep();
73+
fmt.title(chalk.bold.blue('System info'));
74+
fmt.field('arch', os.arch());
75+
fmt.field('platform', os.platform());
76+
fmt.field('type', os.type());
77+
fmt.field('cpus', os.cpus()[0].model);
78+
fmt.field('cpus nb', Object.keys(os.cpus()).length);
79+
fmt.field('freemem', os.freemem());
80+
fmt.field('totalmem', os.totalmem());
81+
fmt.field('home', os.homedir());
82+
83+
that.Client.executeRemote('getMonitorData', {}, function(err, list) {
84+
85+
fmt.sep();
86+
fmt.title(chalk.bold.blue('PM2 list'));
87+
that.list();
88+
89+
UX.dispAsTable(list, that.gl_interact_infos);
90+
91+
fmt.sep();
92+
fmt.title(chalk.bold.blue('Daemon logs'));
93+
Log.tail([{
94+
path : cst.PM2_LOG_FILE_PATH,
95+
app_name : 'PM2',
96+
type : 'PM2'
97+
}], 20, false, function() {
98+
console.log(chalk.bold.green('Please copy/paste the above report in your issue on https://github.com/Unitech/pm2/issues'));
99+
that.exitCli(cst.SUCCESS_EXIT);
100+
});
101+
});
102+
});
103+
};
104+
31105
/**
32106
* Create PM2 memory snapshot
33107
* @method getVersion

lib/API/LogManagement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ module.exports = function(CLI) {
139139
// Get the list of all running apps
140140
that.Client.executeRemote('getMonitorData', {}, function(err, list) {
141141
var regexList = [];
142-
142+
143143
if (err) {
144144
Common.printError(err);
145145
that.exitCli(cst.ERROR_EXIT);

lib/Daemon.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ Daemon.prototype.innerStart = function(cb) {
209209

210210
ping : God.ping,
211211
getVersion : God.getVersion,
212+
getReport : God.getReport,
212213
reloadLogs : God.reloadLogs
213214
});
214215

lib/God.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ cluster.setupMaster({
4040
var God = module.exports = {
4141
next_id : 0,
4242
clusters_db : {},
43+
started_at : Date.now(),
4344
bus : new EventEmitter2({
4445
wildcard: true,
4546
delimiter: ':',

lib/God/ActionMethods.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,4 +764,27 @@ module.exports = function(God) {
764764
});
765765
};
766766

767+
God.getReport = function(arg, cb) {
768+
var report = {
769+
pm2_version : pkg.version,
770+
node_version : 'N/A',
771+
node_path : process.env['_'],
772+
argv0 : process.argv0,
773+
argv : process.argv,
774+
user : process.env.USER,
775+
uid : process.geteuid ? process.geteuid() : 'N/A',
776+
gid : process.getegid ? process.getegid() : 'N/A',
777+
env : process.env,
778+
managed_apps : Object.keys(God.clusters_db).length,
779+
started_at : God.started_at
780+
};
781+
782+
if (process.versions && process.versions.node) {
783+
report.node_version = process.versions.node;
784+
}
785+
786+
process.nextTick(function() {
787+
return cb(null, report);
788+
});
789+
};
767790
};

0 commit comments

Comments
 (0)