systeminformation 6.0.0-beta.7 → 6.0.0-beta.9
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/README.md +17 -1
- package/dist/common/defaults.d.ts +2 -1
- package/dist/common/defaults.js +11 -1
- package/dist/common/files.d.ts +8 -0
- package/dist/common/files.js +58 -3
- package/dist/common/nvidia.js +2 -1
- package/dist/common/parse.d.ts +4 -6
- package/dist/common/parse.js +24 -69
- package/dist/common/security.d.ts +1 -0
- package/dist/common/security.js +3 -1
- package/dist/common/types.d.ts +12 -2
- package/dist/cpu-current-load.js +5 -5
- package/dist/cpu-current-speed.js +5 -3
- package/dist/darwin/index.d.ts +1 -0
- package/dist/darwin/index.js +3 -1
- package/dist/darwin/serial-ports.d.ts +2 -0
- package/dist/darwin/serial-ports.js +94 -0
- package/dist/get-data.d.ts +2 -0
- package/dist/get-data.js +3 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/linux/audio.js +11 -2
- package/dist/linux/baseboard.js +9 -20
- package/dist/linux/bios.js +6 -15
- package/dist/linux/camera.js +2 -1
- package/dist/linux/chassis.js +4 -10
- package/dist/linux/cpu-temperature.js +34 -19
- package/dist/linux/cpu.js +3 -1
- package/dist/linux/disk-layout.js +2 -5
- package/dist/linux/disks-io.js +6 -6
- package/dist/linux/fans.js +3 -2
- package/dist/linux/fs-size.js +120 -26
- package/dist/linux/fs-stats.js +6 -9
- package/dist/linux/gpu.js +2 -1
- package/dist/linux/index.d.ts +1 -0
- package/dist/linux/index.js +3 -1
- package/dist/linux/mem-layout.js +2 -2
- package/dist/linux/network-interfaces.js +10 -29
- package/dist/linux/network-stats.js +1 -1
- package/dist/linux/npu.js +2 -1
- package/dist/linux/os-info.js +19 -4
- package/dist/linux/printer.js +4 -4
- package/dist/linux/process-load.js +9 -12
- package/dist/linux/processes.js +88 -79
- package/dist/linux/serial-ports.d.ts +2 -0
- package/dist/linux/serial-ports.js +102 -0
- package/dist/linux/services.js +12 -12
- package/dist/linux/system.js +1 -7
- package/dist/linux/uuid.js +4 -10
- package/dist/serial-ports.d.ts +1 -0
- package/dist/serial-ports.js +17 -0
- package/dist/windows/index.d.ts +1 -0
- package/dist/windows/index.js +3 -1
- package/dist/windows/process-load.js +5 -4
- package/dist/windows/processes.js +10 -6
- package/dist/windows/serial-ports.d.ts +3 -0
- package/dist/windows/serial-ports.js +73 -0
- package/package.json +1 -1
package/dist/linux/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.shell = exports.services = exports.processLoad = exports.processes = exports.printer = exports.pci = exports.osInfo = exports.npu = exports.npm = exports.networkStats = exports.networkInterfaces = exports.networkInterfaceDefault = exports.networkGatewayDefault = exports.networkConnections = exports.mouse = exports.memLayout = exports.mem = exports.keyboard = exports.inetLatency = exports.inetChecksite = exports.gpu = exports.fullLoad = exports.fsStats = exports.fsSize = exports.fsOpenFiles = exports.dockerAll = exports.dockerVolumes = exports.dockerContainerProcesses = exports.dockerContainerStats = exports.dockerContainers = exports.dockerImages = exports.dockerInfo = exports.displays = exports.disksIO = exports.diskLayout = exports.currentLoad = exports.fans = exports.cpuTemperature = exports.cpuFlags = exports.cpuCurrentSpeed = exports.cpuCache = exports.cpu = exports.chassis = exports.camera = exports.bluetoothDevices = exports.blockDevices = exports.bios = exports.battery = exports.baseboard = exports.audio = void 0;
|
|
4
|
-
exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.versions = exports.version = exports.vboxInfo = exports.uuid = exports.users = exports.usb = exports.time = exports.thunderbolt = exports.system = exports.software = void 0;
|
|
4
|
+
exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.versions = exports.version = exports.vboxInfo = exports.uuid = exports.users = exports.usb = exports.serialPorts = exports.time = exports.thunderbolt = exports.system = exports.software = void 0;
|
|
5
5
|
var audio_1 = require("./audio");
|
|
6
6
|
Object.defineProperty(exports, "audio", { enumerable: true, get: function () { return audio_1.audio; } });
|
|
7
7
|
var baseboard_1 = require("./baseboard");
|
|
@@ -104,6 +104,8 @@ var thunderbolt_1 = require("./thunderbolt");
|
|
|
104
104
|
Object.defineProperty(exports, "thunderbolt", { enumerable: true, get: function () { return thunderbolt_1.thunderbolt; } });
|
|
105
105
|
var time_1 = require("../time");
|
|
106
106
|
Object.defineProperty(exports, "time", { enumerable: true, get: function () { return time_1.time; } });
|
|
107
|
+
var serial_ports_1 = require("./serial-ports");
|
|
108
|
+
Object.defineProperty(exports, "serialPorts", { enumerable: true, get: function () { return serial_ports_1.serialPorts; } });
|
|
107
109
|
var usb_1 = require("./usb");
|
|
108
110
|
Object.defineProperty(exports, "usb", { enumerable: true, get: function () { return usb_1.usb; } });
|
|
109
111
|
var users_1 = require("./users");
|
package/dist/linux/mem-layout.js
CHANGED
|
@@ -5,6 +5,7 @@ const node_os_1 = require("node:os");
|
|
|
5
5
|
const common_1 = require("../common");
|
|
6
6
|
const const_1 = require("../common/const");
|
|
7
7
|
const exec_1 = require("../common/exec");
|
|
8
|
+
const files_1 = require("../common/files");
|
|
8
9
|
const mappings_1 = require("../common/mappings");
|
|
9
10
|
const raspberry_1 = require("../common/raspberry");
|
|
10
11
|
const memLayout = async () => {
|
|
@@ -78,8 +79,7 @@ const memLayout = async () => {
|
|
|
78
79
|
voltageMin: null,
|
|
79
80
|
voltageMax: null
|
|
80
81
|
});
|
|
81
|
-
|
|
82
|
-
let lines = stdout.split('\n');
|
|
82
|
+
let lines = await (0, files_1.readFileLines)('/proc/cpuinfo');
|
|
83
83
|
const version = (0, common_1.getValue)(lines, 'revision', ':', true).toLowerCase();
|
|
84
84
|
if (await (0, raspberry_1.isRaspberry)(lines)) {
|
|
85
85
|
result[0].type = 'LPDDR2';
|
|
@@ -8,6 +8,7 @@ const common_1 = require("../common");
|
|
|
8
8
|
const const_1 = require("../common/const");
|
|
9
9
|
const defaults_1 = require("../common/defaults");
|
|
10
10
|
const exec_1 = require("../common/exec");
|
|
11
|
+
const files_1 = require("../common/files");
|
|
11
12
|
const index_1 = require("../common/index");
|
|
12
13
|
const network_1 = require("../common/network");
|
|
13
14
|
const security_1 = require("../common/security");
|
|
@@ -51,7 +52,7 @@ const readInterfacesLines = async (file) => {
|
|
|
51
52
|
if (file.includes('*') || file.includes('?')) {
|
|
52
53
|
try {
|
|
53
54
|
const rx = new RegExp(`^${(0, node_path_1.basename)(file).replace(/\./g, '\\.').replace(/\*/g, '.*').replace(/\?/g, '.')}$`);
|
|
54
|
-
const names = (await (0, promises_1.readdir)((0, node_path_1.dirname)(file))).filter((n) => rx.test(n)).sort();
|
|
55
|
+
const names = (await (0, promises_1.readdir)((0, node_path_1.dirname)(file))).filter((n) => rx.test(n) && (0, security_1.isSafePathSegment)(n)).sort();
|
|
55
56
|
const out = [];
|
|
56
57
|
for (const n of names) {
|
|
57
58
|
out.push(...(await readInterfacesLines((0, node_path_1.join)((0, node_path_1.dirname)(file), n))));
|
|
@@ -268,35 +269,16 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
|
|
|
268
269
|
}
|
|
269
270
|
const ifaceDevName = dev.split(':')[0].trim();
|
|
270
271
|
const ifaceSanitized = (0, security_1.sanitizeString)(ifaceDevName, true);
|
|
271
|
-
const cmd = `echo -n "addr_assign_type: "; cat /sys/class/net/${ifaceSanitized}/addr_assign_type 2>/dev/null; echo;
|
|
272
|
-
echo -n "address: "; cat /sys/class/net/${ifaceSanitized}/address 2>/dev/null; echo;
|
|
273
|
-
echo -n "addr_len: "; cat /sys/class/net/${ifaceSanitized}/addr_len 2>/dev/null; echo;
|
|
274
|
-
echo -n "broadcast: "; cat /sys/class/net/${ifaceSanitized}/broadcast 2>/dev/null; echo;
|
|
275
|
-
echo -n "carrier: "; cat /sys/class/net/${ifaceSanitized}/carrier 2>/dev/null; echo;
|
|
276
|
-
echo -n "carrier_changes: "; cat /sys/class/net/${ifaceSanitized}/carrier_changes 2>/dev/null; echo;
|
|
277
|
-
echo -n "dev_id: "; cat /sys/class/net/${ifaceSanitized}/dev_id 2>/dev/null; echo;
|
|
278
|
-
echo -n "dev_port: "; cat /sys/class/net/${ifaceSanitized}/dev_port 2>/dev/null; echo;
|
|
279
|
-
echo -n "dormant: "; cat /sys/class/net/${ifaceSanitized}/dormant 2>/dev/null; echo;
|
|
280
|
-
echo -n "duplex: "; cat /sys/class/net/${ifaceSanitized}/duplex 2>/dev/null; echo;
|
|
281
|
-
echo -n "flags: "; cat /sys/class/net/${ifaceSanitized}/flags 2>/dev/null; echo;
|
|
282
|
-
echo -n "gro_flush_timeout: "; cat /sys/class/net/${ifaceSanitized}/gro_flush_timeout 2>/dev/null; echo;
|
|
283
|
-
echo -n "ifalias: "; cat /sys/class/net/${ifaceSanitized}/ifalias 2>/dev/null; echo;
|
|
284
|
-
echo -n "ifindex: "; cat /sys/class/net/${ifaceSanitized}/ifindex 2>/dev/null; echo;
|
|
285
|
-
echo -n "iflink: "; cat /sys/class/net/${ifaceSanitized}/iflink 2>/dev/null; echo;
|
|
286
|
-
echo -n "link_mode: "; cat /sys/class/net/${ifaceSanitized}/link_mode 2>/dev/null; echo;
|
|
287
|
-
echo -n "mtu: "; cat /sys/class/net/${ifaceSanitized}/mtu 2>/dev/null; echo;
|
|
288
|
-
echo -n "netdev_group: "; cat /sys/class/net/${ifaceSanitized}/netdev_group 2>/dev/null; echo;
|
|
289
|
-
echo -n "operstate: "; cat /sys/class/net/${ifaceSanitized}/operstate 2>/dev/null; echo;
|
|
290
|
-
echo -n "proto_down: "; cat /sys/class/net/${ifaceSanitized}/proto_down 2>/dev/null; echo;
|
|
291
|
-
echo -n "speed: "; cat /sys/class/net/${ifaceSanitized}/speed 2>/dev/null; echo;
|
|
292
|
-
echo -n "tx_queue_len: "; cat /sys/class/net/${ifaceSanitized}/tx_queue_len 2>/dev/null; echo;
|
|
293
|
-
echo -n "type: "; cat /sys/class/net/${ifaceSanitized}/type 2>/dev/null; echo;
|
|
294
|
-
echo -n "wireless: "; cat /proc/net/wireless 2>/dev/null | grep ${ifaceSanitized}; echo;
|
|
295
|
-
echo -n "wirelessspeed: "; iw dev ${ifaceSanitized} link 2>&1 | grep bitrate; echo;`;
|
|
296
272
|
let lines = [];
|
|
297
273
|
try {
|
|
298
|
-
const
|
|
299
|
-
|
|
274
|
+
const [sysfsLines, wirelessLines, iwOut] = await Promise.all([
|
|
275
|
+
(0, security_1.isSafePathSegment)(ifaceSanitized) ? (0, files_1.readSysfsMany)(`/sys/class/net/${ifaceSanitized}`, ['address', 'carrier_changes', 'duplex', 'mtu', 'operstate', 'speed', 'type']) : [],
|
|
276
|
+
(0, files_1.readFileLines)('/proc/net/wireless'),
|
|
277
|
+
(0, exec_1.execSecure)('iw', ['dev', ifaceSanitized, 'link'])
|
|
278
|
+
]);
|
|
279
|
+
lines = sysfsLines;
|
|
280
|
+
lines.push(`wireless: ${wirelessLines.find((line) => line.indexOf(ifaceSanitized) >= 0) || ''}`);
|
|
281
|
+
lines.push(...iwOut.split('\n').filter((line) => line.indexOf('bitrate') >= 0).map((line) => line.trim()));
|
|
300
282
|
const connectionName = getLinuxIfaceConnectionName(deviceStatus, ifaceSanitized);
|
|
301
283
|
dhcp = await getLinuxIfaceDHCPstatus(ifaceSanitized, connectionName, _dhcpNics);
|
|
302
284
|
dnsSuffix = await getLinuxIfaceDNSsuffix(connectionName);
|
|
@@ -305,7 +287,6 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
|
|
|
305
287
|
}
|
|
306
288
|
catch { }
|
|
307
289
|
duplex = (0, common_1.getValue)(lines, 'duplex');
|
|
308
|
-
duplex = duplex.startsWith('cat') ? '' : duplex;
|
|
309
290
|
mtu = (0, common_1.toInt)((0, common_1.getValue)(lines, 'mtu'));
|
|
310
291
|
let myspeed = (0, common_1.toInt)((0, common_1.getValue)(lines, 'speed'));
|
|
311
292
|
speed = Number.isNaN(myspeed) ? null : myspeed;
|
|
@@ -13,7 +13,7 @@ const networkStatsSingle = async (iface) => {
|
|
|
13
13
|
const defaults = { ...defaults_1.initNetworkSpeed, iface };
|
|
14
14
|
if (!_network[iface] || (_network[iface] && !_network[iface].ms) || (_network[iface] && _network[iface].ms && Date.now() - _network[iface].ms >= 500)) {
|
|
15
15
|
const dir = '/sys/class/net/' + iface;
|
|
16
|
-
if (
|
|
16
|
+
if ((0, security_1.isSafePathSegment)(iface) && (await (0, files_1.fileExists)(dir))) {
|
|
17
17
|
const [operstate, rx_bytes, tx_bytes, rx_dropped, rx_errors, tx_dropped, tx_errors] = await Promise.all([
|
|
18
18
|
(0, files_1.readSysfs)(dir + '/operstate'),
|
|
19
19
|
...['rx_bytes', 'tx_bytes', 'rx_dropped', 'rx_errors', 'tx_dropped', 'tx_errors'].map(async (f) => (0, common_1.toInt)(await (0, files_1.readSysfs)(dir + '/statistics/' + f)))
|
package/dist/linux/npu.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.npu = void 0;
|
|
|
4
4
|
const promises_1 = require("node:fs/promises");
|
|
5
5
|
const common_1 = require("../common");
|
|
6
6
|
const defaults_1 = require("../common/defaults");
|
|
7
|
+
const security_1 = require("../common/security");
|
|
7
8
|
const ACCEL_PATH = '/sys/class/accel';
|
|
8
9
|
const readAttr = async (path) => {
|
|
9
10
|
try {
|
|
@@ -41,7 +42,7 @@ const npu = async () => {
|
|
|
41
42
|
const result = [];
|
|
42
43
|
const seen = new Set();
|
|
43
44
|
try {
|
|
44
|
-
const nodes = (await (0, promises_1.readdir)(ACCEL_PATH)).filter((node) => node.startsWith('accel')).sort();
|
|
45
|
+
const nodes = (await (0, promises_1.readdir)(ACCEL_PATH)).filter((node) => node.startsWith('accel') && (0, security_1.isSafePathSegment)(node)).sort();
|
|
45
46
|
for (const node of nodes) {
|
|
46
47
|
let dev;
|
|
47
48
|
try {
|
package/dist/linux/os-info.js
CHANGED
|
@@ -6,9 +6,11 @@ const codepage_1 = require("../common/codepage");
|
|
|
6
6
|
const const_1 = require("../common/const");
|
|
7
7
|
const defaults_1 = require("../common/defaults");
|
|
8
8
|
const exec_1 = require("../common/exec");
|
|
9
|
+
const promises_1 = require("node:fs/promises");
|
|
9
10
|
const files_1 = require("../common/files");
|
|
10
11
|
const mappings_1 = require("../common/mappings");
|
|
11
12
|
const uuid_1 = require("./uuid");
|
|
13
|
+
const security_1 = require("../common/security");
|
|
12
14
|
const getInstallDate = async () => {
|
|
13
15
|
try {
|
|
14
16
|
const { stdout } = await (0, exec_1.exec)('stat -c %W / 2>/dev/null', const_1.execOptsLinux);
|
|
@@ -19,8 +21,8 @@ const getInstallDate = async () => {
|
|
|
19
21
|
}
|
|
20
22
|
catch { }
|
|
21
23
|
try {
|
|
22
|
-
const
|
|
23
|
-
const dev =
|
|
24
|
+
const rootMount = (await (0, files_1.readFileLines)('/proc/mounts')).filter((line) => line.split(' ')[1] === '/').pop() || '';
|
|
25
|
+
const dev = rootMount.split(' ')[0] || '';
|
|
24
26
|
if (/^\/dev\/[\w./-]+$/.test(dev)) {
|
|
25
27
|
const { stdout } = await (0, exec_1.exec)(`tune2fs -l ${dev} 2>/dev/null`, const_1.execOptsLinux);
|
|
26
28
|
const line = stdout
|
|
@@ -105,8 +107,21 @@ const osInfo = async () => {
|
|
|
105
107
|
await (0, common_1.nextTick)();
|
|
106
108
|
const defaults = (0, common_1.cloneObj)(await (0, defaults_1.initOsInfo)());
|
|
107
109
|
try {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
+
const releaseFiles = (await (0, promises_1.readdir)('/etc').catch(() => [])).filter((file) => file.endsWith('-release') && (0, security_1.isSafePathSegment)(file)).sort();
|
|
111
|
+
const files = [...releaseFiles.map((file) => `/etc/${file}`), '/usr/lib/os-release', '/etc/openwrt_release'];
|
|
112
|
+
let budget = 1024 * 1024;
|
|
113
|
+
const parts = [];
|
|
114
|
+
for (const file of files) {
|
|
115
|
+
if (budget <= 0) {
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
const content = await (0, files_1.readFileMax)(file, budget);
|
|
119
|
+
if (content) {
|
|
120
|
+
parts.push(content);
|
|
121
|
+
budget -= content.length;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return await parseOsInfo(parts.join('\n') + '\n', defaults);
|
|
110
125
|
}
|
|
111
126
|
catch { }
|
|
112
127
|
return defaults;
|
package/dist/linux/printer.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.printer = void 0;
|
|
4
|
-
const exec_1 = require("
|
|
4
|
+
const exec_1 = require("../common/exec");
|
|
5
|
+
const files_1 = require("../common/files");
|
|
5
6
|
const common_1 = require("../common");
|
|
6
7
|
const const_1 = require("../common/const");
|
|
7
8
|
const parseLinuxCupsHeader = (lines) => {
|
|
@@ -48,8 +49,7 @@ const parseLinuxLpstatPrinter = (lines, id) => {
|
|
|
48
49
|
const printer = async () => {
|
|
49
50
|
await (0, common_1.nextTick)();
|
|
50
51
|
const result = [];
|
|
51
|
-
|
|
52
|
-
const parts = stdout.toString().split('<Printer ');
|
|
52
|
+
const parts = (await (0, files_1.readFileMax)('/etc/cups/printers.conf')).split('<Printer ');
|
|
53
53
|
const printerHeader = parseLinuxCupsHeader(parts[0].split('\n'));
|
|
54
54
|
for (let i = 1; i < parts.length; i++) {
|
|
55
55
|
const printers = parseLinuxCupsPrinter(parts[i].split('\n'));
|
|
@@ -61,7 +61,7 @@ const printer = async () => {
|
|
|
61
61
|
}
|
|
62
62
|
if (result.length === 0) {
|
|
63
63
|
if (const_1.LINUX) {
|
|
64
|
-
|
|
64
|
+
const { stdout } = await (0, exec_1.execSave)('export LC_ALL=C; lpstat -lp 2>/dev/null; unset LC_ALL');
|
|
65
65
|
const parts = ('\n' + stdout.toString()).split('\nprinter ');
|
|
66
66
|
for (let i = 1; i < parts.length; i++) {
|
|
67
67
|
const printers = parseLinuxLpstatPrinter(parts[i].split('\n'), i);
|
|
@@ -6,6 +6,7 @@ const const_1 = require("../common/const");
|
|
|
6
6
|
const common_1 = require("../common");
|
|
7
7
|
const security_1 = require("../common/security");
|
|
8
8
|
const parse_1 = require("../common/parse");
|
|
9
|
+
const files_1 = require("../common/files");
|
|
9
10
|
const _process_cpu = {
|
|
10
11
|
all: 0,
|
|
11
12
|
all_utime: 0,
|
|
@@ -108,19 +109,17 @@ const processLoad = async (proc) => {
|
|
|
108
109
|
result.forEach(function (item) {
|
|
109
110
|
item.cpu = 0;
|
|
110
111
|
});
|
|
111
|
-
|
|
112
|
+
const pids = [];
|
|
112
113
|
for (const i in result) {
|
|
113
|
-
|
|
114
|
-
cmd += ';cat /proc/' + result[i].pids[j] + '/stat';
|
|
115
|
-
}
|
|
114
|
+
pids.push(...result[i].pids);
|
|
116
115
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const all = (0, parse_1.parseProcStat)(
|
|
120
|
-
curr_processes =
|
|
116
|
+
const cpuBaseline = { ..._process_cpu };
|
|
117
|
+
const stats = await (0, files_1.readProcStats)(pids);
|
|
118
|
+
const all = (0, parse_1.parseProcStat)(stats.all);
|
|
119
|
+
const curr_processes = stats.procs;
|
|
121
120
|
const list_new = {};
|
|
122
121
|
curr_processes.forEach((element) => {
|
|
123
|
-
const resultProcess = (0, parse_1.calcProcStatLinux)(element, all,
|
|
122
|
+
const resultProcess = (0, parse_1.calcProcStatLinux)(element, all, cpuBaseline);
|
|
124
123
|
if (resultProcess.pid) {
|
|
125
124
|
let resultItemId = -1;
|
|
126
125
|
for (let i = 0; i < result.length; i++) {
|
|
@@ -135,9 +134,7 @@ const processLoad = async (proc) => {
|
|
|
135
134
|
cpuu: resultProcess.cpuu,
|
|
136
135
|
cpus: resultProcess.cpus,
|
|
137
136
|
utime: resultProcess.utime,
|
|
138
|
-
stime: resultProcess.stime
|
|
139
|
-
cutime: resultProcess.cutime,
|
|
140
|
-
cstime: resultProcess.cstime
|
|
137
|
+
stime: resultProcess.stime
|
|
141
138
|
};
|
|
142
139
|
}
|
|
143
140
|
});
|
package/dist/linux/processes.js
CHANGED
|
@@ -36,71 +36,84 @@ const getName = (command) => {
|
|
|
36
36
|
}
|
|
37
37
|
return result;
|
|
38
38
|
};
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const checkColumn = (i) => {
|
|
46
|
-
offset = offset2;
|
|
47
|
-
if (parsedhead[i]) {
|
|
48
|
-
offset2 = line.substring(parsedhead[i].to + offset, 10000).indexOf(' ');
|
|
39
|
+
const splitPsLine = (line, count) => {
|
|
40
|
+
const fields = [];
|
|
41
|
+
let pos = 0;
|
|
42
|
+
while (fields.length < count) {
|
|
43
|
+
while (pos < line.length && line[pos] === ' ') {
|
|
44
|
+
pos++;
|
|
49
45
|
}
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
const start = pos;
|
|
47
|
+
while (pos < line.length && line[pos] !== ' ') {
|
|
48
|
+
pos++;
|
|
52
49
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const nice = (0, common_1.toInt)(line.substring(parsedhead[7].from + offset, parsedhead[7].to + offset2)) || 0;
|
|
70
|
-
checkColumn(8);
|
|
71
|
-
const started = !const_1.SUNOS
|
|
72
|
-
? (0, datetime_1.parseElapsedTime)(line.substring(parsedhead[8].from + offset, parsedhead[8].to + offset2).trim())
|
|
73
|
-
: (0, datetime_1.parseTimeUnix)(line.substring(parsedhead[8].from + offset, parsedhead[8].to + offset2).trim());
|
|
74
|
-
checkColumn(9);
|
|
75
|
-
let state = line.substring(parsedhead[9].from + offset, parsedhead[9].to + offset2).trim();
|
|
76
|
-
state =
|
|
77
|
-
state[0] === 'R'
|
|
78
|
-
? 'running'
|
|
79
|
-
: state[0] === 'S'
|
|
80
|
-
? 'sleeping'
|
|
81
|
-
: state[0] === 'T'
|
|
82
|
-
? 'stopped'
|
|
83
|
-
: state[0] === 'W'
|
|
84
|
-
? 'paging'
|
|
85
|
-
: state[0] === 'X'
|
|
86
|
-
? 'dead'
|
|
87
|
-
: state[0] === 'Z'
|
|
88
|
-
? 'zombie'
|
|
89
|
-
: state[0] === 'D' || state[0] === 'U'
|
|
90
|
-
? 'blocked'
|
|
91
|
-
: 'unknown';
|
|
92
|
-
checkColumn(10);
|
|
93
|
-
let tty = line.substring(parsedhead[10].from + offset, parsedhead[10].to + offset2).trim();
|
|
94
|
-
if (tty === '?' || tty === '??') {
|
|
95
|
-
tty = '';
|
|
50
|
+
if (pos === start) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
fields.push(line.substring(start, pos));
|
|
54
|
+
}
|
|
55
|
+
while (pos < line.length && line[pos] === ' ') {
|
|
56
|
+
pos++;
|
|
57
|
+
}
|
|
58
|
+
return { fields, rest: line.substring(pos) };
|
|
59
|
+
};
|
|
60
|
+
const parseCpuTime = (value) => {
|
|
61
|
+
const dayParts = value.split('-');
|
|
62
|
+
const days = dayParts.length > 1 ? (0, common_1.toInt)(dayParts[0]) : 0;
|
|
63
|
+
const parts = dayParts[dayParts.length - 1].split(':');
|
|
64
|
+
if (parts.length < 2 || parts.length > 3) {
|
|
65
|
+
return null;
|
|
96
66
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
67
|
+
const seconds = parseFloat(parts[parts.length - 1]);
|
|
68
|
+
if (Number.isNaN(seconds)) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const minutes = (0, common_1.toInt)(parts[parts.length - 2]);
|
|
72
|
+
const hours = parts.length === 3 ? (0, common_1.toInt)(parts[0]) : 0;
|
|
73
|
+
return days * 86400 + hours * 3600 + minutes * 60 + seconds;
|
|
74
|
+
};
|
|
75
|
+
const parseLine = async (line) => {
|
|
76
|
+
const split = splitPsLine(line, 13);
|
|
77
|
+
if (!split) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const [pidValue, ppidValue, cpuValue, memValue, priValue, vszValue, rssValue, niceValue, timeValue, stateValue, ttyValue, user] = split.fields;
|
|
81
|
+
const pid = (0, common_1.toInt)(pidValue);
|
|
82
|
+
if (!pid) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const ppid = (0, common_1.toInt)(ppidValue);
|
|
86
|
+
const cpu = parseFloat(cpuValue.replace(/,/g, '.'));
|
|
87
|
+
const mem = parseFloat(memValue.replace(/,/g, '.'));
|
|
88
|
+
const priority = (0, common_1.toInt)(priValue);
|
|
89
|
+
const vsz = (0, common_1.toInt)(vszValue);
|
|
90
|
+
const rss = (0, common_1.toInt)(rssValue);
|
|
91
|
+
const nice = (0, common_1.toInt)(niceValue) || 0;
|
|
92
|
+
const started = !const_1.SUNOS ? (0, datetime_1.parseElapsedTime)(timeValue) : (0, datetime_1.parseTimeUnix)(timeValue);
|
|
93
|
+
const state = stateValue[0] === 'R'
|
|
94
|
+
? 'running'
|
|
95
|
+
: stateValue[0] === 'S'
|
|
96
|
+
? 'sleeping'
|
|
97
|
+
: stateValue[0] === 'T'
|
|
98
|
+
? 'stopped'
|
|
99
|
+
: stateValue[0] === 'W'
|
|
100
|
+
? 'paging'
|
|
101
|
+
: stateValue[0] === 'X'
|
|
102
|
+
? 'dead'
|
|
103
|
+
: stateValue[0] === 'Z'
|
|
104
|
+
? 'zombie'
|
|
105
|
+
: stateValue[0] === 'D' || stateValue[0] === 'U'
|
|
106
|
+
? 'blocked'
|
|
107
|
+
: 'unknown';
|
|
108
|
+
const tty = ttyValue === '?' || ttyValue === '??' ? '' : ttyValue;
|
|
109
|
+
const cpuTime = parseCpuTime(split.fields[12]);
|
|
100
110
|
let cmdPath = '';
|
|
101
111
|
let command = '';
|
|
102
112
|
let params = '';
|
|
103
|
-
let fullcommand =
|
|
113
|
+
let fullcommand = split.rest.trim();
|
|
114
|
+
if (fullcommand.endsWith(' <defunct>')) {
|
|
115
|
+
fullcommand = fullcommand.slice(0, -10).trim();
|
|
116
|
+
}
|
|
104
117
|
if (fullcommand.endsWith(']')) {
|
|
105
118
|
fullcommand = fullcommand.slice(0, -1);
|
|
106
119
|
}
|
|
@@ -159,6 +172,7 @@ const parseLine = async (line, parsedhead) => {
|
|
|
159
172
|
cpu: cpu,
|
|
160
173
|
cpuu: 0,
|
|
161
174
|
cpus: 0,
|
|
175
|
+
cpuTime,
|
|
162
176
|
mem: mem,
|
|
163
177
|
priority: priority,
|
|
164
178
|
memVsz: vsz,
|
|
@@ -173,13 +187,13 @@ const parseLine = async (line, parsedhead) => {
|
|
|
173
187
|
path: cmdPath
|
|
174
188
|
};
|
|
175
189
|
};
|
|
176
|
-
const parseProcesses = async (lines
|
|
190
|
+
const parseProcesses = async (lines) => {
|
|
177
191
|
const result = [];
|
|
178
192
|
if (lines.length > 1) {
|
|
179
193
|
lines = lines.splice(1);
|
|
180
194
|
for (const line of lines) {
|
|
181
195
|
if (line.trim() !== '') {
|
|
182
|
-
const parsed = await parseLine(line
|
|
196
|
+
const parsed = await parseLine(line);
|
|
183
197
|
if (parsed) {
|
|
184
198
|
result.push(parsed);
|
|
185
199
|
}
|
|
@@ -252,6 +266,7 @@ const parseProcesses2 = (lines) => {
|
|
|
252
266
|
: 'unknown',
|
|
253
267
|
tty: parts[7],
|
|
254
268
|
user: parts[8],
|
|
269
|
+
cpuTime: null,
|
|
255
270
|
command: command,
|
|
256
271
|
params: '',
|
|
257
272
|
path: ''
|
|
@@ -268,42 +283,38 @@ const processes = async () => {
|
|
|
268
283
|
if ((_processes_cpu.ms && Date.now() - _processes_cpu.ms >= 500) || _processes_cpu.ms === 0) {
|
|
269
284
|
try {
|
|
270
285
|
if (const_1.LINUX || const_1.ANDROID) {
|
|
271
|
-
cmd = 'export LC_ALL=C; ps -axo pid:11,ppid:11,pcpu:6,pmem:6,pri:5,vsz:11,rss:11,ni:5,etime:30,state:5,tty:15,user:20,command; unset LC_ALL';
|
|
286
|
+
cmd = 'export LC_ALL=C; ps -axo pid:11,ppid:11,pcpu:6,pmem:6,pri:5,vsz:11,rss:11,ni:5,etime:30,state:5,tty:15,user:20,time,command; unset LC_ALL';
|
|
272
287
|
}
|
|
273
288
|
if (const_1.FREEBSD || const_1.NETBSD || const_1.OPENBSD) {
|
|
274
|
-
cmd = 'export LC_ALL=C; ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,ni,etime,state,tty,user,command; unset LC_ALL';
|
|
289
|
+
cmd = 'export LC_ALL=C; ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,ni,etime,state,tty,user,time,command; unset LC_ALL';
|
|
275
290
|
}
|
|
276
291
|
if (const_1.DARWIN) {
|
|
277
|
-
cmd = 'ps -axo pid,ppid,pcpu,pmem,pri,vsz=temp_title_1,rss=temp_title_2,nice,etime=temp_title_3,state,tty,user,command -r';
|
|
292
|
+
cmd = 'ps -axo pid,ppid,pcpu,pmem,pri,vsz=temp_title_1,rss=temp_title_2,nice,etime=temp_title_3,state,tty,user,time,command -r';
|
|
278
293
|
}
|
|
279
294
|
if (const_1.SUNOS) {
|
|
280
|
-
cmd = 'ps -Ao pid,ppid,pcpu,pmem,pri,vsz,rss,nice,stime,s,tty,user,comm';
|
|
295
|
+
cmd = 'ps -Ao pid,ppid,pcpu,pmem,pri,vsz,rss,nice,stime,s,tty,user,time,comm';
|
|
281
296
|
}
|
|
282
297
|
({ stdout } = await (0, exec_1.exec)(cmd, const_1.execOptsLinux));
|
|
283
298
|
if (stdout.trim()) {
|
|
284
299
|
const lines = stdout.split('\n');
|
|
285
|
-
|
|
286
|
-
result.list = (await parseProcesses(lines, parsedhead)).slice();
|
|
300
|
+
result.list = (await parseProcesses(lines)).slice();
|
|
287
301
|
result.all = result.list.length;
|
|
288
302
|
result.running = result.list.filter((e) => e.state === 'running').length;
|
|
289
303
|
result.blocked = result.list.filter((e) => e.state === 'blocked').length;
|
|
290
304
|
result.sleeping = result.list.filter((e) => e.state === 'sleeping').length;
|
|
291
305
|
if (const_1.LINUX) {
|
|
292
|
-
|
|
293
|
-
result.list.
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
({ stdout } = await (0, exec_1.execSave)(cmd, const_1.execOptsLinux));
|
|
297
|
-
let curr_processes = stdout.toString().split('\n');
|
|
298
|
-
const all = (0, parse_1.parseProcStat)(curr_processes[0]);
|
|
299
|
-
curr_processes = curr_processes.slice(1);
|
|
306
|
+
const cpuBaseline = { ..._processes_cpu };
|
|
307
|
+
const stats = await (0, files_1.readProcStats)(result.list.map((element) => element.pid));
|
|
308
|
+
const all = (0, parse_1.parseProcStat)(stats.all);
|
|
309
|
+
const curr_processes = stats.procs;
|
|
300
310
|
const list_new = {};
|
|
301
311
|
curr_processes.forEach((element) => {
|
|
302
|
-
const resultProcess = (0, parse_1.calcProcStatLinux)(element, all,
|
|
312
|
+
const resultProcess = (0, parse_1.calcProcStatLinux)(element, all, cpuBaseline);
|
|
303
313
|
if (resultProcess.pid) {
|
|
304
314
|
const listPos = result.list.map((e) => e.pid).indexOf(resultProcess.pid);
|
|
305
315
|
if (listPos >= 0) {
|
|
306
316
|
result.list[listPos].cpu = resultProcess.cpuu + resultProcess.cpus;
|
|
317
|
+
result.list[listPos].cpuTime = (resultProcess.utime + resultProcess.stime) / 100;
|
|
307
318
|
result.list[listPos].cpuu = resultProcess.cpuu;
|
|
308
319
|
result.list[listPos].cpus = resultProcess.cpus;
|
|
309
320
|
}
|
|
@@ -311,9 +322,7 @@ const processes = async () => {
|
|
|
311
322
|
cpuu: resultProcess.cpuu,
|
|
312
323
|
cpus: resultProcess.cpus,
|
|
313
324
|
utime: resultProcess.utime,
|
|
314
|
-
stime: resultProcess.stime
|
|
315
|
-
cutime: resultProcess.cutime,
|
|
316
|
-
cstime: resultProcess.cstime
|
|
325
|
+
stime: resultProcess.stime
|
|
317
326
|
};
|
|
318
327
|
}
|
|
319
328
|
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serialPorts = void 0;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const common_1 = require("../common");
|
|
7
|
+
const defaults_1 = require("../common/defaults");
|
|
8
|
+
const files_1 = require("../common/files");
|
|
9
|
+
const security_1 = require("../common/security");
|
|
10
|
+
const busType = (subsystem, name) => {
|
|
11
|
+
switch (subsystem) {
|
|
12
|
+
case 'usb':
|
|
13
|
+
case 'usb-serial':
|
|
14
|
+
return 'usb';
|
|
15
|
+
case 'pnp':
|
|
16
|
+
case 'amba':
|
|
17
|
+
case 'platform':
|
|
18
|
+
case 'of_serial':
|
|
19
|
+
return 'onboard';
|
|
20
|
+
case 'pci':
|
|
21
|
+
return 'pci';
|
|
22
|
+
case 'bluetooth':
|
|
23
|
+
return 'bluetooth';
|
|
24
|
+
default:
|
|
25
|
+
return name.startsWith('rfcomm') ? 'bluetooth' : 'unknown';
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const usbDevicePath = async (devicePath) => {
|
|
29
|
+
let current = devicePath;
|
|
30
|
+
for (let depth = 0; depth < 6; depth++) {
|
|
31
|
+
if (await (0, files_1.fileExists)(`${current}/idVendor`)) {
|
|
32
|
+
return current;
|
|
33
|
+
}
|
|
34
|
+
const parent = (0, path_1.dirname)(current);
|
|
35
|
+
if (parent === current) {
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
current = parent;
|
|
39
|
+
}
|
|
40
|
+
return '';
|
|
41
|
+
};
|
|
42
|
+
const stableIds = async (path) => {
|
|
43
|
+
const map = {};
|
|
44
|
+
try {
|
|
45
|
+
for (const entry of (await (0, promises_1.readdir)(path)).filter(security_1.isSafePathSegment)) {
|
|
46
|
+
try {
|
|
47
|
+
map[(0, path_1.basename)(await (0, promises_1.readlink)(`${path}/${entry}`))] = entry;
|
|
48
|
+
}
|
|
49
|
+
catch { }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch { }
|
|
53
|
+
return map;
|
|
54
|
+
};
|
|
55
|
+
const serialPorts = async (sysPath = '/sys/class/tty', byIdPath = '/dev/serial/by-id') => {
|
|
56
|
+
await (0, common_1.nextTick)();
|
|
57
|
+
const result = [];
|
|
58
|
+
let names = [];
|
|
59
|
+
try {
|
|
60
|
+
names = (await (0, promises_1.readdir)(sysPath)).filter(security_1.isSafePathSegment);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
const byId = await stableIds(byIdPath);
|
|
66
|
+
for (const name of names.sort()) {
|
|
67
|
+
let devicePath = '';
|
|
68
|
+
try {
|
|
69
|
+
devicePath = await (0, promises_1.realpath)(`${sysPath}/${name}/device`);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if ((await (0, files_1.readSysfs)(`${sysPath}/${name}/type`)) === '0') {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
let subsystem = '';
|
|
78
|
+
try {
|
|
79
|
+
subsystem = (0, path_1.basename)(await (0, promises_1.realpath)(`${devicePath}/subsystem`));
|
|
80
|
+
}
|
|
81
|
+
catch { }
|
|
82
|
+
const port = {
|
|
83
|
+
...(0, common_1.cloneObj)(defaults_1.initSerialPortResult),
|
|
84
|
+
device: `/dev/${name}`,
|
|
85
|
+
name,
|
|
86
|
+
type: busType(subsystem, name),
|
|
87
|
+
pnpId: byId[name] || null
|
|
88
|
+
};
|
|
89
|
+
const usbPath = await usbDevicePath(devicePath);
|
|
90
|
+
if (usbPath) {
|
|
91
|
+
port.type = 'usb';
|
|
92
|
+
port.vendorId = (await (0, files_1.readSysfs)(`${usbPath}/idVendor`)).toLowerCase() || null;
|
|
93
|
+
port.productId = (await (0, files_1.readSysfs)(`${usbPath}/idProduct`)).toLowerCase() || null;
|
|
94
|
+
port.manufacturer = (await (0, files_1.readSysfs)(`${usbPath}/manufacturer`)) || null;
|
|
95
|
+
port.serialNumber = (await (0, files_1.readSysfs)(`${usbPath}/serial`)) || null;
|
|
96
|
+
port.name = (await (0, files_1.readSysfs)(`${usbPath}/product`)) || name;
|
|
97
|
+
}
|
|
98
|
+
result.push(port);
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
};
|
|
102
|
+
exports.serialPorts = serialPorts;
|