(dashboard) small fixes

This commit is contained in:
Unitech 2017-02-02 17:10:35 +01:00
parent 0c0af4d3f0
commit 0a8937af25

View File

@ -3,15 +3,11 @@
* Use of this source code is governed by a license that
* can be found in the LICENSE file.
*/
// pm2-htop
// Library who interacts with PM2 to display processes resources in htop way
// by Strzelewicz Alexandre
var os = require('os');
var p = require('path');
var blessed = require('blessed');
var fs = require('fs');
var debug = require('debug')('pm2:monit');
// Total memory
@ -34,7 +30,7 @@ Dashboard.init = function() {
this.list = blessed.list({
top: '0',
left: '0',
width: '45%',
width: '35%',
height: '70%',
noCellBorders: true,
scrollbar: {
@ -66,10 +62,10 @@ Dashboard.init = function() {
}
});
this.box1 = blessed.box({
label: ' Logs ',
label: ' Global Logs ',
top: '0%',
left: '45%',
width: '55%',
left: '35%',
width: '65%',
height: '70%',
scrollable: true,
scrollbar: {
@ -149,7 +145,7 @@ Dashboard.init = function() {
}
});
this.box4 = blessed.text({
content: 'left/right: switch boards | up/down/mouse: scroll {|} {green-fg}PM2{/} Dashboard {red-fg}(To go further check out https://app.keymetrics.io){/}',
content: ' left/right: switch boards | up/down/mouse: scroll | Ctrl-C: exit{|} {green-fg}PM2{/} Dashboard {cyan-fg}{bold}(To go further check out https://app.keymetrics.io){/} ',
left: '0%',
top: '94%',
width: '100%',
@ -169,7 +165,7 @@ Dashboard.init = function() {
this.screen.append(this.box3);
this.screen.append(this.box4);
this.list.setLabel(' Processes ');
this.list.setLabel(' Process list ');
this.screen.render();
@ -242,10 +238,10 @@ Dashboard.refresh = function(processes) {
status = status + '{bold}' + processes[i].pm2_env.status + '{/}';
var name = processes[i].pm2_env.name || p.basename(processes[i].pm2_env.pm_exec_path);
// Line of list
var item = '[' + processes[i].pm2_env.pm_id + '] ' + name + '{|} Mem: {' + gradient(memPercent, [255, 0, 0], [0, 255, 0]) + '-fg}' + (processes[i].monit.memory / 1048576).toFixed(2) + '{/} MB Cpu: {' + gradient(processes[i].monit.cpu, [255, 0, 0], [0, 255, 0]) + '-fg}' + processes[i].monit.cpu + '{/} % ' + status;
var item = '[' + processes[i].pm2_env.pm_id + '] ' + name + '{|} Mem: {bold}{' + gradient(memPercent, [255, 0, 0], [0, 255, 0]) + '-fg}' + (processes[i].monit.memory / 1048576).toFixed(2) + '{/} MB Cpu: {bold}{' + gradient(processes[i].monit.cpu, [255, 0, 0], [0, 255, 0]) + '-fg}' + processes[i].monit.cpu + '{/} % ' + status;
// Check if item exist
if (this.list.getItem(i)) {
this.list.setItem(i, item);
@ -256,30 +252,28 @@ Dashboard.refresh = function(processes) {
var proc = processes[this.list.selected];
this.box2.setLine(0, 'Restarts : ' + proc.pm2_env.restart_time);
this.box2.setLine(1, 'Uptime : ' + ((proc.pm2_env.pm_uptime && proc.pm2_env.status == 'online') ? timeSince(proc.pm2_env.pm_uptime) : 0));
this.box2.setLine(2, 'Script path : ' + proc.pm2_env.pm_exec_path);
this.box2.setLine(3, 'Script args : ' + (proc.pm2_env.args ? (typeof proc.pm2_env.args == 'string' ? JSON.parse(proc.pm2_env.args.replace(/'/g, '"')):proc.pm2_env.args).join(' ') : 'N/A'));
this.box2.setLine(4, 'Exec mode : ' + proc.pm2_env.exec_mode);
this.box2.setLine(5, 'Node.js version : ' + proc.pm2_env.node_version);
this.box2.setLine(6, 'watch & reload : ' + (proc.pm2_env.watch ? '{green-fg}{bold}✔{/}' : '{red-fg}{bold}✘{/}'));
this.box2.setLine(7, 'Unstable restarts : ' + proc.pm2_env.unstable_restarts);
this.box2.setLine(8, 'Created at : ' + new Date(proc.pm2_env.created_at).toISOString());
this.box2.setLine(10, 'Revision control : ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.type : 'N/A'));
this.box2.setLine(11, 'Remote url : ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.url : 'N/A'));
this.box2.setLine(12, 'Repository root : ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.repo_path : 'N/A'));
this.box2.setLine(13, 'Last update : ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.update_time : 'N/A'));
this.box2.setLine(14, 'Revision : ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.revision : 'N/A'));
this.box2.setLine(15, 'Comment : ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.comment : 'N/A'));
this.box2.setLine(16, 'Branch : ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.branch : 'N/A'));
this.box2.setLine(0, 'App Name ' + '{bold}' + proc.pm2_env.name + '{/}');
this.box2.setLine(1, 'Restarts ' + proc.pm2_env.restart_time);
this.box2.setLine(2, 'Uptime ' + ((proc.pm2_env.pm_uptime && proc.pm2_env.status == 'online') ? timeSince(proc.pm2_env.pm_uptime) : 0));
this.box2.setLine(3, 'Script path ' + proc.pm2_env.pm_exec_path);
this.box2.setLine(4, 'Script args ' + (proc.pm2_env.args ? (typeof proc.pm2_env.args == 'string' ? JSON.parse(proc.pm2_env.args.replace(/'/g, '"')):proc.pm2_env.args).join(' ') : 'N/A'));
this.box2.setLine(5, 'Exec mode ' + (proc.pm2_env.exec_mode == 'fork_mode' ? '{bold}fork{/}' : '{blue-fg}{bold}cluster{/}'));
this.box2.setLine(6, 'Node.js version ' + proc.pm2_env.node_version);
this.box2.setLine(7, 'watch & reload ' + (proc.pm2_env.watch ? '{green-fg}{bold}✔{/}' : '{red-fg}{bold}✘{/}'));
this.box2.setLine(8, 'Unstable restarts ' + proc.pm2_env.unstable_restarts);
this.box2.setLine(9, 'Comment ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.comment : 'N/A'));
this.box2.setLine(10, 'Revision ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.revision : 'N/A'));
this.box2.setLine(11, 'Branch ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.branch : 'N/A'));
this.box2.setLine(12, 'Remote url ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.url : 'N/A'));
this.box2.setLine(13, 'Last update ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.update_time : 'N/A'));
if (Object.keys(proc.pm2_env.axm_monitor).length != this.box3.items.length) {
this.box3.clearItems();
}
var j = 0;
for(var monitor in proc.pm2_env.axm_monitor) {
var prob = monitor + ' : ' + proc.pm2_env.axm_monitor[monitor].value;
var prob = monitor + ' {|} ' + proc.pm2_env.axm_monitor[monitor].value;
if (this.box3.getItem(j)) {
this.box3.setItem(j, prob);