@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,238 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const Configuration = require('../configuration')
|
|
4
|
+
const { ServiceManager } = require('../serviceManager')
|
|
5
|
+
const Debug = require('debug')
|
|
6
|
+
const { Cache, StackTraceParser } = require('../utils/stackParser')
|
|
7
|
+
const fs = require('fs')
|
|
8
|
+
const path = require('path')
|
|
9
|
+
|
|
10
|
+
const optionsDefault = {
|
|
11
|
+
catchExceptions: true
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
class NotifyFeature {
|
|
15
|
+
constructor () {
|
|
16
|
+
this.logger = Debug('axm:features:notify')
|
|
17
|
+
this.transport = undefined
|
|
18
|
+
this.cache = null
|
|
19
|
+
this.stackParser = null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
init (options) {
|
|
23
|
+
if (options === undefined) {
|
|
24
|
+
options = optionsDefault
|
|
25
|
+
}
|
|
26
|
+
this.logger('init')
|
|
27
|
+
this.transport = ServiceManager.get('transport')
|
|
28
|
+
if (this.transport === undefined) {
|
|
29
|
+
return this.logger('Failed to load transporter service')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Configuration.configureModule({
|
|
33
|
+
error: true
|
|
34
|
+
})
|
|
35
|
+
if (options.catchExceptions === false) return
|
|
36
|
+
this.logger('Registering hook to catch unhandled exception/rejection')
|
|
37
|
+
this.cache = new Cache({
|
|
38
|
+
miss: (key) => {
|
|
39
|
+
try {
|
|
40
|
+
const content = fs.readFileSync(path.resolve(key))
|
|
41
|
+
return content.toString().split(/\r?\n/)
|
|
42
|
+
} catch (err) {
|
|
43
|
+
this.logger('Error while trying to get file from FS : %s', err.message || err)
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
ttl: 30 * 60
|
|
48
|
+
})
|
|
49
|
+
this.stackParser = new StackTraceParser({
|
|
50
|
+
cache: this.cache,
|
|
51
|
+
contextSize: 5
|
|
52
|
+
})
|
|
53
|
+
this.catchAll()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
destroy () {
|
|
57
|
+
if (this._onUncaughtException) {
|
|
58
|
+
process.removeListener('uncaughtException', this._onUncaughtException)
|
|
59
|
+
}
|
|
60
|
+
if (this._onUnhandledRejection) {
|
|
61
|
+
process.removeListener('unhandledRejection', this._onUnhandledRejection)
|
|
62
|
+
}
|
|
63
|
+
this.logger('destroy')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getSafeError (err) {
|
|
67
|
+
if (err instanceof Error) return err
|
|
68
|
+
|
|
69
|
+
let message
|
|
70
|
+
try {
|
|
71
|
+
message = `Non-error value: ${JSON.stringify(err)}`
|
|
72
|
+
} catch (e) {
|
|
73
|
+
try {
|
|
74
|
+
message = `Unserializable non-error value: ${String(e)}`
|
|
75
|
+
} catch (e2) {
|
|
76
|
+
message = 'Unserializable non-error value that cannot be converted to a string'
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (message.length > 1000) message = message.substr(0, 1000) + '...'
|
|
80
|
+
|
|
81
|
+
return new Error(message)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
notifyError (err, context) {
|
|
85
|
+
if (typeof context !== 'object') {
|
|
86
|
+
context = {}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (this.transport === undefined) {
|
|
90
|
+
return this.logger('Tried to send error without having transporter available')
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const safeError = this.getSafeError(err)
|
|
94
|
+
let stackContext = null
|
|
95
|
+
if (err instanceof Error) {
|
|
96
|
+
stackContext = this.stackParser.retrieveContext(err)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const payload = Object.assign({
|
|
100
|
+
message: safeError.message,
|
|
101
|
+
stack: safeError.stack,
|
|
102
|
+
name: safeError.name,
|
|
103
|
+
metadata: context
|
|
104
|
+
}, stackContext === null ? {} : stackContext)
|
|
105
|
+
|
|
106
|
+
return this.transport.send('process:exception', payload)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
onUncaughtException (error) {
|
|
110
|
+
// Node 18+ always supports console.error(error) directly
|
|
111
|
+
console.error(error)
|
|
112
|
+
|
|
113
|
+
const safeError = this.getSafeError(error)
|
|
114
|
+
let stackContext = null
|
|
115
|
+
if (error instanceof Error) {
|
|
116
|
+
stackContext = this.stackParser.retrieveContext(error)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const payload = Object.assign({
|
|
120
|
+
message: safeError.message,
|
|
121
|
+
stack: safeError.stack,
|
|
122
|
+
name: safeError.name
|
|
123
|
+
}, stackContext === null ? {} : stackContext)
|
|
124
|
+
|
|
125
|
+
if (ServiceManager.get('transport')) {
|
|
126
|
+
ServiceManager.get('transport').send('process:exception', payload)
|
|
127
|
+
}
|
|
128
|
+
if (process.listeners('uncaughtException').length === 1) {
|
|
129
|
+
process.exit(1)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
onUnhandledRejection (error) {
|
|
134
|
+
if (error === undefined) return
|
|
135
|
+
|
|
136
|
+
console.error(error)
|
|
137
|
+
|
|
138
|
+
const safeError = this.getSafeError(error)
|
|
139
|
+
let stackContext = null
|
|
140
|
+
if (error instanceof Error) {
|
|
141
|
+
stackContext = this.stackParser.retrieveContext(error)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const payload = Object.assign({
|
|
145
|
+
message: safeError.message,
|
|
146
|
+
stack: safeError.stack,
|
|
147
|
+
name: safeError.name
|
|
148
|
+
}, stackContext === null ? {} : stackContext)
|
|
149
|
+
|
|
150
|
+
if (ServiceManager.get('transport')) {
|
|
151
|
+
ServiceManager.get('transport').send('process:exception', payload)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
catchAll () {
|
|
156
|
+
if (process.env.exec_mode === 'cluster_mode') {
|
|
157
|
+
return false
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
this._onUncaughtException = this.onUncaughtException.bind(this)
|
|
161
|
+
this._onUnhandledRejection = this.onUnhandledRejection.bind(this)
|
|
162
|
+
process.on('uncaughtException', this._onUncaughtException)
|
|
163
|
+
process.on('unhandledRejection', this._onUnhandledRejection)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
expressErrorHandler () {
|
|
167
|
+
const self = this
|
|
168
|
+
Configuration.configureModule({
|
|
169
|
+
error: true
|
|
170
|
+
})
|
|
171
|
+
return function errorHandler (err, req, res, next) {
|
|
172
|
+
const safeError = self.getSafeError(err)
|
|
173
|
+
const payload = {
|
|
174
|
+
message: safeError.message,
|
|
175
|
+
stack: safeError.stack,
|
|
176
|
+
name: safeError.name,
|
|
177
|
+
metadata: {
|
|
178
|
+
http: {
|
|
179
|
+
url: req.url,
|
|
180
|
+
params: req.params,
|
|
181
|
+
method: req.method,
|
|
182
|
+
query: req.query,
|
|
183
|
+
body: req.body,
|
|
184
|
+
path: req.path,
|
|
185
|
+
route: req.route && req.route.path ? req.route.path : undefined
|
|
186
|
+
},
|
|
187
|
+
custom: {
|
|
188
|
+
user: typeof req.user === 'object' ? req.user.id : undefined
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (ServiceManager.get('transport')) {
|
|
194
|
+
ServiceManager.get('transport').send('process:exception', payload)
|
|
195
|
+
}
|
|
196
|
+
return next(err)
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
koaErrorHandler () {
|
|
201
|
+
const self = this
|
|
202
|
+
Configuration.configureModule({
|
|
203
|
+
error: true
|
|
204
|
+
})
|
|
205
|
+
return async function (ctx, next) {
|
|
206
|
+
try {
|
|
207
|
+
await next()
|
|
208
|
+
} catch (err) {
|
|
209
|
+
const safeError = self.getSafeError(err)
|
|
210
|
+
const payload = {
|
|
211
|
+
message: safeError.message,
|
|
212
|
+
stack: safeError.stack,
|
|
213
|
+
name: safeError.name,
|
|
214
|
+
metadata: {
|
|
215
|
+
http: {
|
|
216
|
+
url: ctx.request.url,
|
|
217
|
+
params: ctx.params,
|
|
218
|
+
method: ctx.request.method,
|
|
219
|
+
query: ctx.request.query,
|
|
220
|
+
body: ctx.request.body,
|
|
221
|
+
path: ctx.request.path,
|
|
222
|
+
route: ctx._matchedRoute
|
|
223
|
+
},
|
|
224
|
+
custom: {
|
|
225
|
+
user: typeof ctx.user === 'object' ? ctx.user.id : undefined
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (ServiceManager.get('transport')) {
|
|
230
|
+
ServiceManager.get('transport').send('process:exception', payload)
|
|
231
|
+
}
|
|
232
|
+
throw err
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
module.exports = { NotifyFeature }
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const AddonProfiler = require('../profilers/addonProfiler')
|
|
4
|
+
const InspectorProfiler = require('../profilers/inspectorProfiler')
|
|
5
|
+
const { canUseInspector } = require('../constants')
|
|
6
|
+
const Debug = require('debug')
|
|
7
|
+
|
|
8
|
+
const defaultProfilingConfig = {
|
|
9
|
+
cpuJS: true,
|
|
10
|
+
heapSnapshot: true,
|
|
11
|
+
heapSampling: true,
|
|
12
|
+
implementation: 'both'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const disabledProfilingConfig = {
|
|
16
|
+
cpuJS: false,
|
|
17
|
+
heapSnapshot: false,
|
|
18
|
+
heapSampling: false,
|
|
19
|
+
implementation: 'none'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
class ProfilingFeature {
|
|
23
|
+
constructor () {
|
|
24
|
+
this.profiler = undefined
|
|
25
|
+
this.logger = Debug('axm:features:profiling')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
init (config) {
|
|
29
|
+
if (config === true) {
|
|
30
|
+
config = defaultProfilingConfig
|
|
31
|
+
} else if (config === false) {
|
|
32
|
+
config = disabledProfilingConfig
|
|
33
|
+
} else if (config === undefined) {
|
|
34
|
+
config = defaultProfilingConfig
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (process.env.PM2_PROFILING_FORCE_FALLBACK === 'true') {
|
|
38
|
+
config.implementation = 'addon'
|
|
39
|
+
}
|
|
40
|
+
if (config.implementation === undefined || config.implementation === 'both') {
|
|
41
|
+
config.implementation = canUseInspector() === true ? 'inspector' : 'addon'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
switch (config.implementation) {
|
|
45
|
+
case 'inspector': {
|
|
46
|
+
this.logger('using inspector implementation')
|
|
47
|
+
this.profiler = new InspectorProfiler()
|
|
48
|
+
break
|
|
49
|
+
}
|
|
50
|
+
case 'addon': {
|
|
51
|
+
this.logger('using addon implementation')
|
|
52
|
+
this.profiler = new AddonProfiler()
|
|
53
|
+
break
|
|
54
|
+
}
|
|
55
|
+
default: {
|
|
56
|
+
return this.logger(`Invalid profiler implementation choosen: ${config.implementation}`)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
this.logger('init')
|
|
60
|
+
this.profiler.init()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
destroy () {
|
|
64
|
+
this.logger('destroy')
|
|
65
|
+
if (this.profiler === undefined) return
|
|
66
|
+
this.profiler.destroy()
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = { ProfilingFeature }
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const Debug = require('debug')
|
|
4
|
+
const Configuration = require('../configuration')
|
|
5
|
+
|
|
6
|
+
const httpMethodToIgnore = [
|
|
7
|
+
'options',
|
|
8
|
+
'head'
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
const defaultTracingConfig = {
|
|
12
|
+
enabled: true,
|
|
13
|
+
outbound: false,
|
|
14
|
+
samplingRate: 0,
|
|
15
|
+
ignoreIncomingPaths: [],
|
|
16
|
+
ignoreOutgoingUrls: [],
|
|
17
|
+
createSpanWithNet: false
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const enabledTracingConfig = {
|
|
21
|
+
enabled: true,
|
|
22
|
+
outbound: true,
|
|
23
|
+
samplingRate: 0.5,
|
|
24
|
+
ignoreIncomingPaths: [
|
|
25
|
+
(_url, request) => {
|
|
26
|
+
const method = (request.method || 'GET').toLowerCase()
|
|
27
|
+
return httpMethodToIgnore.indexOf(method) > -1
|
|
28
|
+
},
|
|
29
|
+
/(.*).js/,
|
|
30
|
+
/(.*).css/,
|
|
31
|
+
/(.*).png/,
|
|
32
|
+
/(.*).ico/,
|
|
33
|
+
/(.*).svg/,
|
|
34
|
+
/webpack/
|
|
35
|
+
],
|
|
36
|
+
ignoreOutgoingUrls: [],
|
|
37
|
+
createSpanWithNet: false
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class TracingFeature {
|
|
41
|
+
constructor () {
|
|
42
|
+
this.options = null
|
|
43
|
+
this.logger = Debug('axm:tracing')
|
|
44
|
+
this.otel = undefined
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
init (config) {
|
|
48
|
+
this.logger('init tracing', config)
|
|
49
|
+
|
|
50
|
+
if (config.tracing === undefined) {
|
|
51
|
+
config.tracing = defaultTracingConfig
|
|
52
|
+
} else if (config.tracing === true) {
|
|
53
|
+
config.tracing = enabledTracingConfig
|
|
54
|
+
} else if (config.tracing === false) {
|
|
55
|
+
config.tracing = defaultTracingConfig
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (config.tracing.enabled === false) {
|
|
59
|
+
this.logger('tracing disabled')
|
|
60
|
+
return
|
|
61
|
+
} else {
|
|
62
|
+
this.logger('tracing enabled')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
this.options = enabledTracingConfig
|
|
66
|
+
|
|
67
|
+
if (typeof config.apmOptions === 'object' && typeof config.apmOptions.appName === 'string') {
|
|
68
|
+
this.options.serviceName = config.apmOptions.appName
|
|
69
|
+
} else if (typeof process.env.name === 'string') {
|
|
70
|
+
this.options.serviceName = process.env.name
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (config.tracing.ignoreOutgoingUrls === undefined) {
|
|
74
|
+
config.tracing.ignoreOutgoingUrls = enabledTracingConfig.ignoreOutgoingUrls
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (config.tracing.ignoreIncomingPaths === undefined) {
|
|
78
|
+
config.tracing.ignoreIncomingPaths = enabledTracingConfig.ignoreIncomingPaths
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let NodeSDK, getNodeAutoInstrumentations, CustomZipkinExporter
|
|
82
|
+
try {
|
|
83
|
+
NodeSDK = require('@opentelemetry/sdk-node').NodeSDK
|
|
84
|
+
getNodeAutoInstrumentations = require('@opentelemetry/auto-instrumentations-node').getNodeAutoInstrumentations
|
|
85
|
+
CustomZipkinExporter = require('../otel/custom-zipkin-exporter/zipkin').CustomZipkinExporter
|
|
86
|
+
} catch(e) {
|
|
87
|
+
console.error('[PM2][ERROR] OpenTelemetry packages not installed. Tracing disabled.')
|
|
88
|
+
console.error('[PM2][ERROR] To enable tracing, run: pm2 install-otel')
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const traceExporter = new CustomZipkinExporter()
|
|
93
|
+
|
|
94
|
+
const serviceName =
|
|
95
|
+
process.env.OTEL_SERVICE_NAME ||
|
|
96
|
+
this.options.serviceName
|
|
97
|
+
|
|
98
|
+
this.otel = new NodeSDK({
|
|
99
|
+
traceExporter,
|
|
100
|
+
serviceName,
|
|
101
|
+
instrumentations: [
|
|
102
|
+
getNodeAutoInstrumentations({
|
|
103
|
+
'@opentelemetry/instrumentation-dns': {
|
|
104
|
+
enabled: false
|
|
105
|
+
},
|
|
106
|
+
'@opentelemetry/instrumentation-fs': {
|
|
107
|
+
enabled: false
|
|
108
|
+
},
|
|
109
|
+
'@opentelemetry/instrumentation-net': {
|
|
110
|
+
enabled: this.options.createSpanWithNet
|
|
111
|
+
},
|
|
112
|
+
'@opentelemetry/instrumentation-http': {
|
|
113
|
+
ignoreIncomingRequestHook: (request) => {
|
|
114
|
+
if (!this.options.ignoreIncomingPaths) {
|
|
115
|
+
return false
|
|
116
|
+
}
|
|
117
|
+
return this.options.ignoreIncomingPaths.some((matcher) => applyMatcher(matcher, request))
|
|
118
|
+
},
|
|
119
|
+
ignoreOutgoingRequestHook: (request) => {
|
|
120
|
+
if (!this.options.ignoreOutgoingUrls) {
|
|
121
|
+
return false
|
|
122
|
+
}
|
|
123
|
+
return this.options.ignoreOutgoingUrls.some((matcher) => applyMatcher(matcher, request))
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
]
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
this.otel.start()
|
|
131
|
+
|
|
132
|
+
Configuration.configureModule({
|
|
133
|
+
otel_tracing: true
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
getTracer () {
|
|
138
|
+
if (!this.options.serviceName) {
|
|
139
|
+
throw new Error('serviceName is required')
|
|
140
|
+
}
|
|
141
|
+
const { trace } = require('@opentelemetry/api')
|
|
142
|
+
return trace.getTracer(this.options.serviceName)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
destroy () {
|
|
146
|
+
if (!this.otel) return
|
|
147
|
+
this.logger('stop otel tracer')
|
|
148
|
+
this.otel.shutdown()
|
|
149
|
+
|
|
150
|
+
Configuration.configureModule({
|
|
151
|
+
otel_tracing: false
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function applyMatcher (matcher, request) {
|
|
157
|
+
if (!matcher) {
|
|
158
|
+
return false
|
|
159
|
+
}
|
|
160
|
+
if (!request.url) {
|
|
161
|
+
return false
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (typeof matcher === 'string') {
|
|
165
|
+
return request.url.includes(matcher)
|
|
166
|
+
}
|
|
167
|
+
if (matcher instanceof RegExp) {
|
|
168
|
+
return matcher.test(request.url)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return matcher(request.url, request)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
module.exports = { TracingFeature }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const PMX = require('./pmx')
|
|
4
|
+
|
|
5
|
+
const IO_KEY = Symbol.for('@pm2/io')
|
|
6
|
+
const isAlreadyHere = (Object.getOwnPropertySymbols(global).indexOf(IO_KEY) > -1)
|
|
7
|
+
|
|
8
|
+
const io = isAlreadyHere ? global[IO_KEY] : new PMX().init()
|
|
9
|
+
global[IO_KEY] = io
|
|
10
|
+
|
|
11
|
+
module.exports = io
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { MetricType } = require('../services/metrics')
|
|
4
|
+
const { ServiceManager } = require('../serviceManager')
|
|
5
|
+
const Debug = require('debug')
|
|
6
|
+
const Histogram = require('../utils/metrics/histogram')
|
|
7
|
+
|
|
8
|
+
const defaultOptions = {
|
|
9
|
+
eventLoopActive: true,
|
|
10
|
+
eventLoopDelay: true
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
class EventLoopHandlesRequestsMetric {
|
|
14
|
+
constructor () {
|
|
15
|
+
this.metricService = undefined
|
|
16
|
+
this.logger = Debug('axm:features:metrics:eventloop')
|
|
17
|
+
this.requestTimer = undefined
|
|
18
|
+
this.handleTimer = undefined
|
|
19
|
+
this.delayTimer = undefined
|
|
20
|
+
this.delayLoopInterval = 1000
|
|
21
|
+
this.runtimeStatsService = undefined
|
|
22
|
+
this.handle = undefined
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
init (config) {
|
|
26
|
+
if (config === false) return
|
|
27
|
+
if (config === undefined) {
|
|
28
|
+
config = defaultOptions
|
|
29
|
+
}
|
|
30
|
+
if (config === true) {
|
|
31
|
+
config = defaultOptions
|
|
32
|
+
}
|
|
33
|
+
this.metricService = ServiceManager.get('metrics')
|
|
34
|
+
if (this.metricService === undefined) return this.logger('Failed to load metric service')
|
|
35
|
+
|
|
36
|
+
this.logger('init')
|
|
37
|
+
if (typeof process._getActiveRequests === 'function' && config.eventLoopActive === true) {
|
|
38
|
+
const requestMetric = this.metricService.metric({
|
|
39
|
+
name: 'Active requests',
|
|
40
|
+
id: 'internal/libuv/requests',
|
|
41
|
+
historic: true
|
|
42
|
+
})
|
|
43
|
+
this.requestTimer = setInterval(_ => {
|
|
44
|
+
requestMetric.set(process._getActiveRequests().length)
|
|
45
|
+
}, 1000)
|
|
46
|
+
this.requestTimer.unref()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (typeof process._getActiveHandles === 'function' && config.eventLoopActive === true) {
|
|
50
|
+
const handleMetric = this.metricService.metric({
|
|
51
|
+
name: 'Active handles',
|
|
52
|
+
id: 'internal/libuv/handles',
|
|
53
|
+
historic: true
|
|
54
|
+
})
|
|
55
|
+
this.handleTimer = setInterval(_ => {
|
|
56
|
+
handleMetric.set(process._getActiveHandles().length)
|
|
57
|
+
}, 1000)
|
|
58
|
+
this.handleTimer.unref()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (config.eventLoopDelay === false) return
|
|
62
|
+
|
|
63
|
+
const histogram = new Histogram()
|
|
64
|
+
|
|
65
|
+
const uvLatencyp50 = {
|
|
66
|
+
name: 'Event Loop Latency',
|
|
67
|
+
id: 'internal/libuv/latency/p50',
|
|
68
|
+
type: MetricType.histogram,
|
|
69
|
+
historic: true,
|
|
70
|
+
implementation: histogram,
|
|
71
|
+
handler: function () {
|
|
72
|
+
const percentiles = this.implementation.percentiles([ 0.5 ])
|
|
73
|
+
if (percentiles[0.5] == null) return null
|
|
74
|
+
return percentiles[0.5].toFixed(2)
|
|
75
|
+
},
|
|
76
|
+
unit: 'ms'
|
|
77
|
+
}
|
|
78
|
+
const uvLatencyp95 = {
|
|
79
|
+
name: 'Event Loop Latency p95',
|
|
80
|
+
id: 'internal/libuv/latency/p95',
|
|
81
|
+
type: MetricType.histogram,
|
|
82
|
+
historic: true,
|
|
83
|
+
implementation: histogram,
|
|
84
|
+
handler: function () {
|
|
85
|
+
const percentiles = this.implementation.percentiles([ 0.95 ])
|
|
86
|
+
if (percentiles[0.95] == null) return null
|
|
87
|
+
return percentiles[0.95].toFixed(2)
|
|
88
|
+
},
|
|
89
|
+
unit: 'ms'
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
this.metricService.registerMetric(uvLatencyp50)
|
|
93
|
+
this.metricService.registerMetric(uvLatencyp95)
|
|
94
|
+
|
|
95
|
+
this.runtimeStatsService = ServiceManager.get('runtimeStats')
|
|
96
|
+
if (this.runtimeStatsService === undefined) {
|
|
97
|
+
this.logger('runtimeStats module not found, fallbacking into pure js method')
|
|
98
|
+
let oldTime = process.hrtime()
|
|
99
|
+
this.delayTimer = setInterval(() => {
|
|
100
|
+
const newTime = process.hrtime()
|
|
101
|
+
const delay = (newTime[0] - oldTime[0]) * 1e3 + (newTime[1] - oldTime[1]) / 1e6 - this.delayLoopInterval
|
|
102
|
+
oldTime = newTime
|
|
103
|
+
histogram.update(delay)
|
|
104
|
+
}, this.delayLoopInterval)
|
|
105
|
+
|
|
106
|
+
this.delayTimer.unref()
|
|
107
|
+
} else {
|
|
108
|
+
this.logger('using runtimeStats module as data source for event loop latency')
|
|
109
|
+
this.handle = (stats) => {
|
|
110
|
+
if (typeof stats !== 'object' || !Array.isArray(stats.ticks)) return
|
|
111
|
+
stats.ticks.forEach((tick) => {
|
|
112
|
+
histogram.update(tick)
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
this.runtimeStatsService.on('data', this.handle)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
destroy () {
|
|
120
|
+
if (this.requestTimer !== undefined) {
|
|
121
|
+
clearInterval(this.requestTimer)
|
|
122
|
+
}
|
|
123
|
+
if (this.handleTimer !== undefined) {
|
|
124
|
+
clearInterval(this.handleTimer)
|
|
125
|
+
}
|
|
126
|
+
if (this.delayTimer !== undefined) {
|
|
127
|
+
clearInterval(this.delayTimer)
|
|
128
|
+
}
|
|
129
|
+
if (this.runtimeStatsService !== undefined) {
|
|
130
|
+
this.runtimeStatsService.removeListener('data', this.handle)
|
|
131
|
+
}
|
|
132
|
+
this.logger('destroy')
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
module.exports = EventLoopHandlesRequestsMetric
|