pm2-perfmonitor 2.6.1 → 2.6.3

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Yisibell Hong
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yisibell Hong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,59 +1,59 @@
1
- # pm2-perfmonitor
2
-
3
- A pm2 module for **zombie process** and **CPU overload** detection.
4
-
5
- # Features
6
-
7
- - Automatically detect **zombie** processes and restart it.
8
- - Monitor the number of zombie process restarts (`pm2 monit`).
9
- - [Added in v2] Support **CPU overload** protection (automatic restart + `perf` collection).
10
- - [Added in v2] Monitor the number of CPU Overload process restarts (`pm2 monit`).
11
-
12
- # Installation
13
-
14
- ```bash
15
- # install or update
16
- $ pm2 install pm2-perfmonitor
17
-
18
- # uninstall
19
- $ pm2 uninstall pm2-perfmonitor
20
- ```
21
-
22
- > NOTE: the command is `pm2 install` NOT `npm install`
23
-
24
- # Configure
25
-
26
- | Property | Defaults | Description | Supported |
27
- | :-----------------------------: | :-----------------: | :-----------------------------------------------------------------------------------------------------: | :----------: |
28
- | `enabled` | `true` | Specify whether to enable this module | v1 and above |
29
- | `excludeApps` | - | Specify the application name that needs to be excluded from guardianship | v1 and above |
30
- | `includeApps` | - | Specify the application name that needs to be guarded | v1 and above |
31
- | `workerInterval` | `60000` | Timed task execution interval (ms) | v1 and above |
32
- | `zombieDetection` | `true` | Specify whether to enable zombie process protection | v1 and above |
33
- | `zombieMaxHits` | `10` | Specify the maximum occurrence frequency of zombie status | v1 and above |
34
- | `autoRestartWhenZombieDetected` | `true` | Specify whether to automatically restart zombie processes | v1 and above |
35
- | `zombieMaxRestarts` | `0` | Specify the maximum number of restarts for zombie processes (set to `0` to indicate no limit) | v1 and above |
36
- | `cpuOverloadDetection` | `false` | Specify whether to enable CPU overload protection | v2 |
37
- | `cpuOverloadThreshold` | `90` | Specify the threshold for determining CPU overload | v2 |
38
- | `cpuOverloadMaxHits` | `5` | Maximum number of consecutive occurrences of CPU overload allowed (automatically restarts when reached) | v2 |
39
- | `enableNodeInspectorCollection` | `false` | Specify whether to enable `node:inspector` performance collection | v2 |
40
- | `nodeInspectorSampleDuration` | `10` | Specify the performance collection duration (s) for `node:inspector` | v2 |
41
- | `enablePerfCollection` | `false` | Specify whether to enable `perf` performance collection | v2 |
42
- | `perfReportGenerationDir` | `/var/log/pm2/perf` | Specify the directory for generating performance reports for `perf` | v2 |
43
- | `flamegraphDir` | `/opt/FlameGraph` | Specify the directory for `flamegraph` flame map generation tool | v2 |
44
- | `perfSampleDuration` | `10` | Specify the sampling duration (s) for `perf` | v2 |
45
- | `perfSampleFrequency` | `99` | Specify the sampling frequency (Hz) for `perf` | v2 |
46
-
47
-
48
- > Please see the details for all configurable options:[Default Options](./lib//defaults.js)
49
-
50
- # How to set these values ?
51
-
52
- After having installed the module you have to type : `pm2 set pm2-perfmonitor:<param> <value>`
53
-
54
- **e.g:**
55
-
56
- - `pm2 set pm2-perfmonitor:includeApps myNuxtApp1, myNextApp2` (Only detect applications named `myNuxtApp1` and `myNextApp2`)
57
- - `pm2 set pm2-perfmonitor:workerInterval 120000` (Check every `2` minutes)
58
- - `pm2 set pm2-perfmonitor:cpuOverloadDetection true`(enable **CPU overload** protection)
59
- - `pm2 set pm2-perfmonitor:zombieProcessDetectionStrategy zombie-state-and-zero-cpu`(Set the strategy for detecting zombie processes to: system process status is **Z** and CPU usage is consistently **0%**)
1
+ # pm2-perfmonitor
2
+
3
+ A pm2 module for **zombie process** and **CPU overload** detection.
4
+
5
+ # Features
6
+
7
+ - Automatically detect **zombie** processes and restart it.
8
+ - Monitor the number of zombie process restarts (`pm2 monit`).
9
+ - [Added in v2] Support **CPU overload** protection (automatic restart + `perf` collection).
10
+ - [Added in v2] Monitor the number of CPU Overload process restarts (`pm2 monit`).
11
+
12
+ # Installation
13
+
14
+ ```bash
15
+ # install or update
16
+ $ pm2 install pm2-perfmonitor
17
+
18
+ # uninstall
19
+ $ pm2 uninstall pm2-perfmonitor
20
+ ```
21
+
22
+ > NOTE: the command is `pm2 install` NOT `npm install`
23
+
24
+ # Configure
25
+
26
+ | Property | Defaults | Description | Supported |
27
+ | :-----------------------------: | :-----------------: | :-----------------------------------------------------------------------------------------------------: | :----------: |
28
+ | `enabled` | `true` | Specify whether to enable this module | v1 and above |
29
+ | `excludeApps` | - | Specify the application name that needs to be excluded from guardianship | v1 and above |
30
+ | `includeApps` | - | Specify the application name that needs to be guarded | v1 and above |
31
+ | `workerInterval` | `60000` | Timed task execution interval (ms) | v1 and above |
32
+ | `zombieDetection` | `true` | Specify whether to enable zombie process protection | v1 and above |
33
+ | `zombieMaxHits` | `10` | Specify the maximum occurrence frequency of zombie status | v1 and above |
34
+ | `autoRestartWhenZombieDetected` | `true` | Specify whether to automatically restart zombie processes | v1 and above |
35
+ | `zombieMaxRestarts` | `0` | Specify the maximum number of restarts for zombie processes (set to `0` to indicate no limit) | v1 and above |
36
+ | `cpuOverloadDetection` | `false` | Specify whether to enable CPU overload protection | v2 |
37
+ | `cpuOverloadThreshold` | `90` | Specify the threshold for determining CPU overload | v2 |
38
+ | `cpuOverloadMaxHits` | `5` | Maximum number of consecutive occurrences of CPU overload allowed (automatically restarts when reached) | v2 |
39
+ | `enableNodeInspectorCollection` | `false` | Specify whether to enable `node:inspector` performance collection | v2 |
40
+ | `nodeInspectorSampleDuration` | `10` | Specify the performance collection duration (s) for `node:inspector` | v2 |
41
+ | `enablePerfCollection` | `false` | Specify whether to enable `perf` performance collection | v2 |
42
+ | `perfReportGenerationDir` | `/var/log/pm2/perf` | Specify the directory for generating performance reports for `perf` | v2 |
43
+ | `flamegraphDir` | `/opt/FlameGraph` | Specify the directory for `flamegraph` flame map generation tool | v2 |
44
+ | `perfSampleDuration` | `10` | Specify the sampling duration (s) for `perf` | v2 |
45
+ | `perfSampleFrequency` | `99` | Specify the sampling frequency (Hz) for `perf` | v2 |
46
+
47
+
48
+ > Please see the details for all configurable options:[Default Options](./lib//defaults.js)
49
+
50
+ # How to set these values ?
51
+
52
+ After having installed the module you have to type : `pm2 set pm2-perfmonitor:<param> <value>`
53
+
54
+ **e.g:**
55
+
56
+ - `pm2 set pm2-perfmonitor:includeApps myNuxtApp1, myNextApp2` (Only detect applications named `myNuxtApp1` and `myNextApp2`)
57
+ - `pm2 set pm2-perfmonitor:workerInterval 120000` (Check every `2` minutes)
58
+ - `pm2 set pm2-perfmonitor:cpuOverloadDetection true`(enable **CPU overload** protection)
59
+ - `pm2 set pm2-perfmonitor:zombieProcessDetectionStrategy zombie-state-and-zero-cpu`(Set the strategy for detecting zombie processes to: system process status is **Z** and CPU usage is consistently **0%**)
package/lib/alert.js CHANGED
@@ -1,29 +1,29 @@
1
- const { getExeca } = require('./execa-helper')
2
-
3
- /**
4
- * 发送警告
5
- * @param { object } options
6
- * @param { string } options.cmd - bash 脚本 path(默认值:/var/job/alert.sh)
7
- * @param { string } options.env - 环境(默认值: prod)
8
- * @param { string } options.level - 报警级别(默认值: Sev-2)
9
- * @param { string } options.title - 报警标题
10
- * @param { string } options.content - 报警正文
11
- */
12
- const sendAlert = async (options) => {
13
- try {
14
- const execa = await getExeca()
15
-
16
- const args = [options.env, options.level, options.title, options.content]
17
-
18
- await execa(options.cmd, args)
19
-
20
- return true
21
- } catch (err) {
22
- console.error('[Send Alert Error]:', err)
23
- return false
24
- }
25
- }
26
-
27
- module.exports = {
28
- sendAlert,
29
- }
1
+ const { getExeca } = require('./execa-helper')
2
+
3
+ /**
4
+ * 发送警告
5
+ * @param { object } options
6
+ * @param { string } options.cmd - bash 脚本 path(默认值:/var/job/alert.sh)
7
+ * @param { string } options.env - 环境(默认值: prod)
8
+ * @param { string } options.level - 报警级别(默认值: Sev-2)
9
+ * @param { string } options.title - 报警标题
10
+ * @param { string } options.content - 报警正文
11
+ */
12
+ const sendAlert = async (options) => {
13
+ try {
14
+ const execa = await getExeca()
15
+
16
+ const args = [options.env, options.level, options.title, options.content]
17
+
18
+ await execa(options.cmd, args)
19
+
20
+ return true
21
+ } catch (err) {
22
+ console.error('[Send Alert Error]:', err)
23
+ return false
24
+ }
25
+ }
26
+
27
+ module.exports = {
28
+ sendAlert,
29
+ }