systeminformation 6.0.0-beta.1 → 6.0.0-beta.11

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.
Files changed (94) hide show
  1. package/README.md +41 -7
  2. package/dist/bsd/network-stats.js +2 -2
  3. package/dist/common/darwin.d.ts +2 -0
  4. package/dist/common/darwin.js +17 -1
  5. package/dist/common/defaults.d.ts +2 -1
  6. package/dist/common/defaults.js +21 -5
  7. package/dist/common/exec.js +1 -1
  8. package/dist/common/files.d.ts +9 -0
  9. package/dist/common/files.js +67 -3
  10. package/dist/common/filesys.d.ts +10 -0
  11. package/dist/common/filesys.js +41 -10
  12. package/dist/common/host.js +55 -3
  13. package/dist/common/mappings.js +2 -1
  14. package/dist/common/network.js +4 -4
  15. package/dist/common/nvidia.d.ts +1 -1
  16. package/dist/common/nvidia.js +4 -5
  17. package/dist/common/parse.d.ts +4 -6
  18. package/dist/common/parse.js +24 -69
  19. package/dist/common/security.d.ts +1 -0
  20. package/dist/common/security.js +3 -1
  21. package/dist/common/types.d.ts +33 -5
  22. package/dist/cpu-current-load.js +28 -6
  23. package/dist/cpu-current-speed.js +5 -3
  24. package/dist/darwin/battery.d.ts +1 -1
  25. package/dist/darwin/battery.js +15 -5
  26. package/dist/darwin/camera.js +3 -3
  27. package/dist/darwin/disk-layout.js +16 -12
  28. package/dist/darwin/disks-io.js +3 -3
  29. package/dist/darwin/displays.js +34 -1
  30. package/dist/darwin/fans.d.ts +2 -0
  31. package/dist/darwin/fans.js +28 -0
  32. package/dist/darwin/gpu.js +1 -1
  33. package/dist/darwin/index.d.ts +2 -0
  34. package/dist/darwin/index.js +6 -2
  35. package/dist/darwin/keyboard.js +4 -4
  36. package/dist/darwin/mouse.js +4 -4
  37. package/dist/darwin/network-interfaces.js +5 -10
  38. package/dist/darwin/network-stats.js +5 -5
  39. package/dist/darwin/serial-ports.d.ts +2 -0
  40. package/dist/darwin/serial-ports.js +94 -0
  41. package/dist/fans.d.ts +1 -0
  42. package/dist/fans.js +17 -0
  43. package/dist/get-data.d.ts +4 -0
  44. package/dist/get-data.js +6 -2
  45. package/dist/index.d.ts +2 -0
  46. package/dist/index.js +6 -2
  47. package/dist/linux/audio.js +59 -0
  48. package/dist/linux/baseboard.js +9 -20
  49. package/dist/linux/bios.js +6 -15
  50. package/dist/linux/camera.js +2 -1
  51. package/dist/linux/chassis.js +4 -10
  52. package/dist/linux/cpu-temperature.js +34 -19
  53. package/dist/linux/cpu.js +3 -1
  54. package/dist/linux/disk-layout.js +7 -10
  55. package/dist/linux/disks-io.js +9 -9
  56. package/dist/linux/displays.js +40 -2
  57. package/dist/linux/fans.d.ts +2 -0
  58. package/dist/linux/fans.js +92 -0
  59. package/dist/linux/fs-size.js +160 -34
  60. package/dist/linux/fs-stats.js +6 -9
  61. package/dist/linux/gpu.js +15 -15
  62. package/dist/linux/index.d.ts +2 -0
  63. package/dist/linux/index.js +6 -2
  64. package/dist/linux/mem-layout.js +2 -2
  65. package/dist/linux/network-interfaces.js +36 -39
  66. package/dist/linux/network-stats.js +8 -36
  67. package/dist/linux/npu.js +2 -1
  68. package/dist/linux/os-info.js +19 -4
  69. package/dist/linux/printer.js +4 -4
  70. package/dist/linux/process-load.js +9 -12
  71. package/dist/linux/processes.js +89 -80
  72. package/dist/linux/serial-ports.d.ts +2 -0
  73. package/dist/linux/serial-ports.js +102 -0
  74. package/dist/linux/services.js +179 -47
  75. package/dist/linux/system.js +1 -7
  76. package/dist/linux/uuid.js +4 -10
  77. package/dist/serial-ports.d.ts +1 -0
  78. package/dist/serial-ports.js +17 -0
  79. package/dist/versions.js +32 -77
  80. package/dist/windows/disk-layout.js +3 -0
  81. package/dist/windows/disks-io.js +3 -3
  82. package/dist/windows/displays.js +43 -12
  83. package/dist/windows/fans.d.ts +2 -0
  84. package/dist/windows/fans.js +71 -0
  85. package/dist/windows/index.d.ts +2 -0
  86. package/dist/windows/index.js +6 -2
  87. package/dist/windows/network-interfaces.js +20 -29
  88. package/dist/windows/network-stats.js +4 -2
  89. package/dist/windows/process-load.js +7 -5
  90. package/dist/windows/processes.js +17 -11
  91. package/dist/windows/serial-ports.d.ts +3 -0
  92. package/dist/windows/serial-ports.js +73 -0
  93. package/dist/windows/services.js +3 -0
  94. 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
@@ -289,6 +291,12 @@ Full function reference with examples can be found at [https://systeminformation
289
291
  | | max | X | X | X | X | | max temperature |
290
292
  | | socket | X | | | | | array socket temperatures |
291
293
  | | chipset | X | | | | | chipset temperature |
294
+ | si.fans() | [{...}] | X | | X* | X* | | detected fans |
295
+ | | [0].id | X | | X* | X* | | identifier, e.g. hwmon2/fan1 |
296
+ | | [0].label | X | | X* | X* | | label if the driver provides one |
297
+ | | [0].rpm | X | | X* | X* | | speed in rpm (or null) |
298
+ | | [0].pwm | X | | X* | X* | | duty cycle in % (or null) |
299
+ | | [0].source | X | | X* | X* | | chip / provider the value came from |
292
300
  | si.npu() | [{...}] | X | | X | X | | detected NPUs / AI accelerators |
293
301
  | | [0].vendor | X | | X | X | | vendor (Intel, AMD, Apple, ...) |
294
302
  | | [0].name | X | | X | X | | name |
@@ -380,6 +388,7 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
380
388
  | | [0].serial | | | X | X | | serial number |
381
389
  | | [0].displayId | | | X | X | | display ID |
382
390
  | | [0].main | X | | X | X | | true if main monitor |
391
+ | | [0].mirror | X | | X | X | | true if mirrored / duplicated |
383
392
  | | [0].builtin | X | | X | | | true if built-in monitor |
384
393
  | | [0].connection | X | | X | X | | e.g. DisplayPort or HDMI |
385
394
  | | [0].sizeX | X | | | X | | size in mm horizontal |
@@ -391,7 +400,12 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
391
400
  | | [0].currentResY | X | | X | X | | current pixel vertical |
392
401
  | | [0].positionX | X | | X | X | | display position X |
393
402
  | | [0].positionY | X | | X | X | | display position Y |
403
+ | | [0].workAreaResolutionX | X | | X | X | | working area (screen minus task bar / panels / menu bar and Dock) resolution X |
404
+ | | [0].workAreaResolutionY | X | | X | X | | working area resolution Y |
405
+ | | [0].workAreaPositionX | X | | X | X | | working area position X |
406
+ | | [0].workAreaPositionY | X | | X | X | | working area position Y |
394
407
  | | [0].currentRefreshRate | X | | X | X | | current screen refresh rate |
408
+ | | [0].scale | | | | X | | DPI scaling factor, e.g. 1.5 |
395
409
 
396
410
  #### 7. Operating System
397
411
 
@@ -453,6 +467,7 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
453
467
  | | currentLoadSystem | X | | X | X | X | CPU load system in % |
454
468
  | | currentLoadNice | X | | X | X | X | CPU load nice in % |
455
469
  | | currentLoadIdle | X | | X | X | X | CPU load idle in % |
470
+ | | currentLoadIowait | X | | | | | CPU load waiting for IO in % (Linux only, 0 elsewhere) |
456
471
  | | currentLoadIrq | X | | X | X | X | CPU load system in % |
457
472
  | | rawCurrentLoad... | X | | X | X | X | CPU load raw values (ticks) |
458
473
  | | cpus[] | X | | X | X | X | current loads per CPU in % + raw ticks |
@@ -470,6 +485,7 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
470
485
  | | ...[0].cpu | X | X | X | X | X | process % CPU usage |
471
486
  | | ...[0].cpuu | X | X | | X | | process % CPU usage (user) |
472
487
  | | ...[0].cpus | X | X | | X | | process % CPU usage (system) |
488
+ | | ...[0].cpuTime | X | X | X | X | X | process cpu time in seconds (own, without reaped children); null if not available |
473
489
  | | ...[0].mem | X | X | X | X | X | process memory % |
474
490
  | | ...[0].priority | X | X | X | X | X | process priority |
475
491
  | | ...[0].memVsz | X | X | X | X | X | process virtual memory size |
@@ -542,12 +558,12 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
542
558
  | | rIO | X | | X | X | | read IOs on all mounted drives |
543
559
  | | wIO | X | | X | X | | write IOs on all mounted drives |
544
560
  | | tIO | X | | X | X | | write IOs on all mounted drives |
545
- | | rIO_sec | X | | X | X | | read IO per sec (* see notes) |
546
- | | wIO_sec | X | | X | X | | write IO per sec (* see notes) |
547
- | | tIO_sec | X | | X | X | | total IO per sec (* see notes) |
548
- | | rWaitTime | X | | | | | read IO request time (* see notes) |
549
- | | wWaitTime | X | | | | | write IO request time (* see notes) |
550
- | | tWaitTime | X | | | | | total IO request time (* see notes) |
561
+ | | rIO_sec | X | | X | X | | read IO operations per sec, not bytes (* see notes) |
562
+ | | wIO_sec | X | | X | X | | write IO operations per sec, not bytes (* see notes) |
563
+ | | tIO_sec | X | | X | X | | total IO operations per sec, not bytes (* see notes) |
564
+ | | rWaitTime | X | | | | | read IO request time in ms during interval, null on 1st call (* notes) |
565
+ | | wWaitTime | X | | | | | write IO request time in ms during interval, null on 1st call (* notes) |
566
+ | | tWaitTime | X | | | | | total IO request time in ms during interval, null on 1st call (* notes) |
551
567
  | | rWaitPercent | X | | | | | read IO request time percent (* see notes) |
552
568
  | | wWaitPercent | X | | | | | write IO request time percent (* see notes) |
553
569
  | | tWaitPercent | X | | | | | total IO request time percent (* see notes) |
@@ -608,6 +624,15 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
608
624
  | | [0].maxPower | X | | | | | max power |
609
625
  | | [0].default | X | | X | X | | is default printer |
610
626
  | | [0].serialNumber | | | X | | | serial number |
627
+ | si.serialPorts() | [{...}] | X | | X | X | | detected serial / COM ports |
628
+ | | [0].device | X | | X | X | | device path (COMx on Windows) |
629
+ | | [0].name | X | | X | X | | product / friendly name |
630
+ | | [0].manufacturer | X | | X | X | | manufacturer |
631
+ | | [0].serialNumber | X | | X | X | | serial number (USB only) |
632
+ | | [0].vendorId | X | | X | X | | vendor id (hex) |
633
+ | | [0].productId | X | | X | X | | product id (hex) |
634
+ | | [0].pnpId | X | | | X | | stable id (by-id / DeviceID) |
635
+ | | [0].type | X | | X | X | | usb, onboard, pci, bluetooth |
611
636
 
612
637
  #### 11. Devices
613
638
 
@@ -1003,6 +1028,15 @@ $ npm install macos-temperature-sensor --save
1003
1028
 
1004
1029
  `systeminformation` will then detect this additional library and return the temperature when calling systeminformations standard function `cpuTemperature()`.
1005
1030
  On Apple Silicon machines `macos-temperature-sensor` also enables the GPU temperature (`temperatureGpu`) in `gpu()`
1031
+ and - as soon as the package exposes them - the fan speeds in `fans()`.
1032
+
1033
+ #### Windows - Fan Speed
1034
+
1035
+ 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`.
1036
+
1037
+ #### Serial Ports
1038
+
1039
+ `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.
1006
1040
 
1007
1041
  #### Windows Temperature, Battery, ...
1008
1042
 
@@ -9,7 +9,7 @@ const darwin_1 = require("../darwin");
9
9
  const network_1 = require("../common/network");
10
10
  const _network = {};
11
11
  const networkStatsSingle = async (iface) => {
12
- const defaults = defaults_1.initNetworkSpeed;
12
+ const defaults = { ...defaults_1.initNetworkSpeed, iface };
13
13
  if (!_network[iface] || (_network[iface] && !_network[iface].ms) || (_network[iface] && _network[iface].ms && Date.now() - _network[iface].ms >= 500)) {
14
14
  let operstate = 'unknown';
15
15
  let rx_bytes = 0;
@@ -18,7 +18,7 @@ const networkStatsSingle = async (iface) => {
18
18
  let rx_errors = 0;
19
19
  let tx_dropped = 0;
20
20
  let tx_errors = 0;
21
- const { stdout } = await (0, exec_1.execSave)(`netstat -ibndI ${iface}`);
21
+ const stdout = await (0, exec_1.execSecure)('netstat', ['-ibndI', iface]);
22
22
  if (stdout) {
23
23
  const lines = stdout.split('\n');
24
24
  for (let i = 1; i < lines.length; i++) {
@@ -1,5 +1,7 @@
1
1
  import type { UserData } from './types';
2
2
  export declare const darwinXcodeExists: () => Promise<boolean>;
3
+ export declare const USB_DATA_TYPES: string[];
4
+ export declare const spItems: (data: any, dataTypes: string | string[]) => any[];
3
5
  export declare const plistParser: (xmlStr: string, items?: boolean) => any;
4
6
  export declare const formatBssid: (s: string) => string;
5
7
  export declare const plistReader: (output: string) => {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseUsersDarwin = exports.plistReader = exports.formatBssid = exports.plistParser = exports.darwinXcodeExists = void 0;
3
+ exports.parseUsersDarwin = exports.plistReader = exports.formatBssid = exports.plistParser = exports.spItems = exports.USB_DATA_TYPES = exports.darwinXcodeExists = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const promises_1 = require("fs/promises");
6
6
  const datetime_1 = require("./datetime");
@@ -14,6 +14,22 @@ const darwinXcodeExists = async () => {
14
14
  };
15
15
  exports.darwinXcodeExists = darwinXcodeExists;
16
16
  const isProtoKey = (key) => key === '__proto__' || key === 'constructor' || key === 'prototype';
17
+ exports.USB_DATA_TYPES = ['SPUSBDataType', 'SPUSBHostDataType'];
18
+ const spItems = (data, dataTypes) => {
19
+ const types = Array.isArray(dataTypes) ? dataTypes : [dataTypes];
20
+ const result = [];
21
+ if (!Array.isArray(data)) {
22
+ return result;
23
+ }
24
+ for (const dataType of types) {
25
+ const section = data.find((s) => s && s._dataType === dataType);
26
+ if (section && Array.isArray(section._items)) {
27
+ result.push(...section._items);
28
+ }
29
+ }
30
+ return result;
31
+ };
32
+ exports.spItems = spItems;
17
33
  const plistParser = (xmlStr, items = true) => {
18
34
  const tags = ['array', 'dict', 'key', 'string', 'integer', 'date', 'real', 'data', 'boolean', 'arrayEmpty'];
19
35
  const startStr = '<plist version';
@@ -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;
@@ -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,
@@ -207,9 +217,9 @@ exports.initDiskIo = {
207
217
  rIO_sec: null,
208
218
  wIO_sec: null,
209
219
  tIO_sec: null,
210
- rWaitTime: 0,
211
- wWaitTime: 0,
212
- tWaitTime: 0,
220
+ rWaitTime: null,
221
+ wWaitTime: null,
222
+ tWaitTime: null,
213
223
  rWaitPercent: null,
214
224
  wWaitPercent: null,
215
225
  tWaitPercent: null,
@@ -224,6 +234,7 @@ exports.initDisplay = {
224
234
  deviceName: '',
225
235
  displayId: null,
226
236
  main: false,
237
+ mirror: false,
227
238
  builtin: false,
228
239
  connection: '',
229
240
  sizeX: null,
@@ -235,7 +246,12 @@ exports.initDisplay = {
235
246
  currentResY: null,
236
247
  positionX: 0,
237
248
  positionY: 0,
238
- currentRefreshRate: null
249
+ workAreaResolutionX: null,
250
+ workAreaResolutionY: null,
251
+ workAreaPositionX: null,
252
+ workAreaPositionY: null,
253
+ currentRefreshRate: null,
254
+ scale: null
239
255
  };
240
256
  exports.initProcesses = {
241
257
  all: 0,
@@ -63,7 +63,7 @@ const execSave = async (cmd, options = {}) => {
63
63
  return { stdout: stdout.toString(), stderr: stderr.toString() };
64
64
  }
65
65
  catch (e) {
66
- return { stdout: e.stdout, stderr: e.stderr };
66
+ return { stdout: String(e.stdout ?? ''), stderr: String(e.stderr ?? '') };
67
67
  }
68
68
  };
69
69
  exports.execSave = execSave;
@@ -1,2 +1,11 @@
1
1
  export declare const getFilesInPath: (source: string) => Promise<string[]>;
2
2
  export declare const fileExists: (file: string) => Promise<boolean>;
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";
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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 { }
@@ -37,3 +38,66 @@ const fileExists = async (file) => {
37
38
  }
38
39
  };
39
40
  exports.fileExists = fileExists;
41
+ const readSysfs = async (file) => {
42
+ try {
43
+ return (await (0, promises_1.readFile)(file, 'utf8')).trim();
44
+ }
45
+ catch {
46
+ return '';
47
+ }
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';
@@ -1,4 +1,14 @@
1
1
  import type { FsBlockDevicesData } from './types';
2
+ export declare const zfsDatasets: () => Promise<{
3
+ byMount: Map<string, {
4
+ used: number;
5
+ available: number;
6
+ }>;
7
+ byName: Map<string, {
8
+ used: number;
9
+ available: number;
10
+ }>;
11
+ }>;
2
12
  export declare const smartMonToolsInstalled: () => Promise<boolean>;
3
13
  export declare const _fs_speed: any;
4
14
  export declare const calcFsSpeed: (rx: number, wx: number) => any;
@@ -1,11 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.matchDevicesWin = exports.matchDevicesLinux = exports.raidMatchLinux = exports.parseLinuxBlk = exports.blkStdoutToObject = exports.calcDiskIO = exports._disk_io = exports.calcFsSpeed = exports._fs_speed = exports.smartMonToolsInstalled = void 0;
3
+ exports.matchDevicesWin = exports.matchDevicesLinux = exports.raidMatchLinux = exports.parseLinuxBlk = exports.blkStdoutToObject = exports.calcDiskIO = exports._disk_io = exports.calcFsSpeed = exports._fs_speed = exports.smartMonToolsInstalled = exports.zfsDatasets = void 0;
4
4
  const index_1 = require("./index");
5
5
  const const_1 = require("./const");
6
6
  const defaults_1 = require("./defaults");
7
7
  const exec_1 = require("./exec");
8
8
  let _smartMonToolsInstalled = null;
9
+ const zfsDatasets = async () => {
10
+ const byMount = new Map();
11
+ const byName = new Map();
12
+ let stdout = '';
13
+ try {
14
+ ({ stdout } = await (0, exec_1.exec)('zfs list -H -p -o name,used,avail,mountpoint', { ...const_1.execOptsLinux, timeout: 5000 }));
15
+ }
16
+ catch {
17
+ return { byMount, byName };
18
+ }
19
+ for (const line of stdout.toString().split('\n')) {
20
+ const parts = line.split('\t');
21
+ if (parts.length < 4) {
22
+ continue;
23
+ }
24
+ const entry = { used: (0, index_1.toInt)(parts[1]), available: (0, index_1.toInt)(parts[2]) };
25
+ const mount = parts[3].trim();
26
+ byName.set(parts[0], entry);
27
+ if (mount.startsWith('/') && !byMount.has(mount)) {
28
+ byMount.set(mount, entry);
29
+ }
30
+ }
31
+ return { byMount, byName };
32
+ };
33
+ exports.zfsDatasets = zfsDatasets;
9
34
  const smartMonToolsInstalled = async () => {
10
35
  if (_smartMonToolsInstalled !== null) {
11
36
  return _smartMonToolsInstalled;
@@ -84,12 +109,12 @@ const calcDiskIO = (rIO, wIO, rWaitTime, wWaitTime, tWaitTime) => {
84
109
  result.rIO_sec = (result.rIO - exports._disk_io.rIO) / (result.ms / 1000);
85
110
  result.wIO_sec = (result.wIO - exports._disk_io.wIO) / (result.ms / 1000);
86
111
  result.tIO_sec = result.rIO_sec + result.wIO_sec;
87
- result.rWaitTime = rWaitTime;
88
- result.wWaitTime = wWaitTime;
89
- result.tWaitTime = tWaitTime;
90
- result.rWaitPercent = ((result.rWaitTime - exports._disk_io.rWaitTime) * 100) / result.ms;
91
- result.wWaitPercent = ((result.wWaitTime - exports._disk_io.wWaitTime) * 100) / result.ms;
92
- result.tWaitPercent = ((result.tWaitTime - exports._disk_io.tWaitTime) * 100) / result.ms;
112
+ result.rWaitTime = rWaitTime - exports._disk_io.rWaitTime;
113
+ result.wWaitTime = wWaitTime - exports._disk_io.wWaitTime;
114
+ result.tWaitTime = tWaitTime - exports._disk_io.tWaitTime;
115
+ result.rWaitPercent = (result.rWaitTime * 100) / result.ms;
116
+ result.wWaitPercent = (result.wWaitTime * 100) / result.ms;
117
+ result.tWaitPercent = (result.tWaitTime * 100) / result.ms;
93
118
  exports._disk_io.rIO = rIO;
94
119
  exports._disk_io.wIO = wIO;
95
120
  exports._disk_io.rIO_sec = result.rIO_sec;
@@ -98,6 +123,9 @@ const calcDiskIO = (rIO, wIO, rWaitTime, wWaitTime, tWaitTime) => {
98
123
  exports._disk_io.rWaitTime = rWaitTime;
99
124
  exports._disk_io.wWaitTime = wWaitTime;
100
125
  exports._disk_io.tWaitTime = tWaitTime;
126
+ exports._disk_io.rWaitTimeDelta = result.rWaitTime;
127
+ exports._disk_io.wWaitTimeDelta = result.wWaitTime;
128
+ exports._disk_io.tWaitTimeDelta = result.tWaitTime;
101
129
  exports._disk_io.rWaitPercent = result.rWaitPercent;
102
130
  exports._disk_io.wWaitPercent = result.wWaitPercent;
103
131
  exports._disk_io.tWaitPercent = result.tWaitPercent;
@@ -108,9 +136,9 @@ const calcDiskIO = (rIO, wIO, rWaitTime, wWaitTime, tWaitTime) => {
108
136
  result.rIO = rIO;
109
137
  result.wIO = wIO;
110
138
  result.tIO = rIO + wIO;
111
- result.rWaitTime = rWaitTime;
112
- result.wWaitTime = wWaitTime;
113
- result.tWaitTime = tWaitTime;
139
+ result.rWaitTime = null;
140
+ result.wWaitTime = null;
141
+ result.tWaitTime = null;
114
142
  exports._disk_io.rIO = rIO;
115
143
  exports._disk_io.wIO = wIO;
116
144
  exports._disk_io.rIO_sec = null;
@@ -119,6 +147,9 @@ const calcDiskIO = (rIO, wIO, rWaitTime, wWaitTime, tWaitTime) => {
119
147
  exports._disk_io.rWaitTime = rWaitTime;
120
148
  exports._disk_io.wWaitTime = wWaitTime;
121
149
  exports._disk_io.tWaitTime = tWaitTime;
150
+ exports._disk_io.rWaitTimeDelta = null;
151
+ exports._disk_io.wWaitTimeDelta = null;
152
+ exports._disk_io.tWaitTimeDelta = null;
122
153
  exports._disk_io.rWaitPercent = null;
123
154
  exports._disk_io.wWaitPercent = null;
124
155
  exports._disk_io.tWaitPercent = null;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getUniqueMacAddresses = exports.getFQDN = void 0;
4
+ const node_child_process_1 = require("node:child_process");
4
5
  const node_os_1 = require("node:os");
5
6
  const const_1 = require("./const");
6
7
  const exec_1 = require("./exec");
@@ -33,16 +34,67 @@ const getFQDN = async () => {
33
34
  return (0, node_os_1.hostname)();
34
35
  };
35
36
  exports.getFQDN = getFQDN;
37
+ const MASKED_MACS = ['00:00:00:00:00:00', '02:00:00:00:00:00'];
38
+ const getMacAddressesSync = () => {
39
+ const result = {};
40
+ let iface = '';
41
+ let mac = '';
42
+ try {
43
+ if (const_1.LINUX) {
44
+ const lines = (0, node_child_process_1.execSync)('export LC_ALL=C; ip link show up; unset LC_ALL', { encoding: 'utf8' }).split('\n');
45
+ for (let i = 0; i < lines.length; i++) {
46
+ const line = lines[i];
47
+ if (line && line[0] !== ' ') {
48
+ const next = (lines[i + 1] || '').trim().split(' ');
49
+ if (next[0] === 'link/ether') {
50
+ iface = (line.split(' ')[1] || '').replace(/:$/, '');
51
+ mac = next[1] || '';
52
+ }
53
+ if (iface && mac) {
54
+ result[iface] = mac.trim();
55
+ iface = '';
56
+ mac = '';
57
+ }
58
+ }
59
+ }
60
+ }
61
+ else if (const_1.DARWIN || const_1.FREEBSD || const_1.NETBSD || const_1.OPENBSD) {
62
+ const lines = (0, node_child_process_1.execSync)('/sbin/ifconfig', { encoding: 'utf8' }).split('\n');
63
+ for (const line of lines) {
64
+ if (line && line[0] !== '\t' && line.indexOf(':') > 0) {
65
+ iface = line.split(':')[0];
66
+ }
67
+ else if (line.indexOf('\tether ') === 0) {
68
+ mac = line.split('\tether ')[1] || '';
69
+ if (iface && mac) {
70
+ result[iface] = mac.trim();
71
+ iface = '';
72
+ mac = '';
73
+ }
74
+ }
75
+ }
76
+ }
77
+ }
78
+ catch { }
79
+ return result;
80
+ };
36
81
  const getUniqueMacAddresses = () => {
37
82
  let macs = [];
38
83
  try {
39
84
  const interfaces = (0, node_os_1.networkInterfaces)();
85
+ let fallbackMacs = null;
40
86
  for (const dev in interfaces) {
41
87
  if (Object.keys(interfaces).includes(dev)) {
42
88
  interfaces[dev]?.forEach((details) => {
43
- if (details?.mac && details.mac !== '00:00:00:00:00:00') {
44
- const mac = details.mac.toLowerCase();
45
- if (macs.indexOf(mac) === -1) {
89
+ if (details?.mac) {
90
+ let mac = details.mac.toLowerCase();
91
+ if (MASKED_MACS.includes(mac)) {
92
+ if (fallbackMacs === null) {
93
+ fallbackMacs = getMacAddressesSync();
94
+ }
95
+ mac = (fallbackMacs[dev] || '').toLowerCase();
96
+ }
97
+ if (mac && !MASKED_MACS.includes(mac) && macs.indexOf(mac) === -1) {
46
98
  macs.push(mac);
47
99
  }
48
100
  }
@@ -1670,7 +1670,8 @@ const graphicsMetalVersion = (id) => {
1670
1670
  spdisplays_metalfeaturesetfamily14: 'family1_v4',
1671
1671
  spdisplays_metalfeaturesetfamily21: 'family2_v1'
1672
1672
  };
1673
- return families[id] || '';
1673
+ const version = /^spdisplays_metal(\d+)$/.exec(id);
1674
+ return families[id] || (version ? version[1] : '');
1674
1675
  };
1675
1676
  exports.graphicsMetalVersion = graphicsMetalVersion;
1676
1677
  exports.winProcessStatus = {
@@ -137,10 +137,10 @@ const calcNetworkSpeed = (iface, rx_bytes, tx_bytes, rx_dropped, rx_errors, tx_d
137
137
  _network[iface].tx_bytes = tx_bytes;
138
138
  _network[iface].rx_sec = null;
139
139
  _network[iface].tx_sec = null;
140
- _network[iface].rx_dropped = result.rx_dropped;
141
- _network[iface].rx_errors = result.rx_errors;
142
- _network[iface].tx_dropped = result.tx_dropped;
143
- _network[iface].tx_errors = result.tx_errors;
140
+ _network[iface].rx_dropped = rx_dropped;
141
+ _network[iface].rx_errors = rx_errors;
142
+ _network[iface].tx_dropped = tx_dropped;
143
+ _network[iface].tx_errors = tx_errors;
144
144
  _network[iface].ms = Date.now();
145
145
  _network[iface].last_ms = 0;
146
146
  _network[iface].operstate = operstate;
@@ -1,5 +1,5 @@
1
1
  import type { GpuData, GpuNvidiaData } from './types';
2
- export declare const getNvidiaSmi: () => Promise<string | null>;
2
+ export declare const getNvidiaSmi: () => Promise<string>;
3
3
  export declare const nvidiaSmi: () => Promise<string>;
4
4
  export declare const nvidiaDevices: () => Promise<({
5
5
  driverVersion: string | undefined;
@@ -22,7 +22,7 @@ const getNvidiaSmi = async () => {
22
22
  const basePath = String.raw `${const_1.WINDIR}\System32\DriverStore\FileRepository`;
23
23
  let lastMod = 0;
24
24
  for (const dir of await (0, promises_1.readdir)(basePath)) {
25
- if (!dir.toLowerCase().startsWith('nv')) {
25
+ if (!dir.toLowerCase().startsWith('nv') || !(0, security_1.isSafePathSegment)(dir)) {
26
26
  continue;
27
27
  }
28
28
  const smiPath = [basePath, dir, 'nvidia-smi.exe'].join('\\');
@@ -41,6 +41,7 @@ const getNvidiaSmi = async () => {
41
41
  else if (const_1.LINUX) {
42
42
  _nvidiaSmiPath = 'nvidia-smi';
43
43
  }
44
+ _nvidiaSmiPath = _nvidiaSmiPath || '';
44
45
  return _nvidiaSmiPath;
45
46
  };
46
47
  exports.getNvidiaSmi = getNvidiaSmi;
@@ -48,11 +49,9 @@ const nvidiaSmi = async () => {
48
49
  const nvidiaSmiExe = await (0, exports.getNvidiaSmi)();
49
50
  if (nvidiaSmiExe) {
50
51
  const nvidiaSmiOpts = '--query-gpu=driver_version,pci.sub_device_id,name,pci.bus_id,fan.speed,memory.total,memory.used,memory.free,utilization.gpu,utilization.memory,temperature.gpu,temperature.memory,power.draw,power.limit,clocks.gr,clocks.mem --format=csv,noheader,nounits';
51
- const cmd = `${nvidiaSmiExe} ${nvidiaSmiOpts}`;
52
52
  try {
53
- const sanitized = (0, security_1.sanitizeShellString)(cmd) + (const_1.LINUX ? ' 2>/dev/null' : '') + (const_1.WINDOWS ? ' 2> nul' : '');
54
- const { stdout } = await (0, exec_1.exec)(sanitized, const_1.execOptsWin);
55
- return stdout;
53
+ const { stdout } = await (0, exec_1.execFile)(nvidiaSmiExe, nvidiaSmiOpts.split(' '), const_1.execOptsWin);
54
+ return String(stdout);
56
55
  }
57
56
  catch { }
58
57
  }
@@ -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;