pm2-perfmonitor 2.1.6 → 2.2.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/lib/app.js +5 -2
- package/lib/utils.js +14 -0
- package/package.json +3 -2
package/lib/app.js
CHANGED
|
@@ -6,6 +6,7 @@ const {
|
|
|
6
6
|
parseParamToNumber,
|
|
7
7
|
parseBool,
|
|
8
8
|
sleepAsync,
|
|
9
|
+
getSysCpuUsageByPid,
|
|
9
10
|
} = require('./utils')
|
|
10
11
|
const { defaultOptions } = require('./defaults')
|
|
11
12
|
const { sendMessage } = require('./message')
|
|
@@ -172,10 +173,12 @@ const processChecker = async () => {
|
|
|
172
173
|
const apps = await listAppsAsync()
|
|
173
174
|
|
|
174
175
|
for (const app of apps) {
|
|
175
|
-
const { name, pm_id, monit, pm2_env
|
|
176
|
+
const { name, pid, pm_id, monit, pm2_env } = app
|
|
177
|
+
|
|
178
|
+
const sysCpuUsage = await getSysCpuUsageByPid(pid)
|
|
176
179
|
|
|
177
180
|
const appStatus = pm2_env?.status
|
|
178
|
-
const appCpuUsage =
|
|
181
|
+
const appCpuUsage = sysCpuUsage
|
|
179
182
|
|
|
180
183
|
// 非目标应用,跳过
|
|
181
184
|
if (
|
package/lib/utils.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const pidusage = require('pidusage')
|
|
2
|
+
|
|
1
3
|
const parseParamToArray = (value, defaultVal = []) => {
|
|
2
4
|
if (Array.isArray(value)) return value
|
|
3
5
|
|
|
@@ -37,9 +39,21 @@ const sleepAsync = (duration = 0) => {
|
|
|
37
39
|
})
|
|
38
40
|
}
|
|
39
41
|
|
|
42
|
+
/**
|
|
43
|
+
* 获取指定进程的CPU使用率
|
|
44
|
+
* @param {string| number} pid
|
|
45
|
+
* @returns { Promise<number> } CPU 使用率
|
|
46
|
+
*/
|
|
47
|
+
const getSysCpuUsageByPid = async (pid) => {
|
|
48
|
+
const stats = await pidusage(pid)
|
|
49
|
+
|
|
50
|
+
return stats.cpu
|
|
51
|
+
}
|
|
52
|
+
|
|
40
53
|
module.exports = {
|
|
41
54
|
parseParamToArray,
|
|
42
55
|
parseParamToNumber,
|
|
43
56
|
parseBool,
|
|
44
57
|
sleepAsync,
|
|
58
|
+
getSysCpuUsageByPid,
|
|
45
59
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pm2-perfmonitor",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "A pm2 module for performance monitoring. Automatically detect zombie processes and restart it",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "elenh",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"execa": "^9.6.1",
|
|
46
46
|
"fs-extra": "^11.3.4",
|
|
47
|
+
"pidusage": "^4.0.1",
|
|
47
48
|
"pm2": "latest",
|
|
48
49
|
"pmx": "latest"
|
|
49
50
|
},
|
|
@@ -52,4 +53,4 @@
|
|
|
52
53
|
"cz-conventional-changelog": "^3.3.0",
|
|
53
54
|
"minimist": "^1.2.8"
|
|
54
55
|
}
|
|
55
|
-
}
|
|
56
|
+
}
|