mirror of
https://github.com/Unitech/pm2.git
synced 2025-12-08 20:35:53 +00:00
Add command pm2 describe <id> to get all informations about a process - tests
This commit is contained in:
parent
7fda1fd985
commit
49aed09a8e
8
bin/pm2
8
bin/pm2
@ -312,6 +312,14 @@ commander.command('generate <name>')
|
||||
CLI.generateSample(name);
|
||||
});
|
||||
|
||||
commander.command('describe <id>')
|
||||
.description('describe all parameters of a process id')
|
||||
.action(CLI.describeProcess);
|
||||
|
||||
commander.command('desc <id>')
|
||||
.description('describe all parameters of a process id')
|
||||
.action(CLI.describeProcess);
|
||||
|
||||
//
|
||||
// List command
|
||||
//
|
||||
|
||||
29
lib/CLI.js
29
lib/CLI.js
@ -639,6 +639,28 @@ CLI.flush = function() {
|
||||
});
|
||||
};
|
||||
|
||||
CLI.describeProcess = function(pm2_id) {
|
||||
var found = false;
|
||||
Satan.executeRemote('getMonitorData', {}, function(err, list) {
|
||||
if (err) {
|
||||
console.error('Error retrieving process list: ' + err);
|
||||
exitCli(cst.ERROR_EXIT);
|
||||
}
|
||||
list.forEach(function(proc) {
|
||||
if (proc.pm_id == pm2_id) {
|
||||
found = true;
|
||||
UX.describeTable(proc);
|
||||
}
|
||||
});
|
||||
|
||||
if (found === false) {
|
||||
printError(pm2_id + ' id doesn\'t exists');
|
||||
return exitCli(cst.ERROR_EXIT);
|
||||
}
|
||||
return exitCli(cst.SUCCESS_EXIT);
|
||||
});
|
||||
};
|
||||
|
||||
CLI.reloadLogs = function() {
|
||||
printOut('Reloading all logs...');
|
||||
Satan.executeRemote('reloadLogs', {}, function(err, logs) {
|
||||
@ -743,7 +765,7 @@ CLI.killDaemon = function() {
|
||||
exitCli(cst.ERROR_EXIT);
|
||||
}
|
||||
|
||||
async.eachLimit(list, 1, function(proc, next) {
|
||||
async.eachLimit(list, 2, function(proc, next) {
|
||||
Satan.executeRemote('deleteProcessId', proc.pm2_env.pm_id, function(err, res) {
|
||||
if (err)
|
||||
printError('Error : ' + err);
|
||||
@ -788,8 +810,11 @@ function speedList() {
|
||||
}
|
||||
if (commander.miniList && !commander.silent)
|
||||
UX.miniDisplay(list);
|
||||
else if (!commander.silent)
|
||||
else if (!commander.silent) {
|
||||
UX.dispAsTable(list);
|
||||
printOut(' Use pm2 describe <id> to get more informations');
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (commander.daemon) {
|
||||
|
||||
51
lib/CliUx.js
51
lib/CliUx.js
@ -31,10 +31,38 @@ UX.miniDisplay = function(list) {
|
||||
|
||||
};
|
||||
|
||||
UX.describeTable = function(process) {
|
||||
var table = new Table({
|
||||
style : {'padding-left' : 1, head : ['cyan', 'bold'], border : ['white'], compact : true}
|
||||
});
|
||||
var pm2_env = process.pm2_env;
|
||||
|
||||
console.log('Describing process with pid %d - name %s', pm2_env.pm_id, pm2_env.name);
|
||||
table.push(
|
||||
{ 'status' : colorStatus(pm2_env.status) },
|
||||
{ 'name': pm2_env.name },
|
||||
{ 'id' : pm2_env.pm_id },
|
||||
{ 'path' : pm2_env.pm_exec_path },
|
||||
{ 'exec cwd' : pm2_env.pm_cwd },
|
||||
{ 'error log path' : pm2_env.pm_err_log_path },
|
||||
{ 'out log path' : pm2_env.pm_out_log_path },
|
||||
{ 'pid path' : pm2_env.pm_pid_path },
|
||||
{ 'mode' : pm2_env.exec_mode },
|
||||
{ 'watch & reload' : pm2_env.watch ? '✔'.green.bold : '✘' },
|
||||
{ 'interpreter' : pm2_env.exec_interpreter },
|
||||
{ 'restarts' : pm2_env.restart_time },
|
||||
{ 'unstable restarts' : pm2_env.unstable_restarts },
|
||||
{ 'uptime' : (pm2_env.pm_uptime && pm2_env.status == 'online') ? timeSince(pm2_env.pm_uptime) : 0 },
|
||||
{ 'created at' : new Date(pm2_env.created_at).toISOString() }
|
||||
);
|
||||
|
||||
console.log(table.toString());
|
||||
};
|
||||
|
||||
UX.dispAsTable = function(list) {
|
||||
var table = new Table({
|
||||
head: ['App Name', 'id', 'mode', 'PID', 'status', 'port', 'Restarted', 'Uptime', 'memory', 'watching', 'err logs'],
|
||||
colAligns : ['left', 'left', 'left', 'left', 'left', 'left', 'right', 'left', 'right', 'right', 'left'],
|
||||
head: ['App Name', 'id', 'mode', 'PID', 'status', 'port', 'Restarted', 'Uptime', 'memory', 'watching'],
|
||||
colAligns : ['left', 'left', 'left', 'left', 'left', 'left', 'right', 'left', 'right', 'right'],
|
||||
style : {'padding-left' : 1, head : ['cyan', 'bold'], border : ['white'], compact : true}
|
||||
});
|
||||
|
||||
@ -50,13 +78,12 @@ UX.dispAsTable = function(list) {
|
||||
l.pm2_env.pm_id,
|
||||
mode == 'fork' ? 'fork'.inverse.bold : 'cluster'.blue.bold,
|
||||
l.pid,
|
||||
status == 'online' ? 'online'.bold.green : status.bold.red,
|
||||
colorStatus(status),
|
||||
port ? port : '',
|
||||
l.pm2_env.restart_time ? l.pm2_env.restart_time : 0,
|
||||
(l.pm2_env.pm_uptime && status == 'online') ? timeSince(l.pm2_env.pm_uptime) : 0,
|
||||
l.monit ? UX.bytesToSize(l.monit.memory, 3) : '',
|
||||
l.pm2_env.watch ? '✔' : '✘',
|
||||
l.pm2_env.pm_err_log_path
|
||||
l.pm2_env.watch ? 'activated'.green.bold : 'unactivated'.grey
|
||||
];
|
||||
|
||||
table.push(obj);
|
||||
@ -96,6 +123,19 @@ UX.bytesToSize = function(bytes, precision) {
|
||||
}
|
||||
};
|
||||
|
||||
function colorStatus(status) {
|
||||
switch (status) {
|
||||
case 'online':
|
||||
return 'online'.green.bold;
|
||||
break;
|
||||
case 'launching':
|
||||
return 'launching'.blue.bold;
|
||||
break;
|
||||
default:
|
||||
return status.bold.red;
|
||||
}
|
||||
};
|
||||
|
||||
function timeSince(date) {
|
||||
|
||||
var seconds = Math.floor((new Date() - date) / 1000);
|
||||
@ -123,4 +163,3 @@ function timeSince(date) {
|
||||
}
|
||||
return Math.floor(seconds) + 's';
|
||||
}
|
||||
|
||||
|
||||
13
test/cli.sh
13
test/cli.sh
@ -46,6 +46,19 @@ OUT=`$pm2 prettylist | grep -o "stopped" | wc -l`
|
||||
[ $OUT -eq 3 ] || fail "$1"
|
||||
success "$1"
|
||||
|
||||
#
|
||||
# Describe process
|
||||
#
|
||||
$pm2 describe 0
|
||||
spec "should describe stopped process"
|
||||
|
||||
$pm2 restart 1
|
||||
|
||||
$pm2 describe 1
|
||||
spec "should describe online process"
|
||||
|
||||
$pm2 describe asdsa
|
||||
ispec "should exit with right exit code when no process found"
|
||||
|
||||
|
||||
#
|
||||
|
||||
@ -31,6 +31,7 @@ describe('God', function() {
|
||||
God.should.have.property('getFormatedProcesses');
|
||||
God.should.have.property('checkProcess');
|
||||
God.should.have.property('stopAll');
|
||||
God.should.have.property('reloadLogs');
|
||||
God.should.have.property('stopProcessId');
|
||||
God.should.have.property('reload');
|
||||
God.should.have.property('reloadProcessName');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user