systeminformation 6.0.0-beta.2 → 6.0.0-beta.21
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 +67 -18
- package/dist/bsd/mem.js +8 -3
- package/dist/bsd/network-stats.d.ts +1 -1
- package/dist/bsd/network-stats.js +14 -7
- package/dist/bsd/os-info.d.ts +1 -0
- package/dist/common/darwin.d.ts +2 -0
- package/dist/common/darwin.js +17 -1
- package/dist/common/defaults.d.ts +2 -1
- package/dist/common/defaults.js +36 -6
- package/dist/common/exec.js +29 -13
- package/dist/common/files.d.ts +9 -0
- package/dist/common/files.js +67 -3
- package/dist/common/filesys.d.ts +30 -0
- package/dist/common/filesys.js +228 -11
- package/dist/common/host.js +55 -3
- package/dist/common/internet.js +31 -20
- package/dist/common/mappings.d.ts +0 -3
- package/dist/common/mappings.js +35 -14
- package/dist/common/network.d.ts +15 -2
- package/dist/common/network.js +18 -22
- package/dist/common/nvidia.d.ts +1 -1
- package/dist/common/nvidia.js +4 -5
- package/dist/common/parse.d.ts +4 -6
- package/dist/common/parse.js +24 -69
- package/dist/common/security.d.ts +2 -0
- package/dist/common/security.js +18 -3
- package/dist/common/types.d.ts +53 -5
- package/dist/common/windows.d.ts +4 -0
- package/dist/common/windows.js +57 -1
- package/dist/cpu-current-load.d.ts +1 -0
- package/dist/cpu-current-load.js +54 -8
- package/dist/cpu-current-speed.js +5 -3
- package/dist/darwin/battery.d.ts +1 -1
- package/dist/darwin/battery.js +15 -5
- package/dist/darwin/camera.js +3 -3
- package/dist/darwin/disk-layout.js +16 -12
- package/dist/darwin/disks-io.js +3 -3
- package/dist/darwin/displays.d.ts +1 -0
- package/dist/darwin/displays.js +64 -2
- package/dist/darwin/fans.d.ts +2 -0
- package/dist/darwin/fans.js +28 -0
- package/dist/darwin/gpu.js +1 -1
- package/dist/darwin/index.d.ts +3 -0
- package/dist/darwin/index.js +8 -2
- package/dist/darwin/keyboard.js +4 -4
- package/dist/darwin/mouse.js +4 -4
- package/dist/darwin/network-interfaces.d.ts +3 -0
- package/dist/darwin/network-interfaces.js +81 -14
- package/dist/darwin/network-stats.d.ts +1 -1
- package/dist/darwin/network-stats.js +14 -7
- package/dist/darwin/os-info.d.ts +2 -0
- package/dist/darwin/os-info.js +24 -2
- package/dist/darwin/process-focused.d.ts +3 -0
- package/dist/darwin/process-focused.js +26 -0
- package/dist/darwin/serial-ports.d.ts +2 -0
- package/dist/darwin/serial-ports.js +94 -0
- package/dist/darwin/users.js +1 -1
- package/dist/docker.js +4 -5
- package/dist/fans.d.ts +1 -0
- package/dist/fans.js +17 -0
- package/dist/get-data.d.ts +4 -0
- package/dist/get-data.js +6 -2
- package/dist/get.js +6 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8 -2
- package/dist/inet-public-ip.js +2 -1
- package/dist/linux/audio.js +59 -0
- package/dist/linux/baseboard.js +9 -20
- package/dist/linux/bios.js +6 -15
- package/dist/linux/block-devices.js +3 -1
- 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 +9 -12
- package/dist/linux/disks-io.js +9 -9
- package/dist/linux/displays.d.ts +8 -0
- package/dist/linux/displays.js +151 -4
- package/dist/linux/fans.d.ts +2 -0
- package/dist/linux/fans.js +92 -0
- package/dist/linux/fs-size.d.ts +1 -1
- package/dist/linux/fs-size.js +164 -37
- package/dist/linux/fs-stats.js +6 -9
- package/dist/linux/gpu.d.ts +2 -0
- package/dist/linux/gpu.js +97 -22
- package/dist/linux/index.d.ts +3 -0
- package/dist/linux/index.js +8 -2
- package/dist/linux/mem-layout.js +3 -7
- package/dist/linux/mem.d.ts +1 -0
- package/dist/linux/mem.js +21 -1
- package/dist/linux/network-interfaces.d.ts +1 -0
- package/dist/linux/network-interfaces.js +154 -113
- package/dist/linux/network-stats.d.ts +1 -1
- package/dist/linux/network-stats.js +14 -40
- package/dist/linux/npu.js +2 -1
- package/dist/linux/os-info.js +56 -5
- package/dist/linux/printer.js +4 -4
- package/dist/linux/process-focused.d.ts +4 -0
- package/dist/linux/process-focused.js +32 -0
- package/dist/linux/process-load.js +11 -13
- package/dist/linux/processes.js +89 -80
- package/dist/linux/serial-ports.d.ts +2 -0
- package/dist/linux/serial-ports.js +102 -0
- package/dist/linux/services.js +182 -49
- package/dist/linux/system.js +1 -7
- package/dist/linux/users.js +1 -1
- package/dist/linux/uuid.js +4 -10
- package/dist/linux/wifi-networks.js +2 -2
- package/dist/network-interfaces.js +1 -1
- package/dist/observe.d.ts +1 -1
- package/dist/observe.js +5 -1
- package/dist/process-focused.d.ts +1 -0
- package/dist/process-focused.js +17 -0
- package/dist/serial-ports.d.ts +1 -0
- package/dist/serial-ports.js +17 -0
- package/dist/versions.js +34 -80
- package/dist/windows/audio.d.ts +29 -0
- package/dist/windows/audio.js +151 -11
- package/dist/windows/disk-layout.js +3 -0
- package/dist/windows/disks-io.js +3 -3
- package/dist/windows/displays.d.ts +5 -0
- package/dist/windows/displays.js +101 -16
- package/dist/windows/fans.d.ts +2 -0
- package/dist/windows/fans.js +71 -0
- package/dist/windows/fs-size.js +1 -4
- package/dist/windows/gpu.js +3 -2
- package/dist/windows/index.d.ts +3 -0
- package/dist/windows/index.js +8 -2
- package/dist/windows/network-interfaces.js +36 -41
- package/dist/windows/network-stats.js +20 -6
- package/dist/windows/process-focused.d.ts +3 -0
- package/dist/windows/process-focused.js +36 -0
- package/dist/windows/process-load.js +7 -5
- package/dist/windows/processes.d.ts +1 -0
- package/dist/windows/processes.js +54 -26
- package/dist/windows/serial-ports.d.ts +3 -0
- package/dist/windows/serial-ports.js +73 -0
- package/dist/windows/services.js +4 -1
- package/package.json +1 -1
|
@@ -34,9 +34,13 @@ const parseLinesWindowsNics = (sections, nconfigsections) => {
|
|
|
34
34
|
}
|
|
35
35
|
if (netEnabled !== '') {
|
|
36
36
|
const speed = (0, common_1.toInt)((0, common_1.getValue)(lines, 'speed', ':').trim()) / 1000000;
|
|
37
|
+
const gateway = ((0, common_1.getValue)(linesNicConfig, 'DefaultIPGateway', ':').replace(/[{}"]/g, '').split(',')[0] || '').trim();
|
|
37
38
|
nics.push({
|
|
38
39
|
mac: (0, common_1.getValue)(lines, 'MACAddress', ':').toLowerCase(),
|
|
39
40
|
dhcp: (0, common_1.getValue)(linesNicConfig, 'dhcpEnabled', ':').toLowerCase() === 'true',
|
|
41
|
+
gateway,
|
|
42
|
+
vendor: (0, common_1.getValue)(lines, 'Manufacturer', ':'),
|
|
43
|
+
model: (0, common_1.getValue)(lines, 'ProductName', ':') || (0, common_1.getValue)(lines, 'Description', ':'),
|
|
40
44
|
name: ifacename,
|
|
41
45
|
iface,
|
|
42
46
|
netEnabled: netEnabled === 'TRUE',
|
|
@@ -54,7 +58,7 @@ const parseLinesWindowsNics = (sections, nconfigsections) => {
|
|
|
54
58
|
};
|
|
55
59
|
const getWindowsNics = async () => {
|
|
56
60
|
let cmd = 'Get-CimInstance Win32_NetworkAdapter | fl *' + "; echo '#-#-#-#';";
|
|
57
|
-
cmd += 'Get-CimInstance Win32_NetworkAdapterConfiguration | fl DHCPEnabled' + '';
|
|
61
|
+
cmd += 'Get-CimInstance Win32_NetworkAdapterConfiguration | fl DHCPEnabled, DefaultIPGateway' + '';
|
|
58
62
|
try {
|
|
59
63
|
const stdout = String((await windows_1.ps.exec(cmd)) || '');
|
|
60
64
|
const data = stdout.split('#-#-#-#');
|
|
@@ -149,8 +153,8 @@ const getWindowsWiredProfilesInformation = async () => {
|
|
|
149
153
|
};
|
|
150
154
|
const getWindowsWirelessIfaceSSID = async (interfaceName) => {
|
|
151
155
|
try {
|
|
152
|
-
const { stdout } = await (0, exec_1.
|
|
153
|
-
const SSID = stdout.split('\r\n')
|
|
156
|
+
const { stdout } = await (0, exec_1.execFile)('netsh', ['wlan', 'show', 'interface', `name=${(0, security_1.sanitizeString)(interfaceName)}`], const_1.execOptsWin);
|
|
157
|
+
const SSID = String(stdout).split('\r\n').find((l) => l.includes('SSID')) || '';
|
|
154
158
|
const parseSSID = (SSID.split(':').pop() || '').trim();
|
|
155
159
|
return parseSSID;
|
|
156
160
|
}
|
|
@@ -197,11 +201,10 @@ const getWindowsIEEE8021x = async (connectionType, iface, interfaces) => {
|
|
|
197
201
|
let i8021xState = '';
|
|
198
202
|
let i8021xProtocol = '';
|
|
199
203
|
try {
|
|
200
|
-
const SSID = await getWindowsWirelessIfaceSSID(
|
|
204
|
+
const SSID = await getWindowsWirelessIfaceSSID(iface);
|
|
201
205
|
if (SSID !== 'Unknown') {
|
|
202
|
-
const
|
|
203
|
-
const
|
|
204
|
-
const profiles = stdout.split('\r\n');
|
|
206
|
+
const { stdout } = await (0, exec_1.execFile)('netsh', ['wlan', 'show', 'profiles', (0, security_1.sanitizeString)(SSID)], const_1.execOptsWin);
|
|
207
|
+
const profiles = String(stdout).split('\r\n');
|
|
205
208
|
i8021xState = (profiles.find((l) => l.indexOf('802.1X') >= 0) || '').trim();
|
|
206
209
|
i8021xProtocol = (profiles.find((l) => l.indexOf('EAP') >= 0) || '').trim();
|
|
207
210
|
}
|
|
@@ -226,7 +229,7 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
|
|
|
226
229
|
await (0, common_1.nextTick)();
|
|
227
230
|
const interfaces = (0, node_os_1.networkInterfaces)();
|
|
228
231
|
if (JSON.stringify(interfaces) === JSON.stringify(_interfaces) && !rescan) {
|
|
229
|
-
return _networkInterfaces;
|
|
232
|
+
return (0, network_1.filterDefaultInterface)(_networkInterfaces, defaultString);
|
|
230
233
|
}
|
|
231
234
|
_interfaces = (0, index_1.cloneObj)(interfaces);
|
|
232
235
|
let result = [];
|
|
@@ -234,18 +237,9 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
|
|
|
234
237
|
const defaultInterface = await (0, network_interface_default_1.networkInterfaceDefault)();
|
|
235
238
|
const nics = await getWindowsNics();
|
|
236
239
|
nics.forEach((nic) => {
|
|
237
|
-
|
|
238
|
-
Object.keys(interfaces).
|
|
239
|
-
|
|
240
|
-
(interfaces[key] || []).forEach((value) => {
|
|
241
|
-
if (Object.keys(value).indexOf('mac') >= 0) {
|
|
242
|
-
found = value['mac'] === nic.mac;
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
if (!found) {
|
|
248
|
-
interfaces[nic.name] = [{ mac: nic.mac }];
|
|
240
|
+
const name = nic.iface || nic.name;
|
|
241
|
+
if (name && !Object.keys(interfaces).some((key) => key.toLowerCase() === name.toLowerCase())) {
|
|
242
|
+
interfaces[name] = [{ mac: nic.mac }];
|
|
249
243
|
}
|
|
250
244
|
});
|
|
251
245
|
const nics8021xInfo = await getWindowsWiredProfilesInformation();
|
|
@@ -261,6 +255,9 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
|
|
|
261
255
|
let speed = 0;
|
|
262
256
|
let operstate = 'down';
|
|
263
257
|
let dhcp = false;
|
|
258
|
+
let gateway = '';
|
|
259
|
+
let vendor = '';
|
|
260
|
+
let model = '';
|
|
264
261
|
let dnsSuffix = '';
|
|
265
262
|
let ieee8021xAuth = '';
|
|
266
263
|
let ieee8021xState = '';
|
|
@@ -280,18 +277,22 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
|
|
|
280
277
|
mac = details.mac;
|
|
281
278
|
});
|
|
282
279
|
dnsSuffix = getWindowsIfaceDNSsuffix(dnsSuffixes.interfaces, ifaceSanitized);
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
280
|
+
const detail = nics.find((nic) => (nic.iface || '').toLowerCase() === dev.toLowerCase() || (nic.name || '').toLowerCase() === dev.toLowerCase()) ||
|
|
281
|
+
(mac ? nics.find((nic) => nic.mac === mac) : undefined);
|
|
282
|
+
if (detail) {
|
|
283
|
+
iface = detail.iface || iface;
|
|
284
|
+
ifaceName = detail.name;
|
|
285
|
+
dhcp = detail.dhcp;
|
|
286
|
+
gateway = detail.gateway;
|
|
287
|
+
vendor = detail.vendor;
|
|
288
|
+
model = detail.model;
|
|
289
|
+
operstate = detail.operstate;
|
|
290
|
+
speed = operstate === 'up' ? detail.speed : 0;
|
|
291
|
+
type = detail.type;
|
|
292
|
+
if (!mac) {
|
|
293
|
+
mac = detail.mac;
|
|
293
294
|
}
|
|
294
|
-
}
|
|
295
|
+
}
|
|
295
296
|
if (dev.toLowerCase().indexOf('wlan') >= 0 ||
|
|
296
297
|
ifaceName.toLowerCase().indexOf('wlan') >= 0 ||
|
|
297
298
|
ifaceName.toLowerCase().indexOf('802.11n') >= 0 ||
|
|
@@ -312,11 +313,14 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
|
|
|
312
313
|
...defaults_1.initNetworkInterface,
|
|
313
314
|
iface,
|
|
314
315
|
ifaceName,
|
|
316
|
+
vendor,
|
|
317
|
+
model,
|
|
315
318
|
default: iface === defaultInterface,
|
|
316
319
|
ip4,
|
|
317
320
|
ip4subnet,
|
|
318
321
|
ip6,
|
|
319
322
|
ip6subnet,
|
|
323
|
+
gateway,
|
|
320
324
|
mac,
|
|
321
325
|
internal,
|
|
322
326
|
virtual,
|
|
@@ -332,15 +336,6 @@ const networkInterfaces = async (defaultString = '', rescan = true) => {
|
|
|
332
336
|
}
|
|
333
337
|
catch { }
|
|
334
338
|
_networkInterfaces = result;
|
|
335
|
-
|
|
336
|
-
result = result.filter((item) => item.default);
|
|
337
|
-
if (result.length > 0) {
|
|
338
|
-
return [result[0]];
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
return [];
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
return result;
|
|
339
|
+
return (0, network_1.filterDefaultInterface)(result, defaultString);
|
|
345
340
|
};
|
|
346
341
|
exports.networkInterfaces = networkInterfaces;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.networkStats = void 0;
|
|
4
|
-
const index_1 = require("./index");
|
|
5
4
|
const common_1 = require("../common");
|
|
6
5
|
const defaults_1 = require("../common/defaults");
|
|
7
6
|
const network_1 = require("../common/network");
|
|
8
7
|
const security_1 = require("../common/security");
|
|
9
8
|
const windows_1 = require("../common/windows");
|
|
10
|
-
const
|
|
9
|
+
const index_1 = require("./index");
|
|
10
|
+
const _network = Object.create(null);
|
|
11
11
|
const parseLinesWindowsPerfData = (sections) => {
|
|
12
12
|
const perfData = [];
|
|
13
13
|
for (const i in sections) {
|
|
@@ -20,9 +20,11 @@ const parseLinesWindowsPerfData = (sections) => {
|
|
|
20
20
|
.replace(/#|\//g, '_')
|
|
21
21
|
.toLowerCase(),
|
|
22
22
|
rx_bytes: (0, common_1.toInt)((0, common_1.getValue)(lines, 'ReceivedBytes', ':')),
|
|
23
|
+
rx_packets: (0, common_1.toInt)((0, common_1.getValue)(lines, 'ReceivedUnicastPackets', ':')) + (0, common_1.toInt)((0, common_1.getValue)(lines, 'ReceivedMulticastPackets', ':')) + (0, common_1.toInt)((0, common_1.getValue)(lines, 'ReceivedBroadcastPackets', ':')),
|
|
23
24
|
rx_errors: (0, common_1.toInt)((0, common_1.getValue)(lines, 'ReceivedPacketErrors', ':')),
|
|
24
25
|
rx_dropped: (0, common_1.toInt)((0, common_1.getValue)(lines, 'ReceivedDiscardedPackets', ':')),
|
|
25
26
|
tx_bytes: (0, common_1.toInt)((0, common_1.getValue)(lines, 'SentBytes', ':')),
|
|
27
|
+
tx_packets: (0, common_1.toInt)((0, common_1.getValue)(lines, 'SentUnicastPackets', ':')) + (0, common_1.toInt)((0, common_1.getValue)(lines, 'SentMulticastPackets', ':')) + (0, common_1.toInt)((0, common_1.getValue)(lines, 'SentBroadcastPackets', ':')),
|
|
26
28
|
tx_errors: (0, common_1.toInt)((0, common_1.getValue)(lines, 'OutboundPacketErrors', ':')),
|
|
27
29
|
tx_dropped: (0, common_1.toInt)((0, common_1.getValue)(lines, 'OutboundDiscardedPackets', ':'))
|
|
28
30
|
});
|
|
@@ -32,19 +34,22 @@ const parseLinesWindowsPerfData = (sections) => {
|
|
|
32
34
|
};
|
|
33
35
|
const networkStatsSingle = async (iface) => {
|
|
34
36
|
await (0, common_1.nextTick)();
|
|
35
|
-
const defaults = defaults_1.initNetworkSpeed;
|
|
37
|
+
const defaults = { ...defaults_1.initNetworkSpeed, iface };
|
|
36
38
|
if (!_network[iface] || (_network[iface] && !_network[iface].ms) || (_network[iface] && _network[iface].ms && Date.now() - _network[iface].ms >= 500)) {
|
|
37
39
|
let operstate = 'unknown';
|
|
38
40
|
let rx_bytes = 0;
|
|
39
41
|
let tx_bytes = 0;
|
|
42
|
+
let rx_packets = 0;
|
|
43
|
+
let tx_packets = 0;
|
|
40
44
|
let rx_dropped = 0;
|
|
41
45
|
let rx_errors = 0;
|
|
42
46
|
let tx_dropped = 0;
|
|
43
47
|
let tx_errors = 0;
|
|
44
48
|
let perfData = [];
|
|
45
49
|
let ifaceName = iface;
|
|
50
|
+
let found = false;
|
|
46
51
|
try {
|
|
47
|
-
const stdout = String((await windows_1.ps.exec('Get-NetAdapterStatistics | select Name,InterfaceDescription,ReceivedBytes,ReceivedPacketErrors,ReceivedDiscardedPackets,SentBytes,OutboundPacketErrors,OutboundDiscardedPackets | fl')) || '');
|
|
52
|
+
const stdout = String((await windows_1.ps.exec('Get-NetAdapterStatistics | select Name,InterfaceDescription,ReceivedBytes,ReceivedUnicastPackets,ReceivedMulticastPackets,ReceivedBroadcastPackets,ReceivedPacketErrors,ReceivedDiscardedPackets,SentBytes,SentUnicastPackets,SentMulticastPackets,SentBroadcastPackets,OutboundPacketErrors,OutboundDiscardedPackets | fl')) || '');
|
|
48
53
|
if (stdout) {
|
|
49
54
|
const psections = stdout.split(/\n\s*\n/);
|
|
50
55
|
perfData = parseLinesWindowsPerfData(psections);
|
|
@@ -73,19 +78,26 @@ const networkStatsSingle = async (iface) => {
|
|
|
73
78
|
.replace(/[()[\] ]+/g, '')
|
|
74
79
|
.replace(/#|\//g, '_')
|
|
75
80
|
.toLowerCase() === detail.desc)) {
|
|
81
|
+
found = true;
|
|
76
82
|
ifaceName = det.iface;
|
|
77
83
|
rx_bytes = detail.rx_bytes;
|
|
84
|
+
rx_packets = detail.rx_packets;
|
|
78
85
|
rx_dropped = detail.rx_dropped;
|
|
79
86
|
rx_errors = detail.rx_errors;
|
|
80
87
|
tx_bytes = detail.tx_bytes;
|
|
88
|
+
tx_packets = detail.tx_packets;
|
|
81
89
|
tx_dropped = detail.tx_dropped;
|
|
82
90
|
tx_errors = detail.tx_errors;
|
|
83
91
|
operstate = det.operstate;
|
|
84
92
|
}
|
|
85
93
|
});
|
|
86
94
|
});
|
|
87
|
-
if (
|
|
88
|
-
|
|
95
|
+
if (found) {
|
|
96
|
+
const stats = (0, network_1.calcNetworkSpeed)({ iface: ifaceName, rx_bytes, tx_bytes, rx_packets, tx_packets, rx_dropped, rx_errors, tx_dropped, tx_errors, operstate }, _network);
|
|
97
|
+
if (ifaceName !== iface) {
|
|
98
|
+
_network[iface] = _network[ifaceName];
|
|
99
|
+
}
|
|
100
|
+
return stats;
|
|
89
101
|
}
|
|
90
102
|
return defaults;
|
|
91
103
|
}
|
|
@@ -94,6 +106,8 @@ const networkStatsSingle = async (iface) => {
|
|
|
94
106
|
...defaults,
|
|
95
107
|
rx_bytes: _network[iface].rx_bytes,
|
|
96
108
|
tx_bytes: _network[iface].tx_bytes,
|
|
109
|
+
rx_packets: _network[iface].rx_packets,
|
|
110
|
+
tx_packets: _network[iface].tx_packets,
|
|
97
111
|
rx_sec: _network[iface].rx_sec,
|
|
98
112
|
tx_sec: _network[iface].tx_sec,
|
|
99
113
|
rx_dropped: _network[iface].rx_dropped,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processFocused = exports.parseWindowsFocused = void 0;
|
|
4
|
+
const windows_1 = require("../common/windows");
|
|
5
|
+
const WIN_FOREGROUND = `if (-not ([System.Management.Automation.PSTypeName]'SI.Win').Type) { Add-Type -Namespace SI -Name Win -MemberDefinition '` +
|
|
6
|
+
'[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); ' +
|
|
7
|
+
'[DllImport("user32.dll")] public static extern int GetWindowThreadProcessId(IntPtr hWnd, out int pid);' +
|
|
8
|
+
`' }; ` +
|
|
9
|
+
'$p = 0; [void][SI.Win]::GetWindowThreadProcessId([SI.Win]::GetForegroundWindow(), [ref]$p); ' +
|
|
10
|
+
'$proc = Get-Process -Id $p -ErrorAction SilentlyContinue; ' +
|
|
11
|
+
'[PSCustomObject]@{pid=$p;name=$proc.ProcessName;path=$proc.Path} | ConvertTo-Json -compress';
|
|
12
|
+
const parseWindowsFocused = (data) => {
|
|
13
|
+
let parsed = data;
|
|
14
|
+
if (typeof parsed === 'string') {
|
|
15
|
+
try {
|
|
16
|
+
parsed = JSON.parse(parsed);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (!parsed || !parsed.pid) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
return { pid: parsed.pid, name: parsed.name || '', path: parsed.path || '' };
|
|
26
|
+
};
|
|
27
|
+
exports.parseWindowsFocused = parseWindowsFocused;
|
|
28
|
+
const processFocused = async () => {
|
|
29
|
+
try {
|
|
30
|
+
return (0, exports.parseWindowsFocused)(await windows_1.ps.exec(WIN_FOREGROUND));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.processFocused = processFocused;
|
|
@@ -20,20 +20,22 @@ const processLoad = async (proc) => {
|
|
|
20
20
|
if (!(0, security_1.isPrototypePolluted)()) {
|
|
21
21
|
const processes = (0, security_1.sanitizeServiceString)(proc);
|
|
22
22
|
if (processes.length) {
|
|
23
|
+
const cpuBaseline = { ..._process_cpu };
|
|
23
24
|
try {
|
|
24
25
|
const processArray = (0, windows_1.psArray)(await windows_1.ps.exec('Get-CimInstance Win32_Process | select ProcessId,Caption,UserModeTime,KernelModeTime,WorkingSetSize | ConvertTo-Json -compress'));
|
|
25
26
|
const procStats = [];
|
|
26
27
|
const list_new = {};
|
|
27
|
-
let allcpuu =
|
|
28
|
-
let allcpus =
|
|
28
|
+
let allcpuu = cpuBaseline.all_utime;
|
|
29
|
+
let allcpus = cpuBaseline.all_stime;
|
|
29
30
|
processArray.forEach((element) => {
|
|
30
31
|
const pid = element.ProcessId;
|
|
31
32
|
const name = element.Caption;
|
|
32
33
|
const utime = element.UserModeTime;
|
|
33
34
|
const stime = element.KernelModeTime;
|
|
34
35
|
const mem = element.WorkingSetSize;
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
const cpuOld = cpuBaseline.list[pid];
|
|
37
|
+
allcpuu += utime - (cpuOld ? cpuOld.utime : 0);
|
|
38
|
+
allcpus += stime - (cpuOld ? cpuOld.stime : 0);
|
|
37
39
|
procStats.push({
|
|
38
40
|
pid: pid,
|
|
39
41
|
name,
|
|
@@ -89,7 +91,7 @@ const processLoad = async (proc) => {
|
|
|
89
91
|
});
|
|
90
92
|
}
|
|
91
93
|
procStats.forEach((element) => {
|
|
92
|
-
const resultProcess = (0, processes_1.calcProcStatWin)(element, allcpuu + allcpus,
|
|
94
|
+
const resultProcess = (0, processes_1.calcProcStatWin)(element, allcpuu + allcpus, cpuBaseline);
|
|
93
95
|
let listPos = -1;
|
|
94
96
|
for (let j = 0; j < result.length; j++) {
|
|
95
97
|
if (result[j].pid === resultProcess.pid || result[j].pids.indexOf(resultProcess.pid) >= 0) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CpuData, ProcessesData, ProcStatData } from '../common/types';
|
|
2
|
+
export declare const processStateWin: (running: number, waiting: number, suspended: number) => "unknown" | "running" | "blocked" | "sleeping";
|
|
2
3
|
export declare const calcProcStatWin: (procStat: ProcStatData, all: number, _cpu_old: CpuData) => {
|
|
3
4
|
pid: number;
|
|
4
5
|
utime: number;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.processes = exports.calcProcStatWin = void 0;
|
|
3
|
+
exports.processes = exports.calcProcStatWin = exports.processStateWin = void 0;
|
|
4
4
|
const node_os_1 = require("node:os");
|
|
5
5
|
const common_1 = require("../common");
|
|
6
6
|
const defaults_1 = require("../common/defaults");
|
|
7
|
-
const mappings_1 = require("../common/mappings");
|
|
8
7
|
const windows_1 = require("../common/windows");
|
|
8
|
+
const parse_1 = require("../common/parse");
|
|
9
9
|
const _processes_cpu = {
|
|
10
10
|
all: 0,
|
|
11
11
|
all_utime: 0,
|
|
@@ -14,23 +14,51 @@ const _processes_cpu = {
|
|
|
14
14
|
ms: 0,
|
|
15
15
|
result: {}
|
|
16
16
|
};
|
|
17
|
+
const processStateWin = (running, waiting, suspended) => {
|
|
18
|
+
if (running > 0) {
|
|
19
|
+
return 'running';
|
|
20
|
+
}
|
|
21
|
+
if (waiting > 0) {
|
|
22
|
+
return 'sleeping';
|
|
23
|
+
}
|
|
24
|
+
if (suspended > 0) {
|
|
25
|
+
return 'blocked';
|
|
26
|
+
}
|
|
27
|
+
return 'unknown';
|
|
28
|
+
};
|
|
29
|
+
exports.processStateWin = processStateWin;
|
|
30
|
+
const WIN_THREAD_STATES = 'Get-Process -ErrorAction SilentlyContinue | ForEach-Object { $r=0;$w=0;$u=0; try { foreach ($t in $_.Threads) { $s=[int]$t.ThreadState; ' +
|
|
31
|
+
'if ($s -eq 1 -or $s -eq 2 -or $s -eq 3 -or $s -eq 6) { $r++ } elseif ($s -eq 5) { if ([int]$t.WaitReason -eq 5) { $u++ } else { $w++ } } } } catch {}; ' +
|
|
32
|
+
'[PSCustomObject]@{i=$_.Id;r=$r;w=$w;u=$u} } | ConvertTo-Json -compress';
|
|
33
|
+
const getWindowsProcessStates = async () => {
|
|
34
|
+
const result = {};
|
|
35
|
+
try {
|
|
36
|
+
for (const entry of (0, windows_1.psArray)(await windows_1.ps.exec(WIN_THREAD_STATES))) {
|
|
37
|
+
result[entry.i] = (0, exports.processStateWin)(entry.r || 0, entry.w || 0, entry.u || 0);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch { }
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
17
43
|
const calcProcStatWin = (procStat, all, _cpu_old) => {
|
|
18
44
|
let cpuu = 0;
|
|
19
45
|
let cpus = 0;
|
|
20
46
|
if (_cpu_old.all > 0 && _cpu_old.list[procStat.pid]) {
|
|
21
|
-
|
|
22
|
-
|
|
47
|
+
const delta = all - _cpu_old.all;
|
|
48
|
+
cpuu = delta > 0 ? ((procStat.utime - _cpu_old.list[procStat.pid].utime) / delta) * 100 : 0;
|
|
49
|
+
cpus = delta > 0 ? ((procStat.stime - _cpu_old.list[procStat.pid].stime) / delta) * 100 : 0;
|
|
23
50
|
}
|
|
24
51
|
else {
|
|
25
|
-
cpuu = (procStat.utime / all) * 100;
|
|
26
|
-
cpus = (procStat.stime / all) * 100;
|
|
52
|
+
cpuu = all > 0 ? (procStat.utime / all) * 100 : 0;
|
|
53
|
+
cpus = all > 0 ? (procStat.stime / all) * 100 : 0;
|
|
27
54
|
}
|
|
55
|
+
const clamped = (0, parse_1.clampCpuPair)(cpuu, cpus);
|
|
28
56
|
return {
|
|
29
57
|
pid: procStat.pid,
|
|
30
58
|
utime: procStat.utime,
|
|
31
59
|
stime: procStat.stime,
|
|
32
|
-
cpuu: cpuu
|
|
33
|
-
cpus: cpus
|
|
60
|
+
cpuu: clamped.cpuu,
|
|
61
|
+
cpus: clamped.cpus
|
|
34
62
|
};
|
|
35
63
|
};
|
|
36
64
|
exports.calcProcStatWin = calcProcStatWin;
|
|
@@ -38,37 +66,33 @@ const processes = async () => {
|
|
|
38
66
|
await (0, common_1.nextTick)();
|
|
39
67
|
const result = (0, common_1.cloneObj)(defaults_1.initProcesses);
|
|
40
68
|
if ((_processes_cpu.ms && Date.now() - _processes_cpu.ms >= 500) || _processes_cpu.ms === 0) {
|
|
69
|
+
const cpuBaseline = { ..._processes_cpu };
|
|
41
70
|
try {
|
|
42
|
-
const
|
|
43
|
-
|
|
71
|
+
const [processList, states] = await Promise.all([
|
|
72
|
+
windows_1.ps.exec(`Get-CimInstance Win32_Process | select-Object ProcessId,ParentProcessId,Caption,CommandLine,ExecutablePath,UserModeTime,KernelModeTime,WorkingSetSize,Priority,PageFileUsage,
|
|
73
|
+
@{n="CreationDate";e={$_.CreationDate.ToString("yyyy-MM-dd HH:mm:ss")}} | ConvertTo-Json -compress`),
|
|
74
|
+
getWindowsProcessStates()
|
|
75
|
+
]);
|
|
76
|
+
const processArray = (0, windows_1.psArray)(processList);
|
|
44
77
|
if (processArray.length) {
|
|
45
78
|
const procs = [];
|
|
46
79
|
const procStats = [];
|
|
47
80
|
const list_new = {};
|
|
48
|
-
let allcpuu =
|
|
49
|
-
let allcpus =
|
|
81
|
+
let allcpuu = cpuBaseline.all_utime;
|
|
82
|
+
let allcpus = cpuBaseline.all_stime;
|
|
50
83
|
processArray.forEach((element) => {
|
|
51
84
|
const pid = element.ProcessId;
|
|
52
85
|
const parentPid = element.ParentProcessId;
|
|
53
|
-
const statusValue = element.ExecutionState || null;
|
|
54
86
|
const name = element.Caption;
|
|
55
87
|
const commandLine = element.CommandLine;
|
|
56
88
|
const commandPath = element.ExecutablePath;
|
|
57
89
|
const utime = element.UserModeTime;
|
|
58
90
|
const stime = element.KernelModeTime;
|
|
59
91
|
const memw = element.WorkingSetSize;
|
|
60
|
-
|
|
61
|
-
|
|
92
|
+
const cpuOld = cpuBaseline.list[pid];
|
|
93
|
+
allcpuu += utime - (cpuOld ? cpuOld.utime : 0);
|
|
94
|
+
allcpus += stime - (cpuOld ? cpuOld.stime : 0);
|
|
62
95
|
result.all++;
|
|
63
|
-
if (!statusValue) {
|
|
64
|
-
result.unknown++;
|
|
65
|
-
}
|
|
66
|
-
if (statusValue === 3) {
|
|
67
|
-
result.running++;
|
|
68
|
-
}
|
|
69
|
-
if (statusValue === 4 || statusValue === 5) {
|
|
70
|
-
result.blocked++;
|
|
71
|
-
}
|
|
72
96
|
procStats.push({
|
|
73
97
|
pid: pid,
|
|
74
98
|
name: '',
|
|
@@ -85,13 +109,14 @@ const processes = async () => {
|
|
|
85
109
|
cpu: 0,
|
|
86
110
|
cpuu: 0,
|
|
87
111
|
cpus: 0,
|
|
112
|
+
cpuTime: (utime + stime) / 1e7,
|
|
88
113
|
mem: (memw / (0, node_os_1.totalmem)()) * 100,
|
|
89
114
|
priority: element.Priority || 0,
|
|
90
115
|
memVsz: element.PageFileUsage || null,
|
|
91
116
|
memRss: Math.floor((element.WorkingSetSize || 0) / 1024),
|
|
92
117
|
nice: 0,
|
|
93
118
|
started: element.CreationDate,
|
|
94
|
-
state:
|
|
119
|
+
state: states[pid] || 'unknown',
|
|
95
120
|
tty: '',
|
|
96
121
|
user: '',
|
|
97
122
|
command: commandLine || name,
|
|
@@ -99,10 +124,13 @@ const processes = async () => {
|
|
|
99
124
|
params: ''
|
|
100
125
|
});
|
|
101
126
|
});
|
|
127
|
+
result.running = procs.filter((proc) => proc.state === 'running').length;
|
|
128
|
+
result.blocked = procs.filter((proc) => proc.state === 'blocked').length;
|
|
129
|
+
result.unknown = procs.filter((proc) => proc.state === 'unknown').length;
|
|
102
130
|
result.sleeping = result.all - result.running - result.blocked - result.unknown;
|
|
103
131
|
result.list = procs;
|
|
104
132
|
procStats.forEach((element) => {
|
|
105
|
-
const resultProcess = (0, exports.calcProcStatWin)(element, allcpuu + allcpus,
|
|
133
|
+
const resultProcess = (0, exports.calcProcStatWin)(element, allcpuu + allcpus, cpuBaseline);
|
|
106
134
|
const listPos = result.list
|
|
107
135
|
.map((e) => {
|
|
108
136
|
return e.pid;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serialPorts = exports.parseSerialPorts = void 0;
|
|
4
|
+
const common_1 = require("../common");
|
|
5
|
+
const defaults_1 = require("../common/defaults");
|
|
6
|
+
const windows_1 = require("../common/windows");
|
|
7
|
+
const matchId = (deviceId, key) => {
|
|
8
|
+
const match = new RegExp(`${key}_([0-9A-Fa-f]{4})`).exec(deviceId);
|
|
9
|
+
return match?.[1] ? match[1].toLowerCase() : null;
|
|
10
|
+
};
|
|
11
|
+
const parseSerial = (deviceId) => {
|
|
12
|
+
const ftdi = /PID_[0-9A-Fa-f]{4}\+([^+\\]+)/.exec(deviceId);
|
|
13
|
+
if (ftdi?.[1]) {
|
|
14
|
+
return ftdi[1];
|
|
15
|
+
}
|
|
16
|
+
const last = deviceId.split('\\').pop() || '';
|
|
17
|
+
return last && !last.includes('&') ? last : null;
|
|
18
|
+
};
|
|
19
|
+
const parseType = (deviceId) => {
|
|
20
|
+
const id = deviceId.toUpperCase();
|
|
21
|
+
if (id.startsWith('USB\\') || id.startsWith('FTDIBUS\\')) {
|
|
22
|
+
return 'usb';
|
|
23
|
+
}
|
|
24
|
+
if (id.startsWith('BTHENUM') || id.startsWith('BTHLE')) {
|
|
25
|
+
return 'bluetooth';
|
|
26
|
+
}
|
|
27
|
+
if (id.startsWith('PCI\\')) {
|
|
28
|
+
return 'pci';
|
|
29
|
+
}
|
|
30
|
+
if (id.startsWith('ACPI\\')) {
|
|
31
|
+
return 'onboard';
|
|
32
|
+
}
|
|
33
|
+
if (id.startsWith('ROOT\\') || id.startsWith('SW\\') || id.startsWith('UMB\\')) {
|
|
34
|
+
return 'virtual';
|
|
35
|
+
}
|
|
36
|
+
return 'unknown';
|
|
37
|
+
};
|
|
38
|
+
const parseSerialPorts = (devices) => {
|
|
39
|
+
const result = [];
|
|
40
|
+
for (const device of devices) {
|
|
41
|
+
const name = (device.Name || '').trim();
|
|
42
|
+
const port = /\((COM\d+)\)/.exec(name);
|
|
43
|
+
if (!port?.[1]) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const deviceId = device.DeviceID || device.PNPDeviceID || '';
|
|
47
|
+
const type = parseType(deviceId);
|
|
48
|
+
result.push({
|
|
49
|
+
...(0, common_1.cloneObj)(defaults_1.initSerialPortResult),
|
|
50
|
+
device: port[1],
|
|
51
|
+
name: name.replace(/\s*\(COM\d+\)\s*$/, '') || port[1],
|
|
52
|
+
manufacturer: (device.Manufacturer || '').trim() || null,
|
|
53
|
+
serialNumber: type === 'usb' ? parseSerial(deviceId) : null,
|
|
54
|
+
vendorId: matchId(deviceId, 'VID'),
|
|
55
|
+
productId: matchId(deviceId, 'PID'),
|
|
56
|
+
pnpId: deviceId || null,
|
|
57
|
+
type
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
};
|
|
62
|
+
exports.parseSerialPorts = parseSerialPorts;
|
|
63
|
+
const serialPorts = async () => {
|
|
64
|
+
await (0, common_1.nextTick)();
|
|
65
|
+
try {
|
|
66
|
+
const result = await windows_1.ps.exec(`@(Get-CimInstance Win32_PnPEntity -Filter "Name LIKE '%(COM%'" | Select-Object Name,DeviceID,Manufacturer) | ConvertTo-Json -Depth 3`);
|
|
67
|
+
return (0, exports.parseSerialPorts)((0, windows_1.psArray)(result));
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
exports.serialPorts = serialPorts;
|
package/dist/windows/services.js
CHANGED
|
@@ -15,7 +15,7 @@ const services = async (srv) => {
|
|
|
15
15
|
if (srvs[0] !== '*') {
|
|
16
16
|
wincommand += ' -Filter "';
|
|
17
17
|
srvs.forEach((srv) => {
|
|
18
|
-
wincommand += `Name='${srv}' or `;
|
|
18
|
+
wincommand += `Name='${srv.replace(/[^a-zA-Z0-9 _.\-@]/g, '')}' or `;
|
|
19
19
|
});
|
|
20
20
|
wincommand = `${wincommand.slice(0, -4)}"`;
|
|
21
21
|
}
|
|
@@ -36,6 +36,7 @@ const services = async (srv) => {
|
|
|
36
36
|
name: srvName,
|
|
37
37
|
running: started.toLowerCase() === 'true',
|
|
38
38
|
startmode: startMode,
|
|
39
|
+
lastChanged: null,
|
|
39
40
|
pids: [pid],
|
|
40
41
|
cpu: 0,
|
|
41
42
|
mem: 0
|
|
@@ -54,6 +55,7 @@ const services = async (srv) => {
|
|
|
54
55
|
name: srvName,
|
|
55
56
|
running: false,
|
|
56
57
|
startmode: '',
|
|
58
|
+
lastChanged: null,
|
|
57
59
|
pids: [],
|
|
58
60
|
cpu: 0,
|
|
59
61
|
mem: 0
|
|
@@ -68,6 +70,7 @@ const services = async (srv) => {
|
|
|
68
70
|
name: srvName,
|
|
69
71
|
running: false,
|
|
70
72
|
startmode: '',
|
|
73
|
+
lastChanged: null,
|
|
71
74
|
pids: [],
|
|
72
75
|
cpu: 0,
|
|
73
76
|
mem: 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "systeminformation",
|
|
3
|
-
"version": "6.0.0-beta.
|
|
3
|
+
"version": "6.0.0-beta.21",
|
|
4
4
|
"description": "Advanced, lightweight system and OS information library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",
|