pubo-node 1.0.165 → 1.0.167
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/child-process/index.d.ts +2 -0
- package/lib/child-process/index.js +72 -5
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -1
- package/package.json +3 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare function getProcessName(pid: any): Promise<string>;
|
|
2
|
+
export declare function getPidByPort(port: any): Promise<unknown>;
|
|
2
3
|
export declare function getProcessCpuUseByPid(pid: number): Promise<number>;
|
|
3
4
|
export declare function getProcessCommandByPid(pid: number): Promise<string>;
|
|
4
5
|
export declare function isProcessDied(pid: any): Promise<boolean>;
|
|
@@ -10,3 +11,4 @@ export declare const getAudioCards: (filter?: string) => Promise<{
|
|
|
10
11
|
text: string;
|
|
11
12
|
index: string;
|
|
12
13
|
}[]>;
|
|
14
|
+
export declare const getDiskUsage: () => Promise<unknown>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAudioCards = exports.heartbeat = exports.getProcessTree = void 0;
|
|
3
|
+
exports.getDiskUsage = exports.getAudioCards = exports.heartbeat = exports.getProcessTree = void 0;
|
|
4
4
|
exports.getProcessName = getProcessName;
|
|
5
|
+
exports.getPidByPort = getPidByPort;
|
|
5
6
|
exports.getProcessCpuUseByPid = getProcessCpuUseByPid;
|
|
6
7
|
exports.getProcessCommandByPid = getProcessCommandByPid;
|
|
7
8
|
exports.isProcessDied = isProcessDied;
|
|
@@ -22,6 +23,44 @@ function getProcessName(pid) {
|
|
|
22
23
|
});
|
|
23
24
|
});
|
|
24
25
|
}
|
|
26
|
+
// 根据端口号获取进程PID
|
|
27
|
+
async function getPidByPort(port) {
|
|
28
|
+
if (!port) {
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
if (process.platform === 'win32') {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
(0, child_process_1.exec)(`netstat -ano | findstr "${port}"`, (error, stdout, stderr) => {
|
|
34
|
+
if (error) {
|
|
35
|
+
reject(error);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const arr = stdout.split('\n');
|
|
39
|
+
if (!arr[0]) {
|
|
40
|
+
resolve('');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const tmp = arr[0].split(' ');
|
|
44
|
+
const res = tmp.pop();
|
|
45
|
+
resolve(res);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
(0, child_process_1.exec)(`lsof -i:${port} | awk '{print $2}'`, (err, stdout) => {
|
|
51
|
+
if (err) {
|
|
52
|
+
reject(err);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
let res = stdout.split('\n')[1];
|
|
56
|
+
if (res) {
|
|
57
|
+
res = res.trim();
|
|
58
|
+
}
|
|
59
|
+
resolve(res);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
25
64
|
// 获取进程 cpu 使用率
|
|
26
65
|
function getProcessCpuUseByPid(pid) {
|
|
27
66
|
return new Promise((resolve) => {
|
|
@@ -35,7 +74,7 @@ function getProcessCpuUseByPid(pid) {
|
|
|
35
74
|
});
|
|
36
75
|
});
|
|
37
76
|
}
|
|
38
|
-
// 获取进程 command
|
|
77
|
+
// 获取进程 command
|
|
39
78
|
function getProcessCommandByPid(pid) {
|
|
40
79
|
return new Promise((resolve) => {
|
|
41
80
|
(0, child_process_1.exec)(`ps -p ${pid} -o command=`, (err, stdout) => {
|
|
@@ -113,6 +152,7 @@ const flatProcessTree = (tree, tmp) => {
|
|
|
113
152
|
tree = null;
|
|
114
153
|
tmp = null;
|
|
115
154
|
};
|
|
155
|
+
// 杀死进程以及子进程
|
|
116
156
|
async function SIGKILL(pid, signal = 2) {
|
|
117
157
|
if (process.platform === 'win32') {
|
|
118
158
|
return new Promise((resolve) => {
|
|
@@ -125,16 +165,17 @@ async function SIGKILL(pid, signal = 2) {
|
|
|
125
165
|
flatProcessTree(tree, tmp);
|
|
126
166
|
tmp.reverse();
|
|
127
167
|
tree = null;
|
|
128
|
-
|
|
168
|
+
const res = { success: true, error: null };
|
|
129
169
|
for (const item of tmp) {
|
|
130
170
|
try {
|
|
131
171
|
await _SIGKILL(item, signal);
|
|
132
172
|
}
|
|
133
173
|
catch (err) {
|
|
134
|
-
|
|
174
|
+
res.error = err;
|
|
175
|
+
res.success = false;
|
|
135
176
|
}
|
|
136
177
|
}
|
|
137
|
-
return
|
|
178
|
+
return res;
|
|
138
179
|
}
|
|
139
180
|
// 子进程心跳包
|
|
140
181
|
const heartbeat = () => {
|
|
@@ -173,3 +214,29 @@ const getAudioCards = (filter = '') => {
|
|
|
173
214
|
});
|
|
174
215
|
};
|
|
175
216
|
exports.getAudioCards = getAudioCards;
|
|
217
|
+
const dic = ['fileSystem', 'size', 'used', 'avail', 'use%', 'mountedOn'];
|
|
218
|
+
const parser = (str) => {
|
|
219
|
+
return str
|
|
220
|
+
.split('\n')
|
|
221
|
+
.filter((item) => item)
|
|
222
|
+
.map((item) => item.split(' ').filter((s) => !!s))
|
|
223
|
+
.map((item) => {
|
|
224
|
+
const res = {};
|
|
225
|
+
dic.forEach((key, i) => (res[key] = item[i]));
|
|
226
|
+
return res;
|
|
227
|
+
})
|
|
228
|
+
.map((item) => ({ ...item, total: parseFloat(item.size), percentage: parseFloat(item['use%']) }));
|
|
229
|
+
};
|
|
230
|
+
const getDiskUsage = async () => {
|
|
231
|
+
return new Promise((resolve) => {
|
|
232
|
+
(0, child_process_1.exec)('df -h | grep G', (err, stdout) => {
|
|
233
|
+
if (err) {
|
|
234
|
+
resolve([]);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
resolve(parser(stdout.toString()));
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
exports.getDiskUsage = getDiskUsage;
|
package/lib/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { JsonStorage } from './storage/json';
|
|
|
2
2
|
export { FtpClient, FtpClientPool } from './ftp-client';
|
|
3
3
|
export type { FtpConnectOptions, FtpFile } from './ftp-client';
|
|
4
4
|
export { createRpcClient, GrpcList } from './grpc';
|
|
5
|
-
export { SIGKILL, isProcessDied, getProcessName, getProcessTree, getProcessByPpid, getProcessCpuUseByPid, getProcessCommandByPid, heartbeat, } from './child-process';
|
|
5
|
+
export { SIGKILL, isProcessDied, getProcessName, getProcessTree, getProcessByPpid, getProcessCpuUseByPid, getProcessCommandByPid, getPidByPort, heartbeat, getDiskUsage, } from './child-process';
|
|
6
6
|
export { isPortAvailable } from './utils';
|
|
7
7
|
export { getWifiName, getNetworks } from './utils/network';
|
|
8
8
|
export { RosTopicManager, RosTopic } from './ros/topic';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PuboFileSystem = exports.RosTopic = exports.RosTopicManager = exports.getNetworks = exports.getWifiName = exports.isPortAvailable = exports.heartbeat = exports.getProcessCommandByPid = exports.getProcessCpuUseByPid = exports.getProcessByPpid = exports.getProcessTree = exports.getProcessName = exports.isProcessDied = exports.SIGKILL = exports.GrpcList = exports.createRpcClient = exports.FtpClientPool = exports.FtpClient = exports.JsonStorage = void 0;
|
|
3
|
+
exports.PuboFileSystem = exports.RosTopic = exports.RosTopicManager = exports.getNetworks = exports.getWifiName = exports.isPortAvailable = exports.getDiskUsage = exports.heartbeat = exports.getPidByPort = exports.getProcessCommandByPid = exports.getProcessCpuUseByPid = exports.getProcessByPpid = exports.getProcessTree = exports.getProcessName = exports.isProcessDied = exports.SIGKILL = exports.GrpcList = exports.createRpcClient = exports.FtpClientPool = exports.FtpClient = exports.JsonStorage = void 0;
|
|
4
4
|
var json_1 = require("./storage/json");
|
|
5
5
|
Object.defineProperty(exports, "JsonStorage", { enumerable: true, get: function () { return json_1.JsonStorage; } });
|
|
6
6
|
var ftp_client_1 = require("./ftp-client");
|
|
@@ -17,7 +17,9 @@ Object.defineProperty(exports, "getProcessTree", { enumerable: true, get: functi
|
|
|
17
17
|
Object.defineProperty(exports, "getProcessByPpid", { enumerable: true, get: function () { return child_process_1.getProcessByPpid; } });
|
|
18
18
|
Object.defineProperty(exports, "getProcessCpuUseByPid", { enumerable: true, get: function () { return child_process_1.getProcessCpuUseByPid; } });
|
|
19
19
|
Object.defineProperty(exports, "getProcessCommandByPid", { enumerable: true, get: function () { return child_process_1.getProcessCommandByPid; } });
|
|
20
|
+
Object.defineProperty(exports, "getPidByPort", { enumerable: true, get: function () { return child_process_1.getPidByPort; } });
|
|
20
21
|
Object.defineProperty(exports, "heartbeat", { enumerable: true, get: function () { return child_process_1.heartbeat; } });
|
|
22
|
+
Object.defineProperty(exports, "getDiskUsage", { enumerable: true, get: function () { return child_process_1.getDiskUsage; } });
|
|
21
23
|
var utils_1 = require("./utils");
|
|
22
24
|
Object.defineProperty(exports, "isPortAvailable", { enumerable: true, get: function () { return utils_1.isPortAvailable; } });
|
|
23
25
|
var network_1 = require("./utils/network");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubo-node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.167",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@types/node": "^17.0.25",
|
|
21
|
-
"pubo-utils": "^1.0.
|
|
21
|
+
"pubo-utils": "^1.0.167",
|
|
22
22
|
"yaml": "^2.5.1"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "3e19f954e9f9cf7e8c358012818b9578007df8a0",
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"del": "^5.1.0",
|
|
27
27
|
"eslint": "^8.42.0",
|