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/README.md
CHANGED
|
@@ -49,6 +49,8 @@ in a browser.
|
|
|
49
49
|
- `npu()` - detected NPUs / AI accelerators (experimental)
|
|
50
50
|
- `software()` - installed software / applications
|
|
51
51
|
- `npm()` - globally installed npm packages
|
|
52
|
+
- `fans()` - detected fans with rpm and pwm
|
|
53
|
+
- `serialPorts()` - detected serial / COM ports
|
|
52
54
|
|
|
53
55
|
### Extended Windows support
|
|
54
56
|
|
|
@@ -163,7 +165,7 @@ implementations can be tree-shaken away.
|
|
|
163
165
|
|
|
164
166
|
- complete rewrite in TypeScript with typed declarations for every function
|
|
165
167
|
- modular imports: load the whole library, a single operating system, or a single function
|
|
166
|
-
- new functions: `camera()`, `keyboard()`, `mouse()`, `thunderbolt()`, `pci()`, `npu()`, `software()`, `npm()`
|
|
168
|
+
- new functions: `camera()`, `keyboard()`, `mouse()`, `thunderbolt()`, `pci()`, `npu()`, `software()`, `npm()`, `fans()`, `serialPorts()`
|
|
167
169
|
- extended Windows support: `disksIO()`, `fsStats()`, `fsOpenFiles()`, `thunderbolt()`
|
|
168
170
|
- `time()` and `version()` are now asynchronous - all functions are async (async/await preferred, promises as alternative)
|
|
169
171
|
- callbacks are no longer supported
|
|
@@ -478,6 +480,7 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
|
|
|
478
480
|
| | ...[0].cpu | X | X | X | X | X | process % CPU usage |
|
|
479
481
|
| | ...[0].cpuu | X | X | | X | | process % CPU usage (user) |
|
|
480
482
|
| | ...[0].cpus | X | X | | X | | process % CPU usage (system) |
|
|
483
|
+
| | ...[0].cpuTime | X | X | X | X | X | process cpu time in seconds (own, without reaped children); null if not available |
|
|
481
484
|
| | ...[0].mem | X | X | X | X | X | process memory % |
|
|
482
485
|
| | ...[0].priority | X | X | X | X | X | process priority |
|
|
483
486
|
| | ...[0].memVsz | X | X | X | X | X | process virtual memory size |
|
|
@@ -616,6 +619,15 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
|
|
|
616
619
|
| | [0].maxPower | X | | | | | max power |
|
|
617
620
|
| | [0].default | X | | X | X | | is default printer |
|
|
618
621
|
| | [0].serialNumber | | | X | | | serial number |
|
|
622
|
+
| si.serialPorts() | [{...}] | X | | X | X | | detected serial / COM ports |
|
|
623
|
+
| | [0].device | X | | X | X | | device path (COMx on Windows) |
|
|
624
|
+
| | [0].name | X | | X | X | | product / friendly name |
|
|
625
|
+
| | [0].manufacturer | X | | X | X | | manufacturer |
|
|
626
|
+
| | [0].serialNumber | X | | X | X | | serial number (USB only) |
|
|
627
|
+
| | [0].vendorId | X | | X | X | | vendor id (hex) |
|
|
628
|
+
| | [0].productId | X | | X | X | | product id (hex) |
|
|
629
|
+
| | [0].pnpId | X | | | X | | stable id (by-id / DeviceID) |
|
|
630
|
+
| | [0].type | X | | X | X | | usb, onboard, pci, bluetooth |
|
|
619
631
|
|
|
620
632
|
#### 11. Devices
|
|
621
633
|
|
|
@@ -1017,6 +1029,10 @@ and - as soon as the package exposes them - the fan speeds in `fans()`.
|
|
|
1017
1029
|
|
|
1018
1030
|
Windows itself does not expose actual fan speeds: `Win32_Fan` only reports that a fan exists, its `DesiredSpeed` is the *requested* speed and is left empty by virtually every mainboard. Real values are read from a running [LibreHardwareMonitor](https://github.com/LibreHardwareMonitor/LibreHardwareMonitor) or OpenHardwareMonitor, which publish their sensors in an own WMI namespace. Without one of these tools running, `fans()` returns an empty array or entries without `rpm`.
|
|
1019
1031
|
|
|
1032
|
+
#### Serial Ports
|
|
1033
|
+
|
|
1034
|
+
`serialPorts()` only *enumerates* ports - opening one (baud rate, termios, RTS toggling) needs a native binding and is out of scope for this zero-dependency library. Two things worth knowing: on Linux a port shows up in the list even when your user is not in the `dialout` / `uucp` group, so listing can succeed while opening fails; on Windows the `COMx` number is reassigned per USB port, so `pnpId` is the only stable key. RS-232 and RS-485 cannot be told apart by enumeration - an RS-485 transceiver looks like an ordinary UART to the operating system - so no such information is reported.
|
|
1035
|
+
|
|
1020
1036
|
#### Windows Temperature, Battery, ...
|
|
1021
1037
|
|
|
1022
1038
|
`get-WmiObject` - which is used to determine temperature and battery sometimes needs to be run with admin
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { AudioData, BaseboardData, BatteryObject, BiosData, ChassisData, CpuCacheData, CpuObject, CpuTemperatureObject, DisksIoData, DisplayData, FsBlockDevicesData, FsOpenFilesData, FsStatsData, InetChecksiteData, MemData, NetworkInterfacesData, NetworkStatsData, NpuData, OsData, PciData, ProcessesData, SystemData, UsbData, UuidData } from './types';
|
|
1
|
+
import type { AudioData, BaseboardData, BatteryObject, BiosData, ChassisData, CpuCacheData, CpuObject, CpuTemperatureObject, DisksIoData, DisplayData, FsBlockDevicesData, FsOpenFilesData, FsStatsData, InetChecksiteData, MemData, NetworkInterfacesData, NetworkStatsData, NpuData, OsData, PciData, ProcessesData, SerialPortData, SystemData, UsbData, UuidData } from './types';
|
|
2
2
|
export declare const initBatteryResult: BatteryObject;
|
|
3
3
|
export declare const initAudioResult: AudioData;
|
|
4
|
+
export declare const initSerialPortResult: SerialPortData;
|
|
4
5
|
export declare const initUsbResult: UsbData;
|
|
5
6
|
export declare const initCpuResult: CpuObject;
|
|
6
7
|
export declare const initCpuCacheResult: CpuCacheData;
|
package/dist/common/defaults.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initNetworkSpeed = exports.initPciData = exports.initNpuData = exports.initNetworkInterface = exports.initProcesses = exports.initDisplay = exports.initDiskIo = exports.initFsStats = exports.initFsBlockDevice = exports.initFsOpenFiles = exports.initSystem = exports.initBios = exports.initBaseboard = exports.initChassis = exports.initUUID = exports.initOsInfo = exports.initMemData = exports.initCheckSite = exports.initCpuTemperature = exports.initCpuCacheResult = exports.initCpuResult = exports.initUsbResult = exports.initAudioResult = exports.initBatteryResult = void 0;
|
|
3
|
+
exports.initNetworkSpeed = exports.initPciData = exports.initNpuData = exports.initNetworkInterface = exports.initProcesses = exports.initDisplay = exports.initDiskIo = exports.initFsStats = exports.initFsBlockDevice = exports.initFsOpenFiles = exports.initSystem = exports.initBios = exports.initBaseboard = exports.initChassis = exports.initUUID = exports.initOsInfo = exports.initMemData = exports.initCheckSite = exports.initCpuTemperature = exports.initCpuCacheResult = exports.initCpuResult = exports.initUsbResult = exports.initSerialPortResult = exports.initAudioResult = exports.initBatteryResult = void 0;
|
|
4
4
|
const node_os_1 = require("node:os");
|
|
5
5
|
const acceleration_1 = require("./acceleration");
|
|
6
6
|
const const_1 = require("./const");
|
|
@@ -34,6 +34,16 @@ exports.initAudioResult = {
|
|
|
34
34
|
out: null,
|
|
35
35
|
status: ''
|
|
36
36
|
};
|
|
37
|
+
exports.initSerialPortResult = {
|
|
38
|
+
device: '',
|
|
39
|
+
name: null,
|
|
40
|
+
manufacturer: null,
|
|
41
|
+
serialNumber: null,
|
|
42
|
+
vendorId: null,
|
|
43
|
+
productId: null,
|
|
44
|
+
pnpId: null,
|
|
45
|
+
type: 'unknown'
|
|
46
|
+
};
|
|
37
47
|
exports.initUsbResult = {
|
|
38
48
|
id: null,
|
|
39
49
|
bus: null,
|
package/dist/common/files.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
export declare const getFilesInPath: (source: string) => Promise<string[]>;
|
|
2
2
|
export declare const fileExists: (file: string) => Promise<boolean>;
|
|
3
3
|
export declare const readSysfs: (file: string) => Promise<string>;
|
|
4
|
+
export declare const readFileLines: (file: string) => Promise<string[]>;
|
|
5
|
+
export declare const readSysfsMany: (dir: string, names: string[]) => Promise<string[]>;
|
|
6
|
+
export declare const readProcStats: (pids: any[]) => Promise<{
|
|
7
|
+
all: string;
|
|
8
|
+
procs: string[];
|
|
9
|
+
}>;
|
|
10
|
+
export declare const readFileMax: (file: string, maxBytes?: number) => Promise<string>;
|
|
11
|
+
export declare const DMI_PATH = "/sys/devices/virtual/dmi/id";
|
package/dist/common/files.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readSysfs = exports.fileExists = exports.getFilesInPath = void 0;
|
|
3
|
+
exports.DMI_PATH = exports.readFileMax = exports.readProcStats = exports.readSysfsMany = exports.readFileLines = exports.readSysfs = exports.fileExists = exports.getFilesInPath = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const promises_1 = require("fs/promises");
|
|
6
6
|
const path_1 = require("path");
|
|
7
|
+
const security_1 = require("./security");
|
|
7
8
|
const getFilesInPath = async (source) => {
|
|
8
9
|
const fetchedFiles = [];
|
|
9
10
|
try {
|
|
10
|
-
const files = await (0, promises_1.readdir)(source);
|
|
11
|
+
const files = (await (0, promises_1.readdir)(source)).filter(security_1.isSafePathSegment);
|
|
11
12
|
for (const file of files) {
|
|
12
13
|
try {
|
|
13
14
|
const filepath = (0, path_1.join)(source, file);
|
|
@@ -17,7 +18,7 @@ const getFilesInPath = async (source) => {
|
|
|
17
18
|
}
|
|
18
19
|
if (stats.isDirectory()) {
|
|
19
20
|
const childFiles = await (0, promises_1.readdir)(filepath);
|
|
20
|
-
files.push(...childFiles.map((f) => (0, path_1.join)(file, f)));
|
|
21
|
+
files.push(...childFiles.filter(security_1.isSafePathSegment).map((f) => (0, path_1.join)(file, f)));
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
catch { }
|
|
@@ -46,3 +47,57 @@ const readSysfs = async (file) => {
|
|
|
46
47
|
}
|
|
47
48
|
};
|
|
48
49
|
exports.readSysfs = readSysfs;
|
|
50
|
+
const readFileLines = async (file) => {
|
|
51
|
+
try {
|
|
52
|
+
return (await (0, promises_1.readFile)(file, 'utf8')).split('\n');
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
exports.readFileLines = readFileLines;
|
|
59
|
+
const readSysfsMany = async (dir, names) => {
|
|
60
|
+
return Promise.all(names.map(async (name) => `${name}: ${await (0, exports.readSysfs)((0, path_1.join)(dir, name))}`));
|
|
61
|
+
};
|
|
62
|
+
exports.readSysfsMany = readSysfsMany;
|
|
63
|
+
const PROC_READ_BATCH = 64;
|
|
64
|
+
const readProcStats = async (pids) => {
|
|
65
|
+
const paths = [];
|
|
66
|
+
for (const pid of pids) {
|
|
67
|
+
const id = String(pid);
|
|
68
|
+
if (/^\d+$/.test(id)) {
|
|
69
|
+
paths.push(`/proc/${id}/stat`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const statLines = await (0, exports.readFileLines)('/proc/stat');
|
|
73
|
+
const procs = [];
|
|
74
|
+
for (let i = 0; i < paths.length; i += PROC_READ_BATCH) {
|
|
75
|
+
procs.push(...(await Promise.all(paths.slice(i, i + PROC_READ_BATCH).map((path) => (0, exports.readSysfs)(path)))));
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
all: statLines.find((line) => line.startsWith('cpu ')) || '',
|
|
79
|
+
procs: procs.filter((line) => line)
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
exports.readProcStats = readProcStats;
|
|
83
|
+
const readFileMax = async (file, maxBytes = 1024 * 1024) => {
|
|
84
|
+
let handle;
|
|
85
|
+
try {
|
|
86
|
+
handle = await (0, promises_1.open)(file, 'r');
|
|
87
|
+
const { size } = await handle.stat();
|
|
88
|
+
const buffer = Buffer.alloc(Math.min(size || maxBytes, maxBytes));
|
|
89
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
90
|
+
return buffer.toString('utf8', 0, bytesRead).trim();
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return '';
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
try {
|
|
97
|
+
await handle?.close();
|
|
98
|
+
}
|
|
99
|
+
catch { }
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
exports.readFileMax = readFileMax;
|
|
103
|
+
exports.DMI_PATH = '/sys/devices/virtual/dmi/id';
|
package/dist/common/nvidia.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.mergeControllerNvidia = exports.nvidiaDevices = exports.nvidiaSmi = expo
|
|
|
4
4
|
const promises_1 = require("fs/promises");
|
|
5
5
|
const const_1 = require("./const");
|
|
6
6
|
const exec_1 = require("./exec");
|
|
7
|
+
const security_1 = require("./security");
|
|
7
8
|
let _nvidiaSmiPath = null;
|
|
8
9
|
const getNvidiaSmi = async () => {
|
|
9
10
|
if (_nvidiaSmiPath !== null) {
|
|
@@ -21,7 +22,7 @@ const getNvidiaSmi = async () => {
|
|
|
21
22
|
const basePath = String.raw `${const_1.WINDIR}\System32\DriverStore\FileRepository`;
|
|
22
23
|
let lastMod = 0;
|
|
23
24
|
for (const dir of await (0, promises_1.readdir)(basePath)) {
|
|
24
|
-
if (!dir.toLowerCase().startsWith('nv')) {
|
|
25
|
+
if (!dir.toLowerCase().startsWith('nv') || !(0, security_1.isSafePathSegment)(dir)) {
|
|
25
26
|
continue;
|
|
26
27
|
}
|
|
27
28
|
const smiPath = [basePath, dir, 'nvidia-smi.exe'].join('\\');
|
package/dist/common/parse.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { CpuData, ProcStatData } from './types';
|
|
2
|
-
export type headerType = {
|
|
3
|
-
from: number;
|
|
4
|
-
to: number;
|
|
5
|
-
cap: string;
|
|
6
|
-
};
|
|
7
|
-
export declare const parseHead: (head: string, rights: number) => headerType[];
|
|
8
2
|
export declare const parseProcStat: (line: string) => number;
|
|
3
|
+
export declare const clampCpuPair: (cpuu: number, cpus: number) => {
|
|
4
|
+
cpuu: number;
|
|
5
|
+
cpus: number;
|
|
6
|
+
};
|
|
9
7
|
export declare const calcProcStatLinux: (line: string, all: number, _cpu_old: CpuData) => ProcStatData;
|
|
10
8
|
export declare const parseJsonArray: (data: string) => any[];
|
|
11
9
|
export declare const cleanDefaults: (str: string) => string;
|
package/dist/common/parse.js
CHANGED
|
@@ -1,63 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.splitByNumber = exports.kFactor = exports.cleanDefaults = exports.parseJsonArray = exports.calcProcStatLinux = exports.
|
|
3
|
+
exports.splitByNumber = exports.kFactor = exports.cleanDefaults = exports.parseJsonArray = exports.calcProcStatLinux = exports.clampCpuPair = exports.parseProcStat = void 0;
|
|
4
4
|
const index_1 = require("./index");
|
|
5
|
-
const parseHead = (head, rights) => {
|
|
6
|
-
let space = rights > 0;
|
|
7
|
-
let count = 1;
|
|
8
|
-
let from = 0;
|
|
9
|
-
let to = 0;
|
|
10
|
-
const result = [];
|
|
11
|
-
for (let i = 0; i < head.length; i++) {
|
|
12
|
-
if (count <= rights) {
|
|
13
|
-
if (/\s/.test(head[i]) && !space) {
|
|
14
|
-
to = i - 1;
|
|
15
|
-
result.push({
|
|
16
|
-
from: from,
|
|
17
|
-
to: to + 1,
|
|
18
|
-
cap: head.substring(from, to + 1)
|
|
19
|
-
});
|
|
20
|
-
from = to + 2;
|
|
21
|
-
count++;
|
|
22
|
-
}
|
|
23
|
-
space = head[i] === ' ';
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
if (!/\s/.test(head[i]) && space) {
|
|
27
|
-
to = i - 1;
|
|
28
|
-
if (from < to) {
|
|
29
|
-
result.push({
|
|
30
|
-
from: from,
|
|
31
|
-
to: to,
|
|
32
|
-
cap: head.substring(from, to)
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
from = to + 1;
|
|
36
|
-
count++;
|
|
37
|
-
}
|
|
38
|
-
space = head[i] === ' ';
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
to = 5000;
|
|
42
|
-
result.push({
|
|
43
|
-
from: from,
|
|
44
|
-
to: to,
|
|
45
|
-
cap: head.substring(from, to)
|
|
46
|
-
});
|
|
47
|
-
let len = result.length;
|
|
48
|
-
for (let i = 0; i < len; i++) {
|
|
49
|
-
if (result[i].cap.replace(/\s/g, '').length === 0) {
|
|
50
|
-
if (i + 1 < len) {
|
|
51
|
-
result[i].to = result[i + 1].to;
|
|
52
|
-
result[i].cap = result[i].cap + result[i + 1].cap;
|
|
53
|
-
result.splice(i + 1, 1);
|
|
54
|
-
len = len - 1;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return result;
|
|
59
|
-
};
|
|
60
|
-
exports.parseHead = parseHead;
|
|
61
5
|
const parseProcStat = (line) => {
|
|
62
6
|
const parts = line.replace(/ +/g, ' ').split(' ');
|
|
63
7
|
const user = parts.length >= 2 ? (0, index_1.toInt)(parts[1]) : 0;
|
|
@@ -73,6 +17,21 @@ const parseProcStat = (line) => {
|
|
|
73
17
|
return user + nice + system + idle + iowait + irq + softirq + steal + guest + guest_nice;
|
|
74
18
|
};
|
|
75
19
|
exports.parseProcStat = parseProcStat;
|
|
20
|
+
const clampCpuPair = (cpuu, cpus) => {
|
|
21
|
+
if (!Number.isFinite(cpuu) || cpuu < 0) {
|
|
22
|
+
cpuu = 0;
|
|
23
|
+
}
|
|
24
|
+
if (!Number.isFinite(cpus) || cpus < 0) {
|
|
25
|
+
cpus = 0;
|
|
26
|
+
}
|
|
27
|
+
const total = cpuu + cpus;
|
|
28
|
+
if (total > 100) {
|
|
29
|
+
cpuu = (cpuu / total) * 100;
|
|
30
|
+
cpus = (cpus / total) * 100;
|
|
31
|
+
}
|
|
32
|
+
return { cpuu, cpus };
|
|
33
|
+
};
|
|
34
|
+
exports.clampCpuPair = clampCpuPair;
|
|
76
35
|
const calcProcStatLinux = (line, all, _cpu_old) => {
|
|
77
36
|
const statparts = line.replace(/ +/g, ' ').split(')');
|
|
78
37
|
if (statparts.length >= 2) {
|
|
@@ -81,27 +40,25 @@ const calcProcStatLinux = (line, all, _cpu_old) => {
|
|
|
81
40
|
const pid = (0, index_1.toInt)(statparts[0].split(' ')[0]);
|
|
82
41
|
const utime = (0, index_1.toInt)(parts[12]);
|
|
83
42
|
const stime = (0, index_1.toInt)(parts[13]);
|
|
84
|
-
const cutime = (0, index_1.toInt)(parts[14]);
|
|
85
|
-
const cstime = (0, index_1.toInt)(parts[15]);
|
|
86
43
|
let cpuu = 0;
|
|
87
44
|
let cpus = 0;
|
|
88
45
|
if (_cpu_old.all > 0 && _cpu_old.list[pid]) {
|
|
89
|
-
|
|
90
|
-
|
|
46
|
+
const delta = all - _cpu_old.all;
|
|
47
|
+
cpuu = delta > 0 ? ((utime - _cpu_old.list[pid].utime) / delta) * 100 : 0;
|
|
48
|
+
cpus = delta > 0 ? ((stime - _cpu_old.list[pid].stime) / delta) * 100 : 0;
|
|
91
49
|
}
|
|
92
50
|
else {
|
|
93
|
-
cpuu = (
|
|
94
|
-
cpus = (
|
|
51
|
+
cpuu = all > 0 ? (utime / all) * 100 : 0;
|
|
52
|
+
cpus = all > 0 ? (stime / all) * 100 : 0;
|
|
95
53
|
}
|
|
54
|
+
const clamped = (0, exports.clampCpuPair)(cpuu, cpus);
|
|
96
55
|
return {
|
|
97
56
|
pid: pid,
|
|
98
57
|
name: '',
|
|
99
58
|
utime: utime,
|
|
100
59
|
stime: stime,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
cpuu: cpuu,
|
|
104
|
-
cpus: cpus
|
|
60
|
+
cpuu: clamped.cpuu,
|
|
61
|
+
cpus: clamped.cpus
|
|
105
62
|
};
|
|
106
63
|
}
|
|
107
64
|
}
|
|
@@ -110,8 +67,6 @@ const calcProcStatLinux = (line, all, _cpu_old) => {
|
|
|
110
67
|
name: '',
|
|
111
68
|
utime: 0,
|
|
112
69
|
stime: 0,
|
|
113
|
-
cutime: 0,
|
|
114
|
-
cstime: 0,
|
|
115
70
|
cpuu: 0,
|
|
116
71
|
cpus: 0
|
|
117
72
|
};
|
|
@@ -22,6 +22,7 @@ export declare const stringSplit: {
|
|
|
22
22
|
export declare const stringStartWith: (searchString: string, position?: number) => boolean;
|
|
23
23
|
export declare const mathMin: (...values: number[]) => number;
|
|
24
24
|
export declare const sanitizeShellString: (str: string, strict?: any) => string;
|
|
25
|
+
export declare const isSafePathSegment: (segment: string) => boolean;
|
|
25
26
|
export declare const sanitizeContainerID: (str: string) => string;
|
|
26
27
|
export declare const sanitizeImageID: (str: string) => string;
|
|
27
28
|
export declare const isPrototypePolluted: () => boolean;
|
package/dist/common/security.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sanitizeString = exports.sanitizeInterfacesString = exports.sanitizeServiceString = exports.sanitizeUrl = exports.isPrototypePolluted = exports.sanitizeImageID = exports.sanitizeContainerID = exports.sanitizeShellString = exports.mathMin = exports.stringStartWith = exports.stringSplit = exports.stringTrim = exports.stringSubstring = exports.stringSubstr = exports.stringToString = exports.stringToLower = exports.stringReplace = void 0;
|
|
3
|
+
exports.sanitizeString = exports.sanitizeInterfacesString = exports.sanitizeServiceString = exports.sanitizeUrl = exports.isPrototypePolluted = exports.sanitizeImageID = exports.sanitizeContainerID = exports.isSafePathSegment = exports.sanitizeShellString = exports.mathMin = exports.stringStartWith = exports.stringSplit = exports.stringTrim = exports.stringSubstring = exports.stringSubstr = exports.stringToString = exports.stringToLower = exports.stringReplace = void 0;
|
|
4
4
|
exports.stringReplace = new String().replace;
|
|
5
5
|
exports.stringToLower = new String().toLowerCase;
|
|
6
6
|
exports.stringToString = new String().toString;
|
|
@@ -56,6 +56,8 @@ const sanitizeShellString = (str, strict) => {
|
|
|
56
56
|
return result;
|
|
57
57
|
};
|
|
58
58
|
exports.sanitizeShellString = sanitizeShellString;
|
|
59
|
+
const isSafePathSegment = (segment) => !!segment && segment.indexOf('/') === -1 && segment.indexOf('\0') === -1 && segment !== '.' && segment !== '..';
|
|
60
|
+
exports.isSafePathSegment = isSafePathSegment;
|
|
59
61
|
const sanitizeContainerID = (str) => {
|
|
60
62
|
const s = String(str || '')
|
|
61
63
|
.substring(0, 2000)
|
package/dist/common/types.d.ts
CHANGED
|
@@ -328,6 +328,17 @@ export type FanData = {
|
|
|
328
328
|
pwm: number | null;
|
|
329
329
|
source: string;
|
|
330
330
|
};
|
|
331
|
+
export type SerialPortType = 'usb' | 'onboard' | 'pci' | 'bluetooth' | 'virtual' | 'unknown';
|
|
332
|
+
export type SerialPortData = {
|
|
333
|
+
device: string;
|
|
334
|
+
name: string | null;
|
|
335
|
+
manufacturer: string | null;
|
|
336
|
+
serialNumber: string | null;
|
|
337
|
+
vendorId: string | null;
|
|
338
|
+
productId: string | null;
|
|
339
|
+
pnpId: string | null;
|
|
340
|
+
type: SerialPortType;
|
|
341
|
+
};
|
|
331
342
|
export type CurrentLoadData = {
|
|
332
343
|
avgLoad: number;
|
|
333
344
|
currentLoad: number;
|
|
@@ -856,8 +867,6 @@ export type ProcStatData = {
|
|
|
856
867
|
name: string;
|
|
857
868
|
utime: number;
|
|
858
869
|
stime: number;
|
|
859
|
-
cutime?: number;
|
|
860
|
-
cstime?: number;
|
|
861
870
|
cpu?: number;
|
|
862
871
|
cpuu: number;
|
|
863
872
|
cpus: number;
|
|
@@ -894,6 +903,7 @@ export type ProcessesProcessData = {
|
|
|
894
903
|
cpu: number;
|
|
895
904
|
cpuu: number;
|
|
896
905
|
cpus: number;
|
|
906
|
+
cpuTime: number | null;
|
|
897
907
|
mem: number;
|
|
898
908
|
priority: number;
|
|
899
909
|
memVsz: number;
|
package/dist/cpu-current-load.js
CHANGED
|
@@ -4,7 +4,8 @@ exports.currentLoad = void 0;
|
|
|
4
4
|
const node_os_1 = require("node:os");
|
|
5
5
|
const common_1 = require("./common");
|
|
6
6
|
const const_1 = require("./common/const");
|
|
7
|
-
const
|
|
7
|
+
const files_1 = require("./common/files");
|
|
8
|
+
const JIFFY_MS = 10;
|
|
8
9
|
let _current_cpu = {
|
|
9
10
|
user: 0,
|
|
10
11
|
nice: 0,
|
|
@@ -81,8 +82,7 @@ const currentLoad = async () => {
|
|
|
81
82
|
_corecount = cpus && cpus.length ? cpus.length : 0;
|
|
82
83
|
if (const_1.LINUX) {
|
|
83
84
|
try {
|
|
84
|
-
const
|
|
85
|
-
const lines = stdout.split('\n');
|
|
85
|
+
const lines = (await (0, files_1.readFileLines)('/proc/stat')).filter((line) => line.startsWith('cpu'));
|
|
86
86
|
if (lines.length > 1) {
|
|
87
87
|
lines.shift();
|
|
88
88
|
if (lines.length === cpus.length) {
|
|
@@ -91,8 +91,8 @@ const currentLoad = async () => {
|
|
|
91
91
|
if (parts.length >= 10) {
|
|
92
92
|
const steal = parseFloat(parts[8]) || 0;
|
|
93
93
|
const guest = parseFloat(parts[9]) || 0;
|
|
94
|
-
cpus[i].times.steal = steal;
|
|
95
|
-
cpus[i].times.guest = guest;
|
|
94
|
+
cpus[i].times.steal = steal * JIFFY_MS;
|
|
95
|
+
cpus[i].times.guest = guest * JIFFY_MS;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -5,7 +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 cpu_1 = require("./common/cpu");
|
|
8
|
-
const
|
|
8
|
+
const files_1 = require("./common/files");
|
|
9
9
|
const getCpuCurrentSpeed = async () => {
|
|
10
10
|
const oscpus = (0, node_os_1.cpus)();
|
|
11
11
|
let minFreq = 999999999;
|
|
@@ -20,8 +20,10 @@ const getCpuCurrentSpeed = async () => {
|
|
|
20
20
|
}
|
|
21
21
|
else if (const_1.LINUX) {
|
|
22
22
|
try {
|
|
23
|
-
const
|
|
24
|
-
|
|
23
|
+
const speedStrings = (await (0, files_1.readFileLines)('/proc/cpuinfo'))
|
|
24
|
+
.filter((line) => line.toLowerCase().startsWith('cpu mhz'))
|
|
25
|
+
.map((line) => (line.split(':')[1] || '').trim())
|
|
26
|
+
.filter((line) => line.length > 0);
|
|
25
27
|
for (const i in speedStrings) {
|
|
26
28
|
speeds.push(Math.floor(parseInt(speedStrings[i], 10) / 10) / 100);
|
|
27
29
|
}
|
package/dist/darwin/index.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ export { software } from './software';
|
|
|
46
46
|
export { system } from './system';
|
|
47
47
|
export { thunderbolt } from './thunderbolt';
|
|
48
48
|
export { time } from '../time';
|
|
49
|
+
export { serialPorts } from './serial-ports';
|
|
49
50
|
export { usb } from './usb';
|
|
50
51
|
export { users } from './users';
|
|
51
52
|
export { uuid } from './uuid';
|
package/dist/darwin/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");
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serialPorts = void 0;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
const common_1 = require("../common");
|
|
6
|
+
const defaults_1 = require("../common/defaults");
|
|
7
|
+
const exec_1 = require("../common/exec");
|
|
8
|
+
const security_1 = require("../common/security");
|
|
9
|
+
const toHex4 = (value) => {
|
|
10
|
+
const num = Number.parseInt(value, 10);
|
|
11
|
+
return Number.isNaN(num) ? null : num.toString(16).padStart(4, '0');
|
|
12
|
+
};
|
|
13
|
+
const parseUsbPorts = (stdout) => {
|
|
14
|
+
const ports = new Map();
|
|
15
|
+
let usb = {};
|
|
16
|
+
for (const raw of stdout.split('\n')) {
|
|
17
|
+
const line = raw.replace(/\|/g, '').trim();
|
|
18
|
+
if (line.startsWith('+-o')) {
|
|
19
|
+
if (line.includes('class IOUSBHostDevice')) {
|
|
20
|
+
usb = {};
|
|
21
|
+
}
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const entry = /^"([^"]+)" = (.+)$/.exec(line);
|
|
25
|
+
if (!entry) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const key = entry[1];
|
|
29
|
+
const value = (entry[2] || '').replace(/^"|"$/g, '').trim();
|
|
30
|
+
switch (key) {
|
|
31
|
+
case 'idVendor':
|
|
32
|
+
usb.vendorId = toHex4(value);
|
|
33
|
+
break;
|
|
34
|
+
case 'idProduct':
|
|
35
|
+
usb.productId = toHex4(value);
|
|
36
|
+
break;
|
|
37
|
+
case 'USB Vendor Name':
|
|
38
|
+
usb.manufacturer = value || null;
|
|
39
|
+
break;
|
|
40
|
+
case 'USB Product Name':
|
|
41
|
+
usb.name = value || null;
|
|
42
|
+
break;
|
|
43
|
+
case 'USB Serial Number':
|
|
44
|
+
usb.serialNumber = value || null;
|
|
45
|
+
break;
|
|
46
|
+
case 'IOCalloutDevice':
|
|
47
|
+
ports.set(value, { ...usb });
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return ports;
|
|
54
|
+
};
|
|
55
|
+
const calloutDevices = (stdout) => {
|
|
56
|
+
const devices = new Set();
|
|
57
|
+
const regex = /"IOCalloutDevice" = "([^"]+)"/g;
|
|
58
|
+
let match = regex.exec(stdout);
|
|
59
|
+
while (match) {
|
|
60
|
+
if (match[1]) {
|
|
61
|
+
devices.add(match[1]);
|
|
62
|
+
}
|
|
63
|
+
match = regex.exec(stdout);
|
|
64
|
+
}
|
|
65
|
+
return devices;
|
|
66
|
+
};
|
|
67
|
+
const serialPorts = async () => {
|
|
68
|
+
await (0, common_1.nextTick)();
|
|
69
|
+
const result = [];
|
|
70
|
+
let devices = [];
|
|
71
|
+
try {
|
|
72
|
+
devices = (await (0, promises_1.readdir)('/dev')).filter((device) => device.startsWith('cu.') && (0, security_1.isSafePathSegment)(device));
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
const [usbTree, bluetoothTree] = await Promise.all([(0, exec_1.execSave)('ioreg -r -c IOUSBHostDevice -l -w0'), (0, exec_1.execSave)('ioreg -r -c IOBluetoothDevice -l -w0')]);
|
|
78
|
+
const usbPorts = parseUsbPorts(usbTree.stdout);
|
|
79
|
+
const bluetoothPorts = calloutDevices(bluetoothTree.stdout);
|
|
80
|
+
for (const device of devices.sort()) {
|
|
81
|
+
const path = `/dev/${device}`;
|
|
82
|
+
const usb = usbPorts.get(path);
|
|
83
|
+
const name = device.substring(3);
|
|
84
|
+
result.push({
|
|
85
|
+
...(0, common_1.cloneObj)(defaults_1.initSerialPortResult),
|
|
86
|
+
...usb,
|
|
87
|
+
device: path,
|
|
88
|
+
name: usb?.name || name,
|
|
89
|
+
type: usb ? 'usb' : bluetoothPorts.has(path) ? 'bluetooth' : 'unknown'
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
};
|
|
94
|
+
exports.serialPorts = serialPorts;
|
package/dist/get-data.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare const getStaticData: () => Promise<{
|
|
|
16
16
|
audio: import("./common/types").AudioData[] | null;
|
|
17
17
|
bluetooth: import("./common/types").BluetoothObject[] | null;
|
|
18
18
|
usb: import("./common/types").UsbData[] | null;
|
|
19
|
+
serialPorts: import("./common/types").SerialPortData[] | null;
|
|
19
20
|
printer: import("./common/types").PrinterData[] | null;
|
|
20
21
|
camera: import("./common/types").Camera[] | null;
|
|
21
22
|
keyboard: import("./common/types").Keyboard[] | null;
|
|
@@ -100,6 +101,7 @@ export declare const getAllData: (srv?: string, iface?: string) => Promise<{
|
|
|
100
101
|
audio: import("./common/types").AudioData[] | null;
|
|
101
102
|
bluetooth: import("./common/types").BluetoothObject[] | null;
|
|
102
103
|
usb: import("./common/types").UsbData[] | null;
|
|
104
|
+
serialPorts: import("./common/types").SerialPortData[] | null;
|
|
103
105
|
printer: import("./common/types").PrinterData[] | null;
|
|
104
106
|
camera: import("./common/types").Camera[] | null;
|
|
105
107
|
keyboard: import("./common/types").Keyboard[] | null;
|
package/dist/get-data.js
CHANGED
|
@@ -38,7 +38,7 @@ const common_1 = require("./common");
|
|
|
38
38
|
const si = __importStar(require("./index"));
|
|
39
39
|
const getStaticData = async () => {
|
|
40
40
|
await (0, common_1.nextTick)();
|
|
41
|
-
const [version, system, bios, baseboard, chassis, os, uuid, versions, cpu, cpuFlags, gpu, displays, net, memLayout, diskLayout, audio, bluetooth, usb, printer, camera, keyboard, mouse, pci, thunderbolt, npu, wifiInterfaces, software] = await Promise.all([
|
|
41
|
+
const [version, system, bios, baseboard, chassis, os, uuid, versions, cpu, cpuFlags, gpu, displays, net, memLayout, diskLayout, audio, bluetooth, usb, serialPorts, printer, camera, keyboard, mouse, pci, thunderbolt, npu, wifiInterfaces, software] = await Promise.all([
|
|
42
42
|
si.version(),
|
|
43
43
|
si.system(),
|
|
44
44
|
si.bios(),
|
|
@@ -57,6 +57,7 @@ const getStaticData = async () => {
|
|
|
57
57
|
si.audio(),
|
|
58
58
|
si.bluetoothDevices(),
|
|
59
59
|
si.usb(),
|
|
60
|
+
si.serialPorts(),
|
|
60
61
|
si.printer(),
|
|
61
62
|
si.camera(),
|
|
62
63
|
si.keyboard(),
|
|
@@ -85,6 +86,7 @@ const getStaticData = async () => {
|
|
|
85
86
|
audio,
|
|
86
87
|
bluetooth,
|
|
87
88
|
usb,
|
|
89
|
+
serialPorts,
|
|
88
90
|
printer,
|
|
89
91
|
camera,
|
|
90
92
|
keyboard,
|
package/dist/index.d.ts
CHANGED
|
@@ -44,6 +44,7 @@ export { pci } from './pci';
|
|
|
44
44
|
export { printer } from './printer';
|
|
45
45
|
export { processes } from './processes';
|
|
46
46
|
export { processLoad } from './process-load';
|
|
47
|
+
export { serialPorts } from './serial-ports';
|
|
47
48
|
export { services } from './services';
|
|
48
49
|
export { shell } from './shell';
|
|
49
50
|
export { software } from './software';
|