@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,33 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
class Counter {
|
|
4
|
+
constructor (opts) {
|
|
5
|
+
opts = opts || {}
|
|
6
|
+
this._count = opts.count || 0
|
|
7
|
+
this._used = false
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
val () {
|
|
11
|
+
return this._count
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
inc (n) {
|
|
15
|
+
this._used = true
|
|
16
|
+
this._count += (n || 1)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
dec (n) {
|
|
20
|
+
this._used = true
|
|
21
|
+
this._count -= (n || 1)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
reset (count) {
|
|
25
|
+
this._count = count || 0
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
isUsed () {
|
|
29
|
+
return this._used
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = Counter
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
class Gauge {
|
|
4
|
+
constructor () {
|
|
5
|
+
this._value = 0
|
|
6
|
+
this._used = false
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
val () {
|
|
10
|
+
return this._value
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
set (value) {
|
|
14
|
+
this._used = true
|
|
15
|
+
this._value = value
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
isUsed () {
|
|
19
|
+
return this._used
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = Gauge
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const EDS = require('../EDS')
|
|
4
|
+
|
|
5
|
+
class Histogram {
|
|
6
|
+
constructor (opts) {
|
|
7
|
+
opts = opts || {}
|
|
8
|
+
|
|
9
|
+
this._measurement = opts.measurement
|
|
10
|
+
this._callFn = null
|
|
11
|
+
|
|
12
|
+
this._sample = new EDS()
|
|
13
|
+
this._min = undefined
|
|
14
|
+
this._max = undefined
|
|
15
|
+
this._count = 0
|
|
16
|
+
this._sum = 0
|
|
17
|
+
|
|
18
|
+
// These are for the Welford algorithm for calculating running variance
|
|
19
|
+
// without floating-point doom.
|
|
20
|
+
this._varianceM = 0
|
|
21
|
+
this._varianceS = 0
|
|
22
|
+
this._ema = 0
|
|
23
|
+
|
|
24
|
+
this._used = false
|
|
25
|
+
|
|
26
|
+
const methods = {
|
|
27
|
+
min : this.getMin,
|
|
28
|
+
max : this.getMax,
|
|
29
|
+
sum : this.getSum,
|
|
30
|
+
count : this.getCount,
|
|
31
|
+
variance : this._calculateVariance,
|
|
32
|
+
mean : this._calculateMean,
|
|
33
|
+
ema : this.getEma()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (methods.hasOwnProperty(this._measurement)) {
|
|
37
|
+
this._callFn = methods[this._measurement]
|
|
38
|
+
} else {
|
|
39
|
+
this._callFn = function () {
|
|
40
|
+
const percentiles = this.percentiles([0.5, 0.75, 0.95, 0.99, 0.999])
|
|
41
|
+
|
|
42
|
+
const medians = {
|
|
43
|
+
median : percentiles[0.5],
|
|
44
|
+
p75 : percentiles[0.75],
|
|
45
|
+
p95 : percentiles[0.95],
|
|
46
|
+
p99 : percentiles[0.99],
|
|
47
|
+
p999 : percentiles[0.999]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return medians[this._measurement]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
update (value) {
|
|
56
|
+
this._used = true
|
|
57
|
+
this._count++
|
|
58
|
+
this._sum += value
|
|
59
|
+
|
|
60
|
+
this._sample.update(value)
|
|
61
|
+
this._updateMin(value)
|
|
62
|
+
this._updateMax(value)
|
|
63
|
+
this._updateVariance(value)
|
|
64
|
+
this._updateEma(value)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
percentiles (percentiles) {
|
|
68
|
+
const values = this._sample
|
|
69
|
+
.toArray()
|
|
70
|
+
.sort(function (a, b) {
|
|
71
|
+
return (a === b)
|
|
72
|
+
? 0
|
|
73
|
+
: a - b
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
const results = {}
|
|
77
|
+
for (let i = 0; i < percentiles.length; i++) {
|
|
78
|
+
const percentile = percentiles[i]
|
|
79
|
+
if (!values.length) {
|
|
80
|
+
results[percentile] = null
|
|
81
|
+
continue
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const pos = percentile * (values.length + 1)
|
|
85
|
+
|
|
86
|
+
if (pos < 1) {
|
|
87
|
+
results[percentile] = values[0]
|
|
88
|
+
} else if (pos >= values.length) {
|
|
89
|
+
results[percentile] = values[values.length - 1]
|
|
90
|
+
} else {
|
|
91
|
+
const lower = values[Math.floor(pos) - 1]
|
|
92
|
+
const upper = values[Math.ceil(pos) - 1]
|
|
93
|
+
|
|
94
|
+
results[percentile] = lower + (pos - Math.floor(pos)) * (upper - lower)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return results
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
val () {
|
|
102
|
+
if (typeof(this._callFn) === 'function') {
|
|
103
|
+
return this._callFn()
|
|
104
|
+
} else {
|
|
105
|
+
return this._callFn
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
getMin () {
|
|
110
|
+
return this._min
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
getMax () {
|
|
114
|
+
return this._max
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
getSum () {
|
|
118
|
+
return this._sum
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
getCount () {
|
|
122
|
+
return this._count
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
getEma () {
|
|
126
|
+
return this._ema
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
fullResults () {
|
|
130
|
+
const percentiles = this.percentiles([0.5, 0.75, 0.95, 0.99, 0.999])
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
min : this._min,
|
|
134
|
+
max : this._max,
|
|
135
|
+
sum : this._sum,
|
|
136
|
+
variance : this._calculateVariance(),
|
|
137
|
+
mean : this._calculateMean(),
|
|
138
|
+
count : this._count,
|
|
139
|
+
median : percentiles[0.5],
|
|
140
|
+
p75 : percentiles[0.75],
|
|
141
|
+
p95 : percentiles[0.95],
|
|
142
|
+
p99 : percentiles[0.99],
|
|
143
|
+
p999 : percentiles[0.999],
|
|
144
|
+
ema : this._ema
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
_updateMin (value) {
|
|
149
|
+
if (this._min === undefined || value < this._min) {
|
|
150
|
+
this._min = value
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
_updateMax (value) {
|
|
155
|
+
if (this._max === undefined || value > this._max) {
|
|
156
|
+
this._max = value
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
_updateVariance (value) {
|
|
161
|
+
if (this._count === 1) return this._varianceM = value
|
|
162
|
+
|
|
163
|
+
const oldM = this._varianceM
|
|
164
|
+
|
|
165
|
+
this._varianceM += ((value - oldM) / this._count)
|
|
166
|
+
this._varianceS += ((value - oldM) * (value - this._varianceM))
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
_updateEma (value) {
|
|
170
|
+
if (this._count <= 1) return this._ema = this._calculateMean()
|
|
171
|
+
const alpha = 2 / (1 + this._count)
|
|
172
|
+
this._ema = value * alpha + this._ema * (1 - alpha)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
_calculateMean () {
|
|
176
|
+
return (this._count === 0)
|
|
177
|
+
? 0
|
|
178
|
+
: this._sum / this._count
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
_calculateVariance () {
|
|
182
|
+
return (this._count <= 1)
|
|
183
|
+
? null
|
|
184
|
+
: this._varianceS / (this._count - 1)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
isUsed () {
|
|
188
|
+
return this._used
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
module.exports = Histogram
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const EWMA = require('../EWMA')
|
|
4
|
+
const units = require('../units')
|
|
5
|
+
|
|
6
|
+
class Meter {
|
|
7
|
+
constructor (opts) {
|
|
8
|
+
const self = this
|
|
9
|
+
|
|
10
|
+
if (typeof opts !== 'object') {
|
|
11
|
+
opts = {}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
this._samples = opts.samples || opts.seconds || 1
|
|
15
|
+
this._timeframe = opts.timeframe || 60
|
|
16
|
+
this._tickInterval = opts.tickInterval || 5 * units.SECONDS
|
|
17
|
+
this._used = false
|
|
18
|
+
|
|
19
|
+
this._rate = new EWMA(this._timeframe * units.SECONDS, this._tickInterval)
|
|
20
|
+
|
|
21
|
+
if (opts.debug && opts.debug === true) {
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
this._interval = setInterval(function () {
|
|
26
|
+
self._rate.tick()
|
|
27
|
+
}, this._tickInterval)
|
|
28
|
+
|
|
29
|
+
this._interval.unref()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
mark (n) {
|
|
33
|
+
this._used = true
|
|
34
|
+
this._rate.update(n === undefined ? 1 : n)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
val () {
|
|
38
|
+
return Math.round(this._rate.rate(this._samples * units.SECONDS) * 100) / 100
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
isUsed () {
|
|
42
|
+
return this._used
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = Meter
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { ServiceManager } = require('../serviceManager')
|
|
4
|
+
|
|
5
|
+
class MiscUtils {
|
|
6
|
+
static generateUUID () {
|
|
7
|
+
return Math.random().toString(36).substr(2, 16)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static getValueFromDump (property, parentProperty) {
|
|
11
|
+
if (!parentProperty) {
|
|
12
|
+
parentProperty = 'handles'
|
|
13
|
+
}
|
|
14
|
+
const dump = ServiceManager.get('eventLoopService').inspector.dump()
|
|
15
|
+
return dump[parentProperty].hasOwnProperty(property) ? dump[parentProperty][property].length : 0
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = MiscUtils
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const Debug = require('debug')
|
|
5
|
+
const path = require('path')
|
|
6
|
+
|
|
7
|
+
const debug = Debug('axm:utils:module')
|
|
8
|
+
|
|
9
|
+
class ModuleUtils {
|
|
10
|
+
/**
|
|
11
|
+
* Try to load a module from its path
|
|
12
|
+
*/
|
|
13
|
+
static loadModule (modulePath, args) {
|
|
14
|
+
let nodule
|
|
15
|
+
try {
|
|
16
|
+
if (args) {
|
|
17
|
+
nodule = require(modulePath).apply(this, args)
|
|
18
|
+
} else {
|
|
19
|
+
nodule = require(modulePath)
|
|
20
|
+
}
|
|
21
|
+
debug(`Succesfully required module at path ${modulePath}`)
|
|
22
|
+
return nodule
|
|
23
|
+
} catch (err) {
|
|
24
|
+
debug(`Failed to load module at path ${modulePath}: ${err.message}`)
|
|
25
|
+
return err
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Try to detect the path of a specific module
|
|
31
|
+
*/
|
|
32
|
+
static detectModule (moduleName) {
|
|
33
|
+
const fakePath = ['./node_modules', '/node_modules']
|
|
34
|
+
if (!require.main) {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
const paths = typeof require.main.paths === 'undefined' ? fakePath : require.main.paths
|
|
38
|
+
|
|
39
|
+
const requirePaths = paths.slice()
|
|
40
|
+
|
|
41
|
+
return ModuleUtils._lookForModule(requirePaths, moduleName)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Lookup in each require path for the module name
|
|
46
|
+
*/
|
|
47
|
+
static _lookForModule (requirePaths, moduleName) {
|
|
48
|
+
// in older node version, the constants where at the top level
|
|
49
|
+
const fsConstants = fs.constants || fs
|
|
50
|
+
// check for every path if we can find the module
|
|
51
|
+
for (let requirePath of requirePaths) {
|
|
52
|
+
const completePath = path.join(requirePath, moduleName)
|
|
53
|
+
debug(`Looking for module ${moduleName} in ${completePath}`)
|
|
54
|
+
try {
|
|
55
|
+
fs.accessSync(completePath, fsConstants.R_OK)
|
|
56
|
+
debug(`Found module ${moduleName} in path ${completePath}`)
|
|
57
|
+
return completePath
|
|
58
|
+
} catch (err) {
|
|
59
|
+
debug(`module ${moduleName} not found in path ${completePath}`)
|
|
60
|
+
continue
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = ModuleUtils
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
function wrap (nodule, name, wrapper) {
|
|
4
|
+
const original = nodule[name]
|
|
5
|
+
const wrapped = wrapper(original, name)
|
|
6
|
+
wrapped.__wrapped = true
|
|
7
|
+
wrapped.__original = original
|
|
8
|
+
wrapped.__unwrap = function () { nodule[name] = original }
|
|
9
|
+
nodule[name] = wrapped
|
|
10
|
+
return wrapped
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function unwrap (nodule, name) {
|
|
14
|
+
if (nodule[name] && nodule[name].__unwrap) {
|
|
15
|
+
nodule[name].__unwrap()
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = { wrap, unwrap }
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Simple cache implementation
|
|
5
|
+
*
|
|
6
|
+
* @param {Object} opts cache options
|
|
7
|
+
* @param {Function} opts.miss function called when a key isn't found in the cache
|
|
8
|
+
*/
|
|
9
|
+
class Cache {
|
|
10
|
+
constructor (opts) {
|
|
11
|
+
this._cache = {}
|
|
12
|
+
this._ttlCache = {}
|
|
13
|
+
this._worker = null
|
|
14
|
+
this._tllTime = opts.ttl || -1
|
|
15
|
+
this._onMiss = opts.miss
|
|
16
|
+
|
|
17
|
+
if (opts.ttl) {
|
|
18
|
+
this._worker = setInterval(this.workerFn.bind(this), 1000)
|
|
19
|
+
this._worker.unref()
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
workerFn () {
|
|
24
|
+
let keys = Object.keys(this._ttlCache)
|
|
25
|
+
for (let i = 0; i < keys.length; i++) {
|
|
26
|
+
let key = keys[i]
|
|
27
|
+
let value = this._ttlCache[key]
|
|
28
|
+
if (Date.now() > value) {
|
|
29
|
+
delete this._cache[key]
|
|
30
|
+
delete this._ttlCache[key]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Get a value from the cache
|
|
37
|
+
*
|
|
38
|
+
* @param {String} key
|
|
39
|
+
*/
|
|
40
|
+
get (key) {
|
|
41
|
+
if (!key) return null
|
|
42
|
+
let value = this._cache[key]
|
|
43
|
+
if (value) return value
|
|
44
|
+
|
|
45
|
+
value = this._onMiss(key)
|
|
46
|
+
|
|
47
|
+
if (value) {
|
|
48
|
+
this.set(key, value)
|
|
49
|
+
}
|
|
50
|
+
return value
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Set a value in the cache
|
|
55
|
+
*
|
|
56
|
+
* @param {String} key
|
|
57
|
+
* @param {Mixed} value
|
|
58
|
+
*/
|
|
59
|
+
set (key, value) {
|
|
60
|
+
if (!key || !value) return false
|
|
61
|
+
this._cache[key] = value
|
|
62
|
+
if (this._tllTime > 0) {
|
|
63
|
+
this._ttlCache[key] = Date.now() + this._tllTime
|
|
64
|
+
}
|
|
65
|
+
return true
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
reset () {
|
|
69
|
+
this._cache = {}
|
|
70
|
+
this._ttlCache = {}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* StackTraceParser is used to parse callsite from stacktrace
|
|
76
|
+
* and get from FS the context of the error (if available)
|
|
77
|
+
*
|
|
78
|
+
* @param {Cache} cache cache implementation used to query file from FS and get context
|
|
79
|
+
*/
|
|
80
|
+
class StackTraceParser {
|
|
81
|
+
constructor (options) {
|
|
82
|
+
this._cache = options.cache
|
|
83
|
+
this._contextSize = options.contextSize || 3
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
isAbsolute (path) {
|
|
87
|
+
if (process.platform === 'win32') {
|
|
88
|
+
// https://github.com/nodejs/node/blob/b3fcc245fb25539909ef1d5eaa01dbf92e168633/lib/path.js#L56
|
|
89
|
+
let splitDeviceRe = /^([a-zA-Z]:|[\\/]{2}[^\\/]+[\\/]+[^\\/]+)?([\\/])?([\s\S]*?)$/
|
|
90
|
+
let result = splitDeviceRe.exec(path)
|
|
91
|
+
if (result === null) return path.charAt(0) === '/'
|
|
92
|
+
let device = result[1] || ''
|
|
93
|
+
let isUnc = Boolean(device && device.charAt(1) !== ':')
|
|
94
|
+
// UNC paths are always absolute
|
|
95
|
+
return Boolean(result[2] || isUnc)
|
|
96
|
+
} else {
|
|
97
|
+
return path.charAt(0) === '/'
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
parse (stack) {
|
|
102
|
+
if (stack.length === 0) return null
|
|
103
|
+
|
|
104
|
+
const userFrame = stack.find(frame => {
|
|
105
|
+
const type = this.isAbsolute(frame.file_name) || frame.file_name[0] === '.' ? 'user' : 'core'
|
|
106
|
+
return type !== 'core' && frame.file_name.indexOf('node_modules') < 0 && frame.file_name.indexOf('pm2-io-bpm') < 0
|
|
107
|
+
})
|
|
108
|
+
if (userFrame === undefined) return null
|
|
109
|
+
|
|
110
|
+
// get the whole context (all lines) and cache them if necessary
|
|
111
|
+
const context = this._cache.get(userFrame.file_name)
|
|
112
|
+
const source = []
|
|
113
|
+
if (context === null || context.length === 0) return null
|
|
114
|
+
// get line before the call
|
|
115
|
+
const preLine = userFrame.line_number - this._contextSize - 1
|
|
116
|
+
const start = preLine > 0 ? preLine : 0
|
|
117
|
+
context.slice(start, userFrame.line_number - 1).forEach(function (line) {
|
|
118
|
+
source.push(line.replace(/\t/g, ' '))
|
|
119
|
+
})
|
|
120
|
+
// get the line where the call has been made
|
|
121
|
+
if (context[userFrame.line_number - 1]) {
|
|
122
|
+
source.push(context[userFrame.line_number - 1].replace(/\t/g, ' ').replace(' ', '>>'))
|
|
123
|
+
}
|
|
124
|
+
// and get the line after the call
|
|
125
|
+
const postLine = userFrame.line_number + this._contextSize
|
|
126
|
+
context.slice(userFrame.line_number, postLine).forEach(function (line) {
|
|
127
|
+
source.push(line.replace(/\t/g, ' '))
|
|
128
|
+
})
|
|
129
|
+
return {
|
|
130
|
+
context: source.join('\n'),
|
|
131
|
+
callsite: [ userFrame.file_name, userFrame.line_number ].join(':')
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
retrieveContext (error) {
|
|
136
|
+
if (error.stack === undefined) return null
|
|
137
|
+
const frameRegex = /(\/[^\\\n]*)/g
|
|
138
|
+
let tmp
|
|
139
|
+
let frames = []
|
|
140
|
+
|
|
141
|
+
while ((tmp = frameRegex.exec(error.stack))) {
|
|
142
|
+
frames.push(tmp[1])
|
|
143
|
+
}
|
|
144
|
+
const stackFrames = frames.map((callsite) => {
|
|
145
|
+
if (callsite[callsite.length - 1] === ')') {
|
|
146
|
+
callsite = callsite.substr(0, callsite.length - 1)
|
|
147
|
+
}
|
|
148
|
+
let location = callsite.split(':')
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
file_name: location[0],
|
|
152
|
+
line_number: parseInt(location[1], 10)
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
return this.parse(stackFrames)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
module.exports = { Cache, StackTraceParser }
|