@ohos-ports/pm2 0.0.0-stage → 7.1.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2607 -0
- package/CONTRIBUTING.md +124 -0
- package/GNU-AGPL-3.0.txt +665 -0
- package/LICENSE +1 -0
- package/README.md +255 -2
- package/SECURITY.md +41 -0
- package/bin/pm2 +3 -0
- package/bin/pm2-dev +3 -0
- package/bin/pm2-docker +3 -0
- package/bin/pm2-runtime +3 -0
- package/bin/pm2.ps1 +3 -0
- package/constants.js +113 -0
- package/index.js +12 -0
- package/lib/API/Configuration.js +212 -0
- package/lib/API/Containerizer.js +335 -0
- package/lib/API/Dashboard.js +726 -0
- package/lib/API/Deploy.js +117 -0
- package/lib/API/Extra.js +798 -0
- package/lib/API/ExtraMgmt/Docker.js +30 -0
- package/lib/API/Log.js +388 -0
- package/lib/API/LogManagement.js +351 -0
- package/lib/API/Modules/LOCAL.js +122 -0
- package/lib/API/Modules/Modularizer.js +148 -0
- package/lib/API/Modules/NPM.js +443 -0
- package/lib/API/Modules/TAR.js +368 -0
- package/lib/API/Modules/flagExt.js +46 -0
- package/lib/API/Modules/index.js +120 -0
- package/lib/API/Monit.js +247 -0
- package/lib/API/Serve.js +497 -0
- package/lib/API/Startup.js +630 -0
- package/lib/API/UX/helpers.js +213 -0
- package/lib/API/UX/index.js +9 -0
- package/lib/API/UX/pm2-describe.js +197 -0
- package/lib/API/UX/pm2-ls-minimal.js +31 -0
- package/lib/API/UX/pm2-ls.js +581 -0
- package/lib/API/Version.js +383 -0
- package/lib/API/interpreter.json +12 -0
- package/lib/API/pm2-plus/PM2IO.js +381 -0
- package/lib/API/pm2-plus/auth-strategies/CliAuth.js +306 -0
- package/lib/API/pm2-plus/auth-strategies/WebAuth.js +195 -0
- package/lib/API/pm2-plus/helpers.js +97 -0
- package/lib/API/pm2-plus/link.js +126 -0
- package/lib/API/pm2-plus/pres/motd +16 -0
- package/lib/API/pm2-plus/pres/motd.update +26 -0
- package/lib/API/pm2-plus/pres/welcome +28 -0
- package/lib/API/pm2-plus/process-selector.js +52 -0
- package/lib/API/schema.json +375 -0
- package/lib/API.js +1980 -0
- package/lib/Client.js +793 -0
- package/lib/Common.js +949 -0
- package/lib/Configuration.js +309 -0
- package/lib/Daemon.js +468 -0
- package/lib/Event.js +37 -0
- package/lib/God/ActionMethods.js +955 -0
- package/lib/God/ClusterMode.js +192 -0
- package/lib/God/ForkMode.js +205 -0
- package/lib/God/Methods.js +292 -0
- package/lib/God/Reload.js +300 -0
- package/lib/God/StdioLogger.js +239 -0
- package/lib/God.js +653 -0
- package/lib/HttpInterface.js +75 -0
- package/lib/OtelManager.js +74 -0
- package/lib/ProcessContainer.js +321 -0
- package/lib/ProcessContainerBun.js +355 -0
- package/lib/ProcessContainerFork.js +42 -0
- package/lib/ProcessContainerForkBun.js +31 -0
- package/lib/ProcessUtils.js +74 -0
- package/lib/TreeKill.js +111 -0
- package/lib/Utility.js +304 -0
- package/lib/VersionCheck.js +46 -0
- package/lib/Watcher.js +117 -0
- package/lib/Worker.js +200 -0
- package/lib/binaries/CLI.js +1092 -0
- package/lib/binaries/DevCLI.js +183 -0
- package/lib/binaries/Runtime.js +101 -0
- package/lib/binaries/Runtime4Docker.js +192 -0
- package/lib/completion.js +229 -0
- package/lib/completion.sh +40 -0
- package/lib/motd +36 -0
- package/lib/templates/Dockerfiles/Dockerfile-nodejs.tpl +8 -0
- package/lib/templates/ecosystem-es.tpl +24 -0
- package/lib/templates/ecosystem-simple-es.tpl +8 -0
- package/lib/templates/ecosystem-simple.tpl +6 -0
- package/lib/templates/ecosystem.tpl +22 -0
- package/lib/templates/init-scripts/launchd.tpl +35 -0
- package/lib/templates/init-scripts/openrc.tpl +52 -0
- package/lib/templates/init-scripts/pm2-init-amazon.sh +86 -0
- package/lib/templates/init-scripts/rcd-openbsd.tpl +41 -0
- package/lib/templates/init-scripts/rcd.tpl +44 -0
- package/lib/templates/init-scripts/smf.tpl +43 -0
- package/lib/templates/init-scripts/systemd-online.tpl +22 -0
- package/lib/templates/init-scripts/systemd.tpl +22 -0
- package/lib/templates/init-scripts/upstart.tpl +103 -0
- package/lib/templates/logrotate.d/pm2 +10 -0
- package/lib/templates/sample-apps/http-server/README.md +14 -0
- package/lib/templates/sample-apps/http-server/api.js +9 -0
- package/lib/templates/sample-apps/http-server/ecosystem.config.js +14 -0
- package/lib/templates/sample-apps/http-server/package.json +11 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/README.md +45 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/custom-metrics.js +66 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/ecosystem.config.js +12 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/package.json +11 -0
- package/lib/templates/sample-apps/python-app/README.md +4 -0
- package/lib/templates/sample-apps/python-app/echo.py +7 -0
- package/lib/templates/sample-apps/python-app/ecosystem.config.js +12 -0
- package/lib/templates/sample-apps/python-app/package.json +11 -0
- package/lib/tools/Config.js +251 -0
- package/lib/tools/SysMetrics.js +375 -0
- package/lib/tools/copydirSync.js +101 -0
- package/lib/tools/deleteFolderRecursive.js +19 -0
- package/lib/tools/find-package-json.js +74 -0
- package/lib/tools/fmt.js +72 -0
- package/lib/tools/interpreter.js +88 -0
- package/lib/tools/isbinaryfile.js +94 -0
- package/lib/tools/json5.js +752 -0
- package/lib/tools/multimeter/bar.js +111 -0
- package/lib/tools/multimeter/charm/encode.js +18 -0
- package/lib/tools/multimeter/charm/index.js +305 -0
- package/lib/tools/multimeter/index.js +76 -0
- package/lib/tools/open.js +56 -0
- package/lib/tools/passwd.js +58 -0
- package/lib/tools/pm2-config-keys.js +165 -0
- package/lib/tools/prompt.js +76 -0
- package/lib/tools/serviceStop.js +149 -0
- package/lib/tools/sexec.js +55 -0
- package/lib/tools/treeify.js +113 -0
- package/lib/tools/typestrip.js +55 -0
- package/lib/tools/which.js +120 -0
- package/lib/tools/xdg-open +861 -0
- package/modules/blessed/LICENSE +20 -0
- package/modules/blessed/README.md +34 -0
- package/modules/blessed/index.js +1 -0
- package/modules/blessed/lib/alias.js +526 -0
- package/modules/blessed/lib/blessed.js +32 -0
- package/modules/blessed/lib/colors.js +530 -0
- package/modules/blessed/lib/events.js +189 -0
- package/modules/blessed/lib/gpmclient.js +221 -0
- package/modules/blessed/lib/helpers.js +165 -0
- package/modules/blessed/lib/keys.js +339 -0
- package/modules/blessed/lib/program.js +4297 -0
- package/modules/blessed/lib/tput.js +3022 -0
- package/modules/blessed/lib/unicode.js +885 -0
- package/modules/blessed/lib/widget.js +32 -0
- package/modules/blessed/lib/widgets/box.js +34 -0
- package/modules/blessed/lib/widgets/element.js +2570 -0
- package/modules/blessed/lib/widgets/list.js +599 -0
- package/modules/blessed/lib/widgets/log.js +83 -0
- package/modules/blessed/lib/widgets/node.js +282 -0
- package/modules/blessed/lib/widgets/screen.js +2298 -0
- package/modules/blessed/lib/widgets/scrollablebox.js +389 -0
- package/modules/blessed/lib/widgets/scrollabletext.js +35 -0
- package/modules/blessed/lib/widgets/text.js +35 -0
- package/modules/blessed/usr/linux +0 -0
- package/modules/blessed/usr/windows-ansi +0 -0
- package/modules/blessed/usr/xterm +0 -0
- package/modules/blessed/usr/xterm-256color +0 -0
- package/modules/blessed/usr/xterm.termcap +243 -0
- package/modules/chokidar/LICENSE +21 -0
- package/modules/chokidar/VENDORED.md +76 -0
- package/modules/chokidar/index.js +979 -0
- package/modules/chokidar/lib/brace-expand.js +180 -0
- package/modules/chokidar/lib/constants.js +66 -0
- package/modules/chokidar/lib/fsevents-handler.js +526 -0
- package/modules/chokidar/lib/nodefs-handler.js +654 -0
- package/modules/fclone.js +49 -0
- package/modules/pm2-axon/index.js +2 -0
- package/modules/pm2-axon/lib/configurable/History.md +5 -0
- package/modules/pm2-axon/lib/configurable/Makefile +7 -0
- package/modules/pm2-axon/lib/configurable/Readme.md +57 -0
- package/modules/pm2-axon/lib/configurable/index.js +2 -0
- package/modules/pm2-axon/lib/configurable/lib/configurable.js +47 -0
- package/modules/pm2-axon/lib/configurable/package.json +68 -0
- package/modules/pm2-axon/lib/index.js +44 -0
- package/modules/pm2-axon/lib/plugins/queue.js +71 -0
- package/modules/pm2-axon/lib/plugins/round-robin.js +55 -0
- package/modules/pm2-axon/lib/sockets/pub-emitter.js +26 -0
- package/modules/pm2-axon/lib/sockets/pub.js +77 -0
- package/modules/pm2-axon/lib/sockets/pull.js +37 -0
- package/modules/pm2-axon/lib/sockets/push.js +32 -0
- package/modules/pm2-axon/lib/sockets/rep.js +73 -0
- package/modules/pm2-axon/lib/sockets/req.js +101 -0
- package/modules/pm2-axon/lib/sockets/sock.js +430 -0
- package/modules/pm2-axon/lib/sockets/sub-emitter.js +92 -0
- package/modules/pm2-axon/lib/sockets/sub.js +147 -0
- package/modules/pm2-axon/lib/utils.js +19 -0
- package/modules/pm2-axon-rpc/index.js +3 -0
- package/modules/pm2-axon-rpc/lib/client.js +63 -0
- package/modules/pm2-axon-rpc/lib/server.js +139 -0
- package/modules/pm2-io-agent/LICENSE +661 -0
- package/modules/pm2-io-agent/README.md +62 -0
- package/modules/pm2-io-agent/config.js +30 -0
- package/modules/pm2-io-agent/constants.js +118 -0
- package/modules/pm2-io-agent/index.js +2 -0
- package/modules/pm2-io-agent/src/InteractorClient.js +513 -0
- package/modules/pm2-io-agent/src/InteractorDaemon.js +455 -0
- package/modules/pm2-io-agent/src/PM2Client.js +112 -0
- package/modules/pm2-io-agent/src/PM2Interface.js +180 -0
- package/modules/pm2-io-agent/src/TransporterInterface.js +173 -0
- package/modules/pm2-io-agent/src/Utility.js +392 -0
- package/modules/pm2-io-agent/src/WatchDog.js +70 -0
- package/modules/pm2-io-agent/src/push/DataRetriever.js +77 -0
- package/modules/pm2-io-agent/src/push/PushInteractor.js +206 -0
- package/modules/pm2-io-agent/src/push/TransactionAggregator.js +670 -0
- package/modules/pm2-io-agent/src/reverse/ReverseInteractor.js +128 -0
- package/modules/pm2-io-agent/src/transporters/Transporter.js +129 -0
- package/modules/pm2-io-agent/src/transporters/WebsocketTransport.js +202 -0
- package/modules/pm2-io-agent/src/utils/BinaryHeap.js +135 -0
- package/modules/pm2-io-agent/src/utils/EDS.js +111 -0
- package/modules/pm2-io-agent/src/utils/probes/Histogram.js +204 -0
- package/modules/pm2-io-agent/src/utils/units.js +10 -0
- package/modules/pm2-io-bpm/configuration.js +141 -0
- package/modules/pm2-io-bpm/constants.js +10 -0
- package/modules/pm2-io-bpm/featureManager.js +110 -0
- package/modules/pm2-io-bpm/features/dependencies.js +48 -0
- package/modules/pm2-io-bpm/features/events.js +50 -0
- package/modules/pm2-io-bpm/features/metrics.js +102 -0
- package/modules/pm2-io-bpm/features/notify.js +238 -0
- package/modules/pm2-io-bpm/features/profiling.js +70 -0
- package/modules/pm2-io-bpm/features/tracing.js +174 -0
- package/modules/pm2-io-bpm/index.js +11 -0
- package/modules/pm2-io-bpm/metrics/eventLoopMetrics.js +136 -0
- package/modules/pm2-io-bpm/metrics/httpMetrics.js +175 -0
- package/modules/pm2-io-bpm/metrics/network.js +132 -0
- package/modules/pm2-io-bpm/metrics/runtime.js +161 -0
- package/modules/pm2-io-bpm/metrics/v8.js +104 -0
- package/modules/pm2-io-bpm/otel/constants.js +7 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/index.js +17 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/index.js +17 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/util.js +51 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/transform.js +137 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/types.js +24 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/utils.js +23 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/zipkin.js +149 -0
- package/modules/pm2-io-bpm/pmx.js +380 -0
- package/modules/pm2-io-bpm/profilers/addonProfiler.js +193 -0
- package/modules/pm2-io-bpm/profilers/inspectorProfiler.js +302 -0
- package/modules/pm2-io-bpm/serviceManager.js +21 -0
- package/modules/pm2-io-bpm/services/actions.js +159 -0
- package/modules/pm2-io-bpm/services/inspector.js +43 -0
- package/modules/pm2-io-bpm/services/metrics.js +186 -0
- package/modules/pm2-io-bpm/services/runtimeStats.js +54 -0
- package/modules/pm2-io-bpm/services/transport.js +11 -0
- package/modules/pm2-io-bpm/transports/IPCTransport.js +115 -0
- package/modules/pm2-io-bpm/utils/BinaryHeap.js +134 -0
- package/modules/pm2-io-bpm/utils/EDS.js +113 -0
- package/modules/pm2-io-bpm/utils/EWMA.js +32 -0
- package/modules/pm2-io-bpm/utils/autocast.js +61 -0
- package/modules/pm2-io-bpm/utils/metrics/counter.js +33 -0
- package/modules/pm2-io-bpm/utils/metrics/gauge.js +23 -0
- package/modules/pm2-io-bpm/utils/metrics/histogram.js +192 -0
- package/modules/pm2-io-bpm/utils/metrics/meter.js +46 -0
- package/modules/pm2-io-bpm/utils/miscellaneous.js +19 -0
- package/modules/pm2-io-bpm/utils/module.js +67 -0
- package/modules/pm2-io-bpm/utils/shimmer.js +19 -0
- package/modules/pm2-io-bpm/utils/stackParser.js +160 -0
- package/modules/pm2-io-bpm/utils/transactionAggregator.js +429 -0
- package/modules/pm2-io-bpm/utils/units.js +16 -0
- package/modules/vizion/LICENSE +13 -0
- package/modules/vizion/README.md +133 -0
- package/modules/vizion/index.js +1 -0
- package/modules/vizion/lib/git/git.js +247 -0
- package/modules/vizion/lib/vizion.js +52 -0
- package/package.json +170 -4
- package/paths.js +121 -0
- package/pm2 +11 -0
- package/types/index.d.ts +732 -0
- package/types/tsconfig.json +14 -0
|
@@ -0,0 +1,726 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013-present the PM2 project authors. All rights reserved.
|
|
3
|
+
* Use of this source code is governed by a license that
|
|
4
|
+
* can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
var os = require('os');
|
|
8
|
+
var p = require('path');
|
|
9
|
+
var blessed = require('../../modules/blessed');
|
|
10
|
+
var debug = require('debug')('pm2:monit');
|
|
11
|
+
|
|
12
|
+
// Total memory
|
|
13
|
+
const totalMem = os.totalmem();
|
|
14
|
+
|
|
15
|
+
var Dashboard = {};
|
|
16
|
+
|
|
17
|
+
var DEFAULT_PADDING = {
|
|
18
|
+
top : 0,
|
|
19
|
+
left : 1,
|
|
20
|
+
right : 1
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
var WIDTH_LEFT_PANEL = 30;
|
|
24
|
+
|
|
25
|
+
// Default / maximum number of log lines preloaded and kept per process
|
|
26
|
+
var DEFAULT_LOG_LINES = 200;
|
|
27
|
+
var MAX_LOG_LINES = 10000;
|
|
28
|
+
|
|
29
|
+
var LOG_COLORS = {
|
|
30
|
+
PM2 : '{blue-fg}',
|
|
31
|
+
out : '{green-fg}',
|
|
32
|
+
err : '{red-fg}'
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Synchronous Dashboard init method
|
|
37
|
+
* @method init
|
|
38
|
+
* @param {Object} opts
|
|
39
|
+
* @param {Number} opts.lines number of log lines per process (default 200)
|
|
40
|
+
* @return this
|
|
41
|
+
*/
|
|
42
|
+
Dashboard.init = function(opts) {
|
|
43
|
+
opts = opts || {};
|
|
44
|
+
|
|
45
|
+
// Init Screen
|
|
46
|
+
this.screen = blessed.screen({
|
|
47
|
+
smartCSR: true,
|
|
48
|
+
fullUnicode: true
|
|
49
|
+
});
|
|
50
|
+
this.screen.title = 'PM2 Dashboard';
|
|
51
|
+
|
|
52
|
+
this.logLines = {}
|
|
53
|
+
this.maxLines = Dashboard.parseLines(opts.lines);
|
|
54
|
+
|
|
55
|
+
this.list = blessed.list({
|
|
56
|
+
top: '0',
|
|
57
|
+
left: '0',
|
|
58
|
+
width: WIDTH_LEFT_PANEL + '%',
|
|
59
|
+
height: '70%',
|
|
60
|
+
padding: 0,
|
|
61
|
+
scrollbar: {
|
|
62
|
+
ch: ' ',
|
|
63
|
+
inverse: false
|
|
64
|
+
},
|
|
65
|
+
border: {
|
|
66
|
+
type: 'line'
|
|
67
|
+
},
|
|
68
|
+
keys: true,
|
|
69
|
+
autoCommandKeys: true,
|
|
70
|
+
tags: true,
|
|
71
|
+
style: {
|
|
72
|
+
selected: {
|
|
73
|
+
bg: 'blue',
|
|
74
|
+
fg: 'white'
|
|
75
|
+
},
|
|
76
|
+
scrollbar: {
|
|
77
|
+
bg: 'blue',
|
|
78
|
+
fg: 'black'
|
|
79
|
+
},
|
|
80
|
+
fg: 'white',
|
|
81
|
+
border: {
|
|
82
|
+
fg: 'blue'
|
|
83
|
+
},
|
|
84
|
+
header: {
|
|
85
|
+
fg: 'blue'
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Re-render the side panes right away from the last process list
|
|
91
|
+
// received, instead of waiting for the next getMonitorData tick
|
|
92
|
+
this.list.on('select item', (item, i) => {
|
|
93
|
+
this.logBox.clearItems()
|
|
94
|
+
if (this.processes)
|
|
95
|
+
this.refresh(this.processes);
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
// Page-wise scrolling of the focused log pane: Ctrl+Up / Ctrl+Down
|
|
99
|
+
// (PageUp / PageDown as well)
|
|
100
|
+
var pageScroll = (direction, key) => {
|
|
101
|
+
if (!this.logBox.focused) return;
|
|
102
|
+
var page = Math.max(1, this.logBox.height - this.logBox.iheight);
|
|
103
|
+
// the list's own 'up'/'down' handler still runs after this one for
|
|
104
|
+
// Ctrl+arrows (it ignores the modifier) and moves one more line
|
|
105
|
+
if (key.ctrl) page -= 1;
|
|
106
|
+
this.logBox.move(direction * page);
|
|
107
|
+
this.screen.render();
|
|
108
|
+
};
|
|
109
|
+
this.screen.key(['C-up', 'pageup'], (ch, key) => pageScroll(-1, key));
|
|
110
|
+
this.screen.key(['C-down', 'pagedown'], (ch, key) => pageScroll(1, key));
|
|
111
|
+
|
|
112
|
+
this.logBox = blessed.list({
|
|
113
|
+
label: ' Logs ',
|
|
114
|
+
top: '0',
|
|
115
|
+
left: WIDTH_LEFT_PANEL + '%',
|
|
116
|
+
width: 100 - WIDTH_LEFT_PANEL + '%',
|
|
117
|
+
height: '70%',
|
|
118
|
+
padding: DEFAULT_PADDING,
|
|
119
|
+
scrollable: true,
|
|
120
|
+
scrollbar: {
|
|
121
|
+
ch: ' ',
|
|
122
|
+
inverse: false
|
|
123
|
+
},
|
|
124
|
+
keys: true,
|
|
125
|
+
autoCommandKeys: true,
|
|
126
|
+
tags: true,
|
|
127
|
+
border: {
|
|
128
|
+
type: 'line'
|
|
129
|
+
},
|
|
130
|
+
style: {
|
|
131
|
+
fg: 'white',
|
|
132
|
+
border: {
|
|
133
|
+
fg: 'white'
|
|
134
|
+
},
|
|
135
|
+
scrollbar: {
|
|
136
|
+
bg: 'blue',
|
|
137
|
+
fg: 'black'
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
this.metadataBox = blessed.box({
|
|
143
|
+
label: ' Metadata ',
|
|
144
|
+
top: '70%',
|
|
145
|
+
left: WIDTH_LEFT_PANEL + '%',
|
|
146
|
+
width: 100 - WIDTH_LEFT_PANEL + '%',
|
|
147
|
+
bottom: 1,
|
|
148
|
+
padding: DEFAULT_PADDING,
|
|
149
|
+
scrollable: true,
|
|
150
|
+
scrollbar: {
|
|
151
|
+
ch: ' ',
|
|
152
|
+
inverse: false
|
|
153
|
+
},
|
|
154
|
+
keys: true,
|
|
155
|
+
autoCommandKeys: true,
|
|
156
|
+
tags: true,
|
|
157
|
+
border: {
|
|
158
|
+
type: 'line'
|
|
159
|
+
},
|
|
160
|
+
style: {
|
|
161
|
+
fg: 'white',
|
|
162
|
+
border: {
|
|
163
|
+
fg: 'white'
|
|
164
|
+
},
|
|
165
|
+
scrollbar: {
|
|
166
|
+
bg: 'blue',
|
|
167
|
+
fg: 'black'
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
this.metricsBox = blessed.list({
|
|
173
|
+
label: ' Custom Metrics ',
|
|
174
|
+
top: '70%',
|
|
175
|
+
left: '0%',
|
|
176
|
+
width: WIDTH_LEFT_PANEL + '%',
|
|
177
|
+
bottom: 1,
|
|
178
|
+
padding: DEFAULT_PADDING,
|
|
179
|
+
scrollbar: {
|
|
180
|
+
ch: ' ',
|
|
181
|
+
inverse: false
|
|
182
|
+
},
|
|
183
|
+
keys: true,
|
|
184
|
+
autoCommandKeys: true,
|
|
185
|
+
tags: true,
|
|
186
|
+
border: {
|
|
187
|
+
type: 'line'
|
|
188
|
+
},
|
|
189
|
+
style: {
|
|
190
|
+
fg: 'white',
|
|
191
|
+
border: {
|
|
192
|
+
fg: 'white'
|
|
193
|
+
},
|
|
194
|
+
scrollbar: {
|
|
195
|
+
bg: 'blue',
|
|
196
|
+
fg: 'black'
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
this.box4 = blessed.text({
|
|
202
|
+
content: ' left/right: switch boards | up/down/mouse: scroll | Ctrl-up/down: page | Ctrl-C: exit{|} {cyan-fg}{bold}To go further check out https://pm2.io/{/} ',
|
|
203
|
+
left: '0%',
|
|
204
|
+
bottom: 0,
|
|
205
|
+
width: '100%',
|
|
206
|
+
height: 1,
|
|
207
|
+
tags: true,
|
|
208
|
+
style: {
|
|
209
|
+
fg: 'white'
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
this.list.focus();
|
|
214
|
+
|
|
215
|
+
this.screen.append(this.list);
|
|
216
|
+
this.screen.append(this.logBox);
|
|
217
|
+
this.screen.append(this.metadataBox);
|
|
218
|
+
this.screen.append(this.metricsBox);
|
|
219
|
+
this.screen.append(this.box4);
|
|
220
|
+
|
|
221
|
+
this.list.setLabel(' Process List ');
|
|
222
|
+
|
|
223
|
+
this.screen.render();
|
|
224
|
+
|
|
225
|
+
var that = this;
|
|
226
|
+
|
|
227
|
+
var i = 0;
|
|
228
|
+
var boards = ['list', 'logBox', 'metricsBox', 'metadataBox'];
|
|
229
|
+
this.screen.key(['left', 'right'], function(ch, key) {
|
|
230
|
+
(key.name === 'left') ? i-- : i++;
|
|
231
|
+
if (i == 4)
|
|
232
|
+
i = 0;
|
|
233
|
+
if (i == -1)
|
|
234
|
+
i = 3;
|
|
235
|
+
that[boards[i]].focus();
|
|
236
|
+
that[boards[i]].style.border.fg = 'blue';
|
|
237
|
+
if (key.name === 'left') {
|
|
238
|
+
if (i == 3)
|
|
239
|
+
that[boards[0]].style.border.fg = 'white';
|
|
240
|
+
else
|
|
241
|
+
that[boards[i + 1]].style.border.fg = 'white';
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
if (i == 0)
|
|
245
|
+
that[boards[3]].style.border.fg = 'white';
|
|
246
|
+
else
|
|
247
|
+
that[boards[i - 1]].style.border.fg = 'white';
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
this.screen.key(['escape', 'q', 'C-c'], function(ch, key) {
|
|
252
|
+
this.screen.destroy();
|
|
253
|
+
process.exit(0);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// async refresh of the ui
|
|
257
|
+
setInterval(function () {
|
|
258
|
+
that.screen.render();
|
|
259
|
+
}, 300);
|
|
260
|
+
|
|
261
|
+
return this;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Refresh dashboard
|
|
266
|
+
* @method refresh
|
|
267
|
+
* @param {} processes
|
|
268
|
+
* @return this
|
|
269
|
+
*/
|
|
270
|
+
Dashboard.refresh = function(processes) {
|
|
271
|
+
debug('Monit refresh');
|
|
272
|
+
|
|
273
|
+
if(!processes) {
|
|
274
|
+
this.list.setItem(0, 'No process available');
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// keep the last list around for instant re-rendering on selection change
|
|
279
|
+
this.processes = processes;
|
|
280
|
+
|
|
281
|
+
if (processes.length != this.list.items.length) {
|
|
282
|
+
this.list.clearItems();
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Total of processes memory
|
|
286
|
+
var mem = 0;
|
|
287
|
+
processes.forEach(function(proc) {
|
|
288
|
+
mem += proc.monit.memory;
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
// Sort process list
|
|
292
|
+
processes.sort(function(a, b) {
|
|
293
|
+
if (a.pm2_env.name < b.pm2_env.name)
|
|
294
|
+
return -1;
|
|
295
|
+
if (a.pm2_env.name > b.pm2_env.name)
|
|
296
|
+
return 1;
|
|
297
|
+
return 0;
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// Loop to get process infos
|
|
301
|
+
for (var i = 0; i < processes.length; i++) {
|
|
302
|
+
// Percent of memory use by one process in all pm2 processes
|
|
303
|
+
var memPercent = (processes[i].monit.memory / mem) * 100;
|
|
304
|
+
|
|
305
|
+
// Status of process
|
|
306
|
+
var status = processes[i].pm2_env.status == 'online' ? '{green-fg}' : '{red-fg}';
|
|
307
|
+
status = status + '{bold}' + processes[i].pm2_env.status + '{/}';
|
|
308
|
+
|
|
309
|
+
var name = processes[i].pm2_env.name || p.basename(processes[i].pm2_env.pm_exec_path);
|
|
310
|
+
var maxNameLen = 15;
|
|
311
|
+
if (name.length > maxNameLen) name = name.substring(0, maxNameLen - 1) + '…';
|
|
312
|
+
name = name.padEnd(maxNameLen);
|
|
313
|
+
|
|
314
|
+
// Line of list
|
|
315
|
+
var memMB = (processes[i].monit.memory / 1048576).toFixed(0);
|
|
316
|
+
var cpu = processes[i].monit.cpu;
|
|
317
|
+
var memColor = gradient(memPercent, [255, 0, 0], [0, 255, 0]);
|
|
318
|
+
var cpuColor = gradient(cpu, [255, 0, 0], [0, 255, 0]);
|
|
319
|
+
var item = `[${String(processes[i].pm2_env.pm_id).padStart(2)}] ${name} Mem: {bold}{${memColor}-fg}${String(memMB).padStart(3)}{/} MB CPU: {bold}{${cpuColor}-fg}${String(cpu).padStart(2)}{/} % ${status}`;
|
|
320
|
+
|
|
321
|
+
// Check if item exist
|
|
322
|
+
if (this.list.getItem(i)) {
|
|
323
|
+
this.list.setItem(i, item);
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
this.list.pushItem(item);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
var proc = processes[this.list.selected];
|
|
330
|
+
// render the logBox
|
|
331
|
+
let process_id = proc.pm_id
|
|
332
|
+
let logs = this.displayLines(process_id);
|
|
333
|
+
if(logs !== null){
|
|
334
|
+
// blessed's setItems restores the selection by *content*, which
|
|
335
|
+
// jumps to the first duplicate line: keep the numeric index instead
|
|
336
|
+
var selected = this.logBox.selected;
|
|
337
|
+
this.logBox.setItems(logs)
|
|
338
|
+
if (!this.logBox.focused) {
|
|
339
|
+
// newest line first: stay pinned to the top until focused
|
|
340
|
+
this.logBox.select(0);
|
|
341
|
+
this.logBox.setScrollPerc(0);
|
|
342
|
+
} else {
|
|
343
|
+
this.logBox.select(Math.min(selected, logs.length - 1));
|
|
344
|
+
}
|
|
345
|
+
}else{
|
|
346
|
+
this.logBox.clearItems();
|
|
347
|
+
}
|
|
348
|
+
this.logBox.setLabel(` ${proc.pm2_env.name} Logs `)
|
|
349
|
+
|
|
350
|
+
this.metadataBox.setLine(0, 'App Name ' + '{bold}' + proc.pm2_env.name + '{/}');
|
|
351
|
+
this.metadataBox.setLine(1, 'Namespace ' + '{bold}' + proc.pm2_env.namespace + '{/}');
|
|
352
|
+
this.metadataBox.setLine(2, 'Version ' + '{bold}' + proc.pm2_env.version + '{/}');
|
|
353
|
+
this.metadataBox.setLine(3, 'Restarts ' + proc.pm2_env.restart_time);
|
|
354
|
+
this.metadataBox.setLine(4, 'Uptime ' + ((proc.pm2_env.pm_uptime && proc.pm2_env.status == 'online') ? timeSince(proc.pm2_env.pm_uptime) : 0));
|
|
355
|
+
this.metadataBox.setLine(5, 'Script path ' + proc.pm2_env.pm_exec_path);
|
|
356
|
+
this.metadataBox.setLine(6, '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'));
|
|
357
|
+
this.metadataBox.setLine(7, 'Interpreter ' + proc.pm2_env.exec_interpreter);
|
|
358
|
+
this.metadataBox.setLine(8, 'Interpreter args ' + (proc.pm2_env.node_args.length != 0 ? proc.pm2_env.node_args : 'N/A'));
|
|
359
|
+
this.metadataBox.setLine(9, 'Exec mode ' + (proc.pm2_env.exec_mode == 'fork_mode' ? '{bold}fork{/}' : '{blue-fg}{bold}cluster{/}'));
|
|
360
|
+
this.metadataBox.setLine(10, 'Node.js version ' + proc.pm2_env.node_version);
|
|
361
|
+
this.metadataBox.setLine(11, 'watch & reload ' + (proc.pm2_env.watch ? '{green-fg}{bold}✔{/}' : '{red-fg}{bold}✘{/}'));
|
|
362
|
+
this.metadataBox.setLine(12, 'Unstable restarts ' + proc.pm2_env.unstable_restarts);
|
|
363
|
+
|
|
364
|
+
this.metadataBox.setLine(13, 'Comment ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.comment : 'N/A'));
|
|
365
|
+
this.metadataBox.setLine(14, 'Revision ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.revision : 'N/A'));
|
|
366
|
+
this.metadataBox.setLine(15, 'Branch ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.branch : 'N/A'));
|
|
367
|
+
this.metadataBox.setLine(16, 'Remote url ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.url : 'N/A'));
|
|
368
|
+
this.metadataBox.deleteLine(17)
|
|
369
|
+
this.metadataBox.setLine(17, 'Last update ' + ((proc.pm2_env.versioning) ? proc.pm2_env.versioning.update_time : 'N/A'));
|
|
370
|
+
|
|
371
|
+
if (Object.keys(proc.pm2_env.axm_monitor).length != this.metricsBox.items.length) {
|
|
372
|
+
this.metricsBox.clearItems();
|
|
373
|
+
}
|
|
374
|
+
var j = 0;
|
|
375
|
+
// inner width minus the scrollbar column blessed keeps on the right,
|
|
376
|
+
// minus one so the line never reaches the wrap threshold
|
|
377
|
+
var metrics_width = this.metricsBox.width - this.metricsBox.iwidth - 2;
|
|
378
|
+
var metric_lines = Dashboard.formatMetrics(proc.pm2_env.axm_monitor, metrics_width);
|
|
379
|
+
for (var m = 0; m < metric_lines.length; m++) {
|
|
380
|
+
var probe = metric_lines[m];
|
|
381
|
+
|
|
382
|
+
if (this.metricsBox.getItem(j)) {
|
|
383
|
+
this.metricsBox.setItem(j, probe);
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
this.metricsBox.pushItem(probe);
|
|
387
|
+
}
|
|
388
|
+
j++;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
this.screen.render();
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return this;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Put Log
|
|
399
|
+
* @method log
|
|
400
|
+
* @param {} data
|
|
401
|
+
* @return this
|
|
402
|
+
*/
|
|
403
|
+
Dashboard.log = function(type, data) {
|
|
404
|
+
var lines = (data.data || '').split('\n');
|
|
405
|
+
|
|
406
|
+
lines.forEach((line) => {
|
|
407
|
+
this.pushLine(data.process.pm_id, data.process.name, type, line);
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
return this;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Render a metric value: numbers (or numeric strings) are rounded to two
|
|
415
|
+
* decimals, integers are left untouched, anything else is stringified
|
|
416
|
+
* @method formatMetricValue
|
|
417
|
+
* @param {*} value
|
|
418
|
+
* @return {String}
|
|
419
|
+
*/
|
|
420
|
+
Dashboard.formatMetricValue = function(value) {
|
|
421
|
+
if (typeof value === 'boolean' || value === '')
|
|
422
|
+
return String(value);
|
|
423
|
+
var n = typeof value === 'number' ? value : Number(value);
|
|
424
|
+
if (typeof value !== 'number' && (typeof value !== 'string' || value.trim() === '' || isNaN(n)))
|
|
425
|
+
return String(value);
|
|
426
|
+
if (!isFinite(n))
|
|
427
|
+
return String(value);
|
|
428
|
+
if (Number.isInteger(n))
|
|
429
|
+
return String(n);
|
|
430
|
+
return n.toFixed(2);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Format the custom metrics of a process as aligned columns:
|
|
435
|
+
* name on the left, value right-aligned, unit in a fixed-width column
|
|
436
|
+
* @method formatMetrics
|
|
437
|
+
* @param {Object} axm_monitor
|
|
438
|
+
* @return {Array<String>} one blessed-tagged line per metric
|
|
439
|
+
*/
|
|
440
|
+
Dashboard.formatMetrics = function(axm_monitor, width) {
|
|
441
|
+
var metrics = Object.keys(axm_monitor || {}).map(function(key) {
|
|
442
|
+
var m = axm_monitor[key];
|
|
443
|
+
var has_value = m !== null && typeof m === 'object' && m.hasOwnProperty('value');
|
|
444
|
+
var value = has_value ? m.value : m;
|
|
445
|
+
var unit = (m !== null && typeof m === 'object' && m.unit) ? String(m.unit) : '';
|
|
446
|
+
if (value === undefined || value === null || (typeof value === 'object'))
|
|
447
|
+
value = '';
|
|
448
|
+
return { key: key, value: Dashboard.formatMetricValue(value), unit: unit };
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
var value_width = metrics.reduce(function(w, m) { return Math.max(w, m.value.length); }, 0);
|
|
452
|
+
var unit_width = metrics.reduce(function(w, m) { return Math.max(w, m.unit.length); }, 0);
|
|
453
|
+
|
|
454
|
+
return metrics.map(function(m) {
|
|
455
|
+
var cols = m.value.padStart(value_width);
|
|
456
|
+
if (unit_width > 0)
|
|
457
|
+
cols += ' ' + m.unit.padEnd(unit_width);
|
|
458
|
+
var key = m.key;
|
|
459
|
+
if (!width)
|
|
460
|
+
return `{bold}${key}{/} {|} ${cols}`;
|
|
461
|
+
|
|
462
|
+
// Known pane width: pad by hand. blessed's `{|}` is measured before it
|
|
463
|
+
// is expanded (as 3 literal chars) and lines reaching the width are
|
|
464
|
+
// cut, which used to drop the unit column. Shorten the name rather
|
|
465
|
+
// than letting the value overflow.
|
|
466
|
+
var max_key = width - cols.length - 1;
|
|
467
|
+
if (key.length > max_key)
|
|
468
|
+
key = max_key > 1 ? key.substring(0, max_key - 1) + '…' : '';
|
|
469
|
+
var gap = ' '.repeat(Math.max(1, width - key.length - cols.length));
|
|
470
|
+
return `{bold}${key}{/}${gap}${cols}`;
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Lines of a process as displayed: most recent first
|
|
476
|
+
* @method displayLines
|
|
477
|
+
* @param {Number} pm_id
|
|
478
|
+
* @return {Array|null} null when the process has no line yet
|
|
479
|
+
*/
|
|
480
|
+
Dashboard.displayLines = function(pm_id) {
|
|
481
|
+
var buffer = this.logLines && this.logLines[pm_id];
|
|
482
|
+
if (typeof(buffer) === 'undefined')
|
|
483
|
+
return null;
|
|
484
|
+
return buffer.slice().reverse();
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Parse a --lines value: positive integer, DEFAULT_LOG_LINES otherwise
|
|
489
|
+
* @method parseLines
|
|
490
|
+
* @param {*} value
|
|
491
|
+
* @return {Number}
|
|
492
|
+
*/
|
|
493
|
+
Dashboard.parseLines = function(value) {
|
|
494
|
+
var n = parseInt(value, 10);
|
|
495
|
+
if (isNaN(n) || n <= 0)
|
|
496
|
+
return DEFAULT_LOG_LINES;
|
|
497
|
+
return Math.min(n, MAX_LOG_LINES);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Make a raw log line safe for a blessed pane (#5397): keep only what a
|
|
502
|
+
* terminal would leave on screen, and nothing blessed could misread.
|
|
503
|
+
* - \r: a terminal overwrites the line, keep the last segment
|
|
504
|
+
* (progress bars, spinners)
|
|
505
|
+
* - non-SGR escape sequences (cursor moves, erase line, OSC titles…)
|
|
506
|
+
* are removed; colors (SGR, \x1b[..m) are kept, blessed renders them
|
|
507
|
+
* - other control characters are dropped, tabs become spaces
|
|
508
|
+
* - { and } are escaped so they are not parsed as blessed tags
|
|
509
|
+
* @method sanitizeLine
|
|
510
|
+
* @param {String} line
|
|
511
|
+
* @return {String}
|
|
512
|
+
*/
|
|
513
|
+
Dashboard.sanitizeLine = function(line) {
|
|
514
|
+
line = String(line);
|
|
515
|
+
|
|
516
|
+
if (line.indexOf('\r') !== -1) {
|
|
517
|
+
var segments = line.replace(/\r+$/, '').split('\r');
|
|
518
|
+
line = segments[segments.length - 1];
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
line = line
|
|
522
|
+
// CSI sequences: keep SGR (final byte m), drop the others
|
|
523
|
+
.replace(/\x1b\[[0-9;?]*[ -\/]*[@-~]/g, function(seq) {
|
|
524
|
+
return seq[seq.length - 1] === 'm' ? seq : '';
|
|
525
|
+
})
|
|
526
|
+
// OSC (terminated by BEL or ST) and remaining 2-char escapes
|
|
527
|
+
.replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)?/g, '')
|
|
528
|
+
.replace(/\x1b[ -\/]*[0-Z\\-~]/g, '')
|
|
529
|
+
.replace(/\t/g, ' ')
|
|
530
|
+
.replace(/[\x00-\x08\x0b-\x1a\x1c-\x1f\x7f]/g, '');
|
|
531
|
+
|
|
532
|
+
return blessed.escape(line);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Append one formatted log line to a process buffer, bounded to maxLines
|
|
537
|
+
* @method pushLine
|
|
538
|
+
* @param {Number} pm_id
|
|
539
|
+
* @param {String} name process name
|
|
540
|
+
* @param {String} type PM2 | out | err
|
|
541
|
+
* @param {String} line
|
|
542
|
+
* @return this
|
|
543
|
+
*/
|
|
544
|
+
Dashboard.pushLine = function(pm_id, name, type, line) {
|
|
545
|
+
if (!line || line.length === 0)
|
|
546
|
+
return this;
|
|
547
|
+
|
|
548
|
+
if (typeof(this.logLines) === 'undefined')
|
|
549
|
+
this.logLines = {};
|
|
550
|
+
if (typeof(this.logLines[pm_id]) === 'undefined')
|
|
551
|
+
this.logLines[pm_id] = [];
|
|
552
|
+
|
|
553
|
+
line = Dashboard.sanitizeLine(line);
|
|
554
|
+
if (line.length === 0)
|
|
555
|
+
return this;
|
|
556
|
+
|
|
557
|
+
var buffer = this.logLines[pm_id];
|
|
558
|
+
var color = LOG_COLORS[type] || '{white-fg}';
|
|
559
|
+
var max = this.maxLines || DEFAULT_LOG_LINES;
|
|
560
|
+
|
|
561
|
+
buffer.push(color + name + '{/} > ' + line);
|
|
562
|
+
|
|
563
|
+
// bound the buffer per process: drop the oldest lines
|
|
564
|
+
if (buffer.length > max)
|
|
565
|
+
buffer.splice(0, buffer.length - max);
|
|
566
|
+
|
|
567
|
+
return this;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Preload the history of a process from its out/err log files
|
|
572
|
+
* (called before live log events start flowing)
|
|
573
|
+
* @method preload
|
|
574
|
+
* @param {Object} proc process object (pm_id, name)
|
|
575
|
+
* @param {Array} out_lines last lines of the out log file
|
|
576
|
+
* @param {Array} err_lines last lines of the err log file
|
|
577
|
+
* @return this
|
|
578
|
+
*/
|
|
579
|
+
Dashboard.preload = function(proc, out_lines, err_lines) {
|
|
580
|
+
var merged = Dashboard.mergeLogLines(out_lines || [], err_lines || []);
|
|
581
|
+
|
|
582
|
+
merged.forEach((entry) => {
|
|
583
|
+
this.pushLine(proc.pm_id, proc.name, entry.type, entry.line);
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
return this;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Merge out and err lines into one chronological stream.
|
|
591
|
+
* Lines are interleaved by their leading timestamp when both streams
|
|
592
|
+
* carry one (log_date_format / --time); otherwise out lines come first,
|
|
593
|
+
* then err lines. Order within a stream is always preserved (stable).
|
|
594
|
+
* @method mergeLogLines
|
|
595
|
+
* @param {Array} out_lines
|
|
596
|
+
* @param {Array} err_lines
|
|
597
|
+
* @return {Array} [{ type: 'out'|'err', line: String }]
|
|
598
|
+
*/
|
|
599
|
+
Dashboard.mergeLogLines = function(out_lines, err_lines) {
|
|
600
|
+
// Parse a leading timestamp: "2026-08-28T10:00:00: msg",
|
|
601
|
+
// "2026-08-28 10:00:00 +02:00: msg" (pm2 default log_date_format)
|
|
602
|
+
var stamp = function(line) {
|
|
603
|
+
var m = /^(\d{4}[-/]\d{1,2}[-/]\d{1,2}[T ]\d{1,2}:\d{2}(?::\d{2})?(?:\.\d+)?(?: ?[+-]\d{2}:?\d{2}| ?Z)?)/.exec(line);
|
|
604
|
+
if (!m) return NaN;
|
|
605
|
+
return Date.parse(m[1].replace(' ', 'T').replace(/ (?=[+-]\d|Z)/, ''));
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
// Stamp each line; continuation lines (stack traces, multi-line JSON)
|
|
609
|
+
// inherit the stamp of the previous line of their stream
|
|
610
|
+
var tag = function(lines, type) {
|
|
611
|
+
var last = NaN;
|
|
612
|
+
var stamped = 0;
|
|
613
|
+
var entries = lines.map(function(line) {
|
|
614
|
+
var ts = stamp(line);
|
|
615
|
+
if (!isNaN(ts)) { last = ts; stamped++; }
|
|
616
|
+
return { type: type, line: line, ts: last };
|
|
617
|
+
});
|
|
618
|
+
entries.stamped = stamped;
|
|
619
|
+
return entries;
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
var out = tag(out_lines, 'out');
|
|
623
|
+
var err = tag(err_lines, 'err');
|
|
624
|
+
|
|
625
|
+
var strip = function(e) { return { type: e.type, line: e.line }; };
|
|
626
|
+
|
|
627
|
+
// no interleaving possible without timestamps on both sides
|
|
628
|
+
if (out.length === 0 || err.length === 0 || out.stamped === 0 || err.stamped === 0)
|
|
629
|
+
return out.concat(err).map(strip);
|
|
630
|
+
|
|
631
|
+
// two-pointer merge, stable within each stream; leading lines without
|
|
632
|
+
// any stamp yet (NaN) are emitted first
|
|
633
|
+
var result = [];
|
|
634
|
+
var i = 0, j = 0;
|
|
635
|
+
while (i < out.length && j < err.length) {
|
|
636
|
+
var a = out[i].ts, b = err[j].ts;
|
|
637
|
+
if (isNaN(a) || (!isNaN(b) && a <= b))
|
|
638
|
+
result.push(out[i++]);
|
|
639
|
+
else
|
|
640
|
+
result.push(err[j++]);
|
|
641
|
+
}
|
|
642
|
+
return result.concat(out.slice(i), err.slice(j)).map(strip);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Replay a live log event buffered during the history preload, skipping
|
|
647
|
+
* lines already loaded from the file (a line emitted during the preload
|
|
648
|
+
* window is both in the file and on the bus)
|
|
649
|
+
* @method replay
|
|
650
|
+
* @param {String} type
|
|
651
|
+
* @param {Object} data
|
|
652
|
+
* @return this
|
|
653
|
+
*/
|
|
654
|
+
Dashboard.replay = function(type, data) {
|
|
655
|
+
var pm_id = data.process.pm_id;
|
|
656
|
+
var name = data.process.name;
|
|
657
|
+
var buffer = (this.logLines && this.logLines[pm_id]) || [];
|
|
658
|
+
var color = LOG_COLORS[type] || '{white-fg}';
|
|
659
|
+
// only the tail of the history can overlap with buffered live events
|
|
660
|
+
var tail = buffer.slice(-50);
|
|
661
|
+
|
|
662
|
+
(data.data || '').split('\n').forEach((line) => {
|
|
663
|
+
var clean = Dashboard.sanitizeLine(line);
|
|
664
|
+
if (clean.length === 0) return;
|
|
665
|
+
var formatted = color + name + '{/} > ' + clean;
|
|
666
|
+
var idx = tail.indexOf(formatted);
|
|
667
|
+
if (idx !== -1) {
|
|
668
|
+
// consume the match so a legitimately repeated line is not dropped
|
|
669
|
+
tail.splice(0, idx + 1);
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
this.pushLine(pm_id, name, type, line);
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
return this;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
module.exports = Dashboard;
|
|
679
|
+
|
|
680
|
+
function timeSince(date) {
|
|
681
|
+
|
|
682
|
+
var seconds = Math.floor((new Date() - date) / 1000);
|
|
683
|
+
|
|
684
|
+
var interval = Math.floor(seconds / 31536000);
|
|
685
|
+
|
|
686
|
+
if (interval > 1) {
|
|
687
|
+
return interval + 'Y';
|
|
688
|
+
}
|
|
689
|
+
interval = Math.floor(seconds / 2592000);
|
|
690
|
+
if (interval > 1) {
|
|
691
|
+
return interval + 'M';
|
|
692
|
+
}
|
|
693
|
+
interval = Math.floor(seconds / 86400);
|
|
694
|
+
if (interval > 1) {
|
|
695
|
+
return interval + 'D';
|
|
696
|
+
}
|
|
697
|
+
interval = Math.floor(seconds / 3600);
|
|
698
|
+
if (interval > 1) {
|
|
699
|
+
return interval + 'h';
|
|
700
|
+
}
|
|
701
|
+
interval = Math.floor(seconds / 60);
|
|
702
|
+
if (interval > 1) {
|
|
703
|
+
return interval + 'm';
|
|
704
|
+
}
|
|
705
|
+
return Math.floor(seconds) + 's';
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/* Args :
|
|
709
|
+
* p : Percent 0 - 100
|
|
710
|
+
* rgb_ : Array of rgb [255, 255, 255]
|
|
711
|
+
* Return :
|
|
712
|
+
* Hexa #FFFFFF
|
|
713
|
+
*/
|
|
714
|
+
function gradient(p, rgb_beginning, rgb_end) {
|
|
715
|
+
|
|
716
|
+
var w = (p / 100) * 2 - 1;
|
|
717
|
+
|
|
718
|
+
var w1 = (w + 1) / 2.0;
|
|
719
|
+
var w2 = 1 - w1;
|
|
720
|
+
|
|
721
|
+
var rgb = [parseInt(rgb_beginning[0] * w1 + rgb_end[0] * w2),
|
|
722
|
+
parseInt(rgb_beginning[1] * w1 + rgb_end[1] * w2),
|
|
723
|
+
parseInt(rgb_beginning[2] * w1 + rgb_end[2] * w2)];
|
|
724
|
+
|
|
725
|
+
return "#" + ((1 << 24) + (rgb[0] << 16) + (rgb[1] << 8) + rgb[2]).toString(16).slice(1);
|
|
726
|
+
}
|