systeminformation 6.0.0-beta.4 → 6.0.0-beta.6

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 CHANGED
@@ -289,6 +289,12 @@ Full function reference with examples can be found at [https://systeminformation
289
289
  | | max | X | X | X | X | | max temperature |
290
290
  | | socket | X | | | | | array socket temperatures |
291
291
  | | chipset | X | | | | | chipset temperature |
292
+ | si.fans() | [{...}] | X | | X* | X* | | detected fans |
293
+ | | [0].id | X | | X* | X* | | identifier, e.g. hwmon2/fan1 |
294
+ | | [0].label | X | | X* | X* | | label if the driver provides one |
295
+ | | [0].rpm | X | | X* | X* | | speed in rpm (or null) |
296
+ | | [0].pwm | X | | X* | X* | | duty cycle in % (or null) |
297
+ | | [0].source | X | | X* | X* | | chip / provider the value came from |
292
298
  | si.npu() | [{...}] | X | | X | X | | detected NPUs / AI accelerators |
293
299
  | | [0].vendor | X | | X | X | | vendor (Intel, AMD, Apple, ...) |
294
300
  | | [0].name | X | | X | X | | name |
@@ -380,6 +386,7 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
380
386
  | | [0].serial | | | X | X | | serial number |
381
387
  | | [0].displayId | | | X | X | | display ID |
382
388
  | | [0].main | X | | X | X | | true if main monitor |
389
+ | | [0].mirror | X | | X | X | | true if mirrored / duplicated |
383
390
  | | [0].builtin | X | | X | | | true if built-in monitor |
384
391
  | | [0].connection | X | | X | X | | e.g. DisplayPort or HDMI |
385
392
  | | [0].sizeX | X | | | X | | size in mm horizontal |
@@ -392,6 +399,7 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
392
399
  | | [0].positionX | X | | X | X | | display position X |
393
400
  | | [0].positionY | X | | X | X | | display position Y |
394
401
  | | [0].currentRefreshRate | X | | X | X | | current screen refresh rate |
402
+ | | [0].scale | | | | X | | DPI scaling factor, e.g. 1.5 |
395
403
 
396
404
  #### 7. Operating System
397
405
 
@@ -1003,6 +1011,11 @@ $ npm install macos-temperature-sensor --save
1003
1011
 
1004
1012
  `systeminformation` will then detect this additional library and return the temperature when calling systeminformations standard function `cpuTemperature()`.
1005
1013
  On Apple Silicon machines `macos-temperature-sensor` also enables the GPU temperature (`temperatureGpu`) in `gpu()`
1014
+ and - as soon as the package exposes them - the fan speeds in `fans()`.
1015
+
1016
+ #### Windows - Fan Speed
1017
+
1018
+ 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`.
1006
1019
 
1007
1020
  #### Windows Temperature, Battery, ...
1008
1021
 
@@ -236,7 +236,8 @@ exports.initDisplay = {
236
236
  currentResY: null,
237
237
  positionX: 0,
238
238
  positionY: 0,
239
- currentRefreshRate: null
239
+ currentRefreshRate: null,
240
+ scale: null
240
241
  };
241
242
  exports.initProcesses = {
242
243
  all: 0,
@@ -1,2 +1,3 @@
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>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fileExists = exports.getFilesInPath = void 0;
3
+ 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");
@@ -37,3 +37,12 @@ const fileExists = async (file) => {
37
37
  }
38
38
  };
39
39
  exports.fileExists = fileExists;
40
+ const readSysfs = async (file) => {
41
+ try {
42
+ return (await (0, promises_1.readFile)(file, 'utf8')).trim();
43
+ }
44
+ catch {
45
+ return '';
46
+ }
47
+ };
48
+ exports.readSysfs = readSysfs;
@@ -321,6 +321,13 @@ export type CpuTemperatureObject = {
321
321
  socket: number[];
322
322
  chipset: number | null;
323
323
  };
324
+ export type FanData = {
325
+ id: string;
326
+ label: string | null;
327
+ rpm: number | null;
328
+ pwm: number | null;
329
+ source: string;
330
+ };
324
331
  export type CurrentLoadData = {
325
332
  avgLoad: number;
326
333
  currentLoad: number;
@@ -824,6 +831,7 @@ export type DisplayData = {
824
831
  positionX: number;
825
832
  positionY: number;
826
833
  currentRefreshRate: number | null;
834
+ scale: number | null;
827
835
  };
828
836
  export type GpuNvidiaData = {
829
837
  driverVersion: string;
@@ -38,7 +38,8 @@ const parseDisplaysDarwin = (graphicsArr) => {
38
38
  currentResY: currentResolution.length > 1 ? parseInt(currentResolution[1], 10) : null,
39
39
  positionX: 0,
40
40
  positionY: 0,
41
- currentRefreshRate: currentResolutionParts.length > 1 ? parseInt(currentResolutionParts[1], 10) : null
41
+ currentRefreshRate: currentResolutionParts.length > 1 ? parseInt(currentResolutionParts[1], 10) : null,
42
+ scale: null
42
43
  });
43
44
  });
44
45
  }
@@ -0,0 +1,2 @@
1
+ import type { FanData } from '../common/types';
2
+ export declare const fans: () => Promise<FanData[]>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fans = void 0;
4
+ const common_1 = require("../common");
5
+ const fans = async () => {
6
+ await (0, common_1.nextTick)();
7
+ const result = [];
8
+ try {
9
+ const macosTemp = require('macos-temperature-sensor');
10
+ if (typeof macosTemp.fans === 'function') {
11
+ const res = macosTemp.fans();
12
+ if (Array.isArray(res)) {
13
+ res.forEach((fan, index) => {
14
+ result.push({
15
+ id: `fan${index}`,
16
+ label: fan?.label || null,
17
+ rpm: typeof fan?.rpm === 'number' ? Math.round(fan.rpm) : null,
18
+ pwm: typeof fan?.pwm === 'number' ? Math.round(fan.pwm) : null,
19
+ source: 'SMC'
20
+ });
21
+ });
22
+ }
23
+ }
24
+ }
25
+ catch { }
26
+ return result;
27
+ };
28
+ exports.fans = fans;
@@ -11,6 +11,7 @@ export { cpuCache } from './cpu-cache';
11
11
  export { cpuCurrentSpeed } from '../cpu-current-speed';
12
12
  export { cpuFlags } from './cpu-flags';
13
13
  export { cpuTemperature } from './cpu-temperature';
14
+ export { fans } from './fans';
14
15
  export { currentLoad } from '../cpu-current-load';
15
16
  export { diskLayout } from './disk-layout';
16
17
  export { disksIO } from './disks-io';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.software = 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.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 = void 0;
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;
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");
@@ -28,6 +28,8 @@ var cpu_flags_1 = require("./cpu-flags");
28
28
  Object.defineProperty(exports, "cpuFlags", { enumerable: true, get: function () { return cpu_flags_1.cpuFlags; } });
29
29
  var cpu_temperature_1 = require("./cpu-temperature");
30
30
  Object.defineProperty(exports, "cpuTemperature", { enumerable: true, get: function () { return cpu_temperature_1.cpuTemperature; } });
31
+ var fans_1 = require("./fans");
32
+ Object.defineProperty(exports, "fans", { enumerable: true, get: function () { return fans_1.fans; } });
31
33
  var cpu_current_load_1 = require("../cpu-current-load");
32
34
  Object.defineProperty(exports, "currentLoad", { enumerable: true, get: function () { return cpu_current_load_1.currentLoad; } });
33
35
  var disk_layout_1 = require("./disk-layout");
package/dist/fans.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const fans: () => Promise<import("./common/types").FanData[] | null>;
package/dist/fans.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fans = void 0;
4
+ const const_1 = require("./common/const");
5
+ const fans = async () => {
6
+ switch (true) {
7
+ case const_1.LINUX || const_1.ANDROID:
8
+ return (await import('./linux/fans.js')).fans();
9
+ case const_1.DARWIN:
10
+ return (await import('./darwin/fans.js')).fans();
11
+ case const_1.WINDOWS:
12
+ return (await import('./windows/fans.js')).fans();
13
+ default:
14
+ return null;
15
+ }
16
+ };
17
+ exports.fans = fans;
@@ -40,6 +40,7 @@ export declare const getDynamicData: (srv?: string, iface?: string) => Promise<{
40
40
  processes: import("./common/types").ProcessesData | null;
41
41
  currentLoad: import("./common/types").CurrentLoadData;
42
42
  temp: any;
43
+ fans: import("./common/types").FanData[] | null;
43
44
  networkStats: import("./common/types").NetworkStatsData[] | null;
44
45
  networkConnections: import("./common/types").NetworkConnectionsData[] | null;
45
46
  mem: any;
@@ -68,6 +69,7 @@ export declare const getAllData: (srv?: string, iface?: string) => Promise<{
68
69
  processes: import("./common/types").ProcessesData | null;
69
70
  currentLoad: import("./common/types").CurrentLoadData;
70
71
  temp: any;
72
+ fans: import("./common/types").FanData[] | null;
71
73
  networkStats: import("./common/types").NetworkStatsData[] | null;
72
74
  networkConnections: import("./common/types").NetworkConnectionsData[] | null;
73
75
  mem: any;
package/dist/get-data.js CHANGED
@@ -99,13 +99,14 @@ const getStaticData = async () => {
99
99
  exports.getStaticData = getStaticData;
100
100
  const getDynamicData = async (srv = '', iface = '') => {
101
101
  await (0, common_1.nextTick)();
102
- const [time, cpuCurrentSpeed, users, processes, currentLoad, temp, networkStats, networkConnections, mem, battery, services, fsSize, fsStats, disksIO, wifiNetworks, wifiConnections, fsOpenFiles, blockDevices, inetLatency] = await Promise.all([
102
+ const [time, cpuCurrentSpeed, users, processes, currentLoad, temp, fans, networkStats, networkConnections, mem, battery, services, fsSize, fsStats, disksIO, wifiNetworks, wifiConnections, fsOpenFiles, blockDevices, inetLatency] = await Promise.all([
103
103
  si.time(),
104
104
  si.cpuCurrentSpeed(),
105
105
  si.users(),
106
106
  si.processes(),
107
107
  si.currentLoad(),
108
108
  si.cpuTemperature(),
109
+ si.fans(),
109
110
  (async () => si.networkStats(iface || (await si.networkInterfaceDefault()) || '*'))(),
110
111
  si.networkConnections(),
111
112
  si.mem(),
@@ -129,6 +130,7 @@ const getDynamicData = async (srv = '', iface = '') => {
129
130
  processes,
130
131
  currentLoad,
131
132
  temp,
133
+ fans,
132
134
  networkStats,
133
135
  networkConnections,
134
136
  mem,
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export { cpuCache } from './cpu-cache';
11
11
  export { cpuCurrentSpeed } from './cpu-current-speed';
12
12
  export { cpuFlags } from './cpu-flags';
13
13
  export { cpuTemperature } from './cpu-temperature';
14
+ export { fans } from './fans';
14
15
  export { currentLoad } from './cpu-current-load';
15
16
  export { diskLayout } from './disk-layout';
16
17
  export { disksIO } from './disks-io';
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pci = exports.osInfo = exports.observe = exports.npu = exports.npm = exports.networkStats = exports.networkInterfaces = exports.networkInterfaceDefault = exports.networkGatewayDefault = exports.networkConnections = exports.mouse = exports.memLayout = exports.mem = exports.keyboard = exports.inetPublicIp = exports.inetLatency = exports.inetChecksite = exports.gpu = exports.getAllData = exports.getDynamicData = exports.getStaticData = exports.get = 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.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 = exports.shell = exports.services = exports.processLoad = exports.processes = exports.printer = void 0;
3
+ exports.osInfo = exports.observe = exports.npu = exports.npm = exports.networkStats = exports.networkInterfaces = exports.networkInterfaceDefault = exports.networkGatewayDefault = exports.networkConnections = exports.mouse = exports.memLayout = exports.mem = exports.keyboard = exports.inetPublicIp = exports.inetLatency = exports.inetChecksite = exports.gpu = exports.getAllData = exports.getDynamicData = exports.getStaticData = exports.get = 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 = exports.shell = exports.services = exports.processLoad = exports.processes = exports.printer = exports.pci = 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");
@@ -28,6 +28,8 @@ var cpu_flags_1 = require("./cpu-flags");
28
28
  Object.defineProperty(exports, "cpuFlags", { enumerable: true, get: function () { return cpu_flags_1.cpuFlags; } });
29
29
  var cpu_temperature_1 = require("./cpu-temperature");
30
30
  Object.defineProperty(exports, "cpuTemperature", { enumerable: true, get: function () { return cpu_temperature_1.cpuTemperature; } });
31
+ var fans_1 = require("./fans");
32
+ Object.defineProperty(exports, "fans", { enumerable: true, get: function () { return fans_1.fans; } });
31
33
  var cpu_current_load_1 = require("./cpu-current-load");
32
34
  Object.defineProperty(exports, "currentLoad", { enumerable: true, get: function () { return cpu_current_load_1.currentLoad; } });
33
35
  var disk_layout_1 = require("./disk-layout");
@@ -51,11 +51,15 @@ const parseAudioAlsa = (stdout) => {
51
51
  const [cards, pcms] = `${stdout}`.split('--pcm--');
52
52
  const lines = (cards || '').split('\n');
53
53
  lines.forEach((line, i) => {
54
- const card = line.match(/^\s*(\d+)\s+\[(.+?)\s*\]:\s*(\S+)\s+-\s+(.*)$/);
55
- if (card) {
54
+ const card = line.match(/^\s*(\d+)\s+\[(.+?)\s*\]:\s*(.*)$/);
55
+ if (card && card[3].trim()) {
56
56
  const index = card[1];
57
- const driver = card[3];
58
- const name = card[4].trim();
57
+ const sep = card[3].lastIndexOf(' - ');
58
+ const name = (sep >= 0 ? card[3].substring(sep + 3) : card[3]).trim();
59
+ let driver = (sep >= 0 ? card[3].substring(0, sep) : '').trim();
60
+ if (name && driver.endsWith(name)) {
61
+ driver = driver.substring(0, driver.length - name.length).trim();
62
+ }
59
63
  const longName = (lines[i + 1] || '').trim();
60
64
  const manufacturer = longName.indexOf(name) > 0 ? longName.substring(0, longName.indexOf(name)).trim() : '';
61
65
  const devices = (pcms || '').split('\n').filter((pcm) => pcm.indexOf(`/card${index}/pcm`) >= 0);
@@ -171,7 +171,8 @@ const displays = async () => {
171
171
  currentResY: null,
172
172
  positionX: 0,
173
173
  positionY: 0,
174
- currentRefreshRate: null
174
+ currentRefreshRate: null,
175
+ scale: null
175
176
  });
176
177
  }
177
178
  }
@@ -0,0 +1,2 @@
1
+ import type { FanData } from '../common/types';
2
+ export declare const fans: (hwmonPath?: string, thermalPath?: string) => Promise<FanData[]>;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fans = void 0;
4
+ const promises_1 = require("fs/promises");
5
+ const common_1 = require("../common");
6
+ const files_1 = require("../common/files");
7
+ const toNumber = (value) => {
8
+ const result = Number.parseFloat(value);
9
+ return Number.isNaN(result) ? null : result;
10
+ };
11
+ const pwmToPercent = (value) => {
12
+ const raw = toNumber(value);
13
+ return raw === null ? null : Math.round((raw / 255) * 100);
14
+ };
15
+ const hwmonFans = async (hwmonPath) => {
16
+ const fans = [];
17
+ let nodes = [];
18
+ try {
19
+ nodes = await (0, promises_1.readdir)(hwmonPath);
20
+ }
21
+ catch {
22
+ return fans;
23
+ }
24
+ for (const node of nodes) {
25
+ const entries = [];
26
+ try {
27
+ entries.push(...(await (0, promises_1.readdir)(`${hwmonPath}/${node}`)));
28
+ }
29
+ catch {
30
+ continue;
31
+ }
32
+ const source = (await (0, files_1.readSysfs)(`${hwmonPath}/${node}/name`)) || node;
33
+ for (const entry of entries) {
34
+ const match = /^fan(\d+)_input$/.exec(entry);
35
+ if (!match) {
36
+ continue;
37
+ }
38
+ const index = match[1];
39
+ const rpm = toNumber(await (0, files_1.readSysfs)(`${hwmonPath}/${node}/fan${index}_input`));
40
+ if (rpm === null) {
41
+ continue;
42
+ }
43
+ fans.push({
44
+ id: `${node}/fan${index}`,
45
+ label: (await (0, files_1.readSysfs)(`${hwmonPath}/${node}/fan${index}_label`)) || null,
46
+ rpm,
47
+ pwm: pwmToPercent(await (0, files_1.readSysfs)(`${hwmonPath}/${node}/pwm${index}`)),
48
+ source
49
+ });
50
+ }
51
+ }
52
+ return fans;
53
+ };
54
+ const coolingDeviceFans = async (thermalPath) => {
55
+ const fans = [];
56
+ let nodes = [];
57
+ try {
58
+ nodes = (await (0, promises_1.readdir)(thermalPath)).filter((entry) => entry.startsWith('cooling_device'));
59
+ }
60
+ catch {
61
+ return fans;
62
+ }
63
+ for (const node of nodes) {
64
+ const type = await (0, files_1.readSysfs)(`${thermalPath}/${node}/type`);
65
+ if (!type.toLowerCase().includes('fan')) {
66
+ continue;
67
+ }
68
+ const current = toNumber(await (0, files_1.readSysfs)(`${thermalPath}/${node}/cur_state`));
69
+ const max = toNumber(await (0, files_1.readSysfs)(`${thermalPath}/${node}/max_state`));
70
+ if (current === null || !max) {
71
+ continue;
72
+ }
73
+ fans.push({
74
+ id: node,
75
+ label: null,
76
+ rpm: null,
77
+ pwm: Math.round((current / max) * 100),
78
+ source: type
79
+ });
80
+ }
81
+ return fans;
82
+ };
83
+ const fans = async (hwmonPath = '/sys/class/hwmon', thermalPath = '/sys/class/thermal') => {
84
+ await (0, common_1.nextTick)();
85
+ const result = await hwmonFans(hwmonPath);
86
+ if (!result.length) {
87
+ return coolingDeviceFans(thermalPath);
88
+ }
89
+ return result;
90
+ };
91
+ exports.fans = fans;
package/dist/linux/gpu.js CHANGED
@@ -5,20 +5,13 @@ const promises_1 = require("fs/promises");
5
5
  const common_1 = require("../common");
6
6
  const const_1 = require("../common/const");
7
7
  const exec_1 = require("../common/exec");
8
+ const files_1 = require("../common/files");
8
9
  const nvidia_1 = require("../common/nvidia");
9
10
  const raspberry_1 = require("../common/raspberry");
10
- const readSysfs = async (file) => {
11
- try {
12
- return (await (0, promises_1.readFile)(file, 'utf8')).trim();
13
- }
14
- catch {
15
- return '';
16
- }
17
- };
18
11
  const readSysfsNumber = async (files, divisor = 1, preferNonZero = false) => {
19
12
  let fallback = null;
20
13
  for (const file of files) {
21
- const value = Number.parseFloat(await readSysfs(file));
14
+ const value = Number.parseFloat(await (0, files_1.readSysfs)(file));
22
15
  if (Number.isNaN(value)) {
23
16
  continue;
24
17
  }
@@ -77,7 +70,7 @@ const drmDevices = async (drmPath = '/sys/class/drm') => {
77
70
  temperatureGpu: await readSysfsNumber(hwmon.map((node) => `${node}/temp1_input`), 1000),
78
71
  powerDraw: await readSysfsNumber(hwmon.map((node) => `${node}/power1_input`), 1000000),
79
72
  powerLimit: await readSysfsNumber(hwmon.map((node) => `${node}/power1_max`), 1000000),
80
- clockCore: clockCore !== null ? clockCore : parseAmdClock(await readSysfs(`${devicePath}/pp_dpm_sclk`))
73
+ clockCore: clockCore !== null ? clockCore : parseAmdClock(await (0, files_1.readSysfs)(`${devicePath}/pp_dpm_sclk`))
81
74
  });
82
75
  }
83
76
  return devices;
@@ -11,6 +11,7 @@ export { cpuCache } from './cpu-cache';
11
11
  export { cpuCurrentSpeed } from '../cpu-current-speed';
12
12
  export { cpuFlags } from './cpu-flags';
13
13
  export { cpuTemperature } from './cpu-temperature';
14
+ export { fans } from './fans';
14
15
  export { currentLoad } from '../cpu-current-load';
15
16
  export { diskLayout } from './disk-layout';
16
17
  export { disksIO } from './disks-io';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.software = 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.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 = void 0;
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;
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");
@@ -28,6 +28,8 @@ var cpu_flags_1 = require("./cpu-flags");
28
28
  Object.defineProperty(exports, "cpuFlags", { enumerable: true, get: function () { return cpu_flags_1.cpuFlags; } });
29
29
  var cpu_temperature_1 = require("./cpu-temperature");
30
30
  Object.defineProperty(exports, "cpuTemperature", { enumerable: true, get: function () { return cpu_temperature_1.cpuTemperature; } });
31
+ var fans_1 = require("./fans");
32
+ Object.defineProperty(exports, "fans", { enumerable: true, get: function () { return fans_1.fans; } });
31
33
  var cpu_current_load_1 = require("../cpu-current-load");
32
34
  Object.defineProperty(exports, "currentLoad", { enumerable: true, get: function () { return cpu_current_load_1.currentLoad; } });
33
35
  var disk_layout_1 = require("./disk-layout");
@@ -5,7 +5,7 @@ const common_1 = require("../common");
5
5
  const mappings_1 = require("../common/mappings");
6
6
  const exec_1 = require("../common/exec");
7
7
  const windows_1 = require("../common/windows");
8
- const psCurrentModes = "Add-Type -AssemblyName System.Windows.Forms; if (-not ('SiDevMode' -as [Type])) { Add-Type -TypeDefinition 'using System;using System.Runtime.InteropServices;[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi)]public struct SIDEVMODE{[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)]public string dmDeviceName;public short dmSpecVersion;public short dmDriverVersion;public short dmSize;public short dmDriverExtra;public int dmFields;public int dmPositionX;public int dmPositionY;public int dmDisplayOrientation;public int dmDisplayFixedOutput;public short dmColor;public short dmDuplex;public short dmYResolution;public short dmTTOption;public short dmCollate;[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)]public string dmFormName;public short dmLogPixels;public int dmBitsPerPel;public int dmPelsWidth;public int dmPelsHeight;public int dmDisplayFlags;public int dmDisplayFrequency;public int dmICMMethod;public int dmICMIntent;public int dmMediaType;public int dmDitherType;public int dmReserved1;public int dmReserved2;public int dmPanningWidth;public int dmPanningHeight;}public class SiDevMode{[DllImport(\"user32.dll\",CharSet=CharSet.Ansi)]public static extern bool EnumDisplaySettings(string lpszDeviceName,int iModeNum,ref SIDEVMODE lpDevMode);}' }; [System.Windows.Forms.Screen]::AllScreens | ForEach-Object { $dm = New-Object SIDEVMODE; $dm.dmSize = [System.Runtime.InteropServices.Marshal]::SizeOf($dm); if ([SiDevMode]::EnumDisplaySettings($_.DeviceName, -1, [ref]$dm)) { $_.DeviceName + '|' + $dm.dmDisplayFrequency + '|' + $dm.dmBitsPerPel + '|' + $dm.dmPelsWidth + '|' + $dm.dmPelsHeight } }";
8
+ const psCurrentModes = "Add-Type -AssemblyName System.Windows.Forms; if (-not ('SiDevMode' -as [Type])) { Add-Type -TypeDefinition 'using System;using System.Runtime.InteropServices;[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi)]public struct SIDEVMODE{[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)]public string dmDeviceName;public short dmSpecVersion;public short dmDriverVersion;public short dmSize;public short dmDriverExtra;public int dmFields;public int dmPositionX;public int dmPositionY;public int dmDisplayOrientation;public int dmDisplayFixedOutput;public short dmColor;public short dmDuplex;public short dmYResolution;public short dmTTOption;public short dmCollate;[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)]public string dmFormName;public short dmLogPixels;public int dmBitsPerPel;public int dmPelsWidth;public int dmPelsHeight;public int dmDisplayFlags;public int dmDisplayFrequency;public int dmICMMethod;public int dmICMIntent;public int dmMediaType;public int dmDitherType;public int dmReserved1;public int dmReserved2;public int dmPanningWidth;public int dmPanningHeight;}public class SiDevMode{[DllImport(\"user32.dll\",CharSet=CharSet.Ansi)]public static extern bool EnumDisplaySettings(string lpszDeviceName,int iModeNum,ref SIDEVMODE lpDevMode);}' }; [System.Windows.Forms.Screen]::AllScreens | ForEach-Object { $dm = New-Object SIDEVMODE; $dm.dmSize = [System.Runtime.InteropServices.Marshal]::SizeOf($dm); if ([SiDevMode]::EnumDisplaySettings($_.DeviceName, -1, [ref]$dm)) { $_.DeviceName + '|' + $dm.dmDisplayFrequency + '|' + $dm.dmBitsPerPel + '|' + $dm.dmPelsWidth + '|' + $dm.dmPelsHeight + '|' + $dm.dmPositionX + '|' + $dm.dmPositionY } }";
9
9
  const parseLinesWindowsDisplaysPowershell = (ssections, monitors, dsections, connections, isections, currentModes) => {
10
10
  const displays = [];
11
11
  const desktopMonitors = (dsections || []).map((section) => {
@@ -33,6 +33,13 @@ const parseLinesWindowsDisplaysPowershell = (ssections, monitors, dsections, con
33
33
  const sizeY = monitor ? monitor.sizeY : '';
34
34
  const videoOutputTechnology = instanceName && connections[instanceName] !== undefined ? connections[instanceName] : '';
35
35
  const deviceName = (0, common_1.getValue)(linesScreen, 'DeviceName');
36
+ const mode = currentModes[deviceName.toLowerCase()];
37
+ const boundsWidth = (0, common_1.toInt)((0, common_1.getValue)(bounds, 'Width', ':'));
38
+ const boundsHeight = (0, common_1.toInt)((0, common_1.getValue)(bounds, 'Height', ':'));
39
+ const boundsX = (0, common_1.toInt)((0, common_1.getValue)(bounds, 'X', ':'));
40
+ const boundsY = (0, common_1.toInt)((0, common_1.getValue)(bounds, 'Y', ':'));
41
+ const resX = mode ? mode.width : boundsWidth;
42
+ const resY = mode ? mode.height : boundsHeight;
36
43
  const isection = instanceName ? isections.find((element) => element.instanceId.toLowerCase().startsWith(instanceName)) : undefined;
37
44
  const dsection = instanceName ? desktopMonitors.find((element) => element.deviceId && instanceName.startsWith(element.deviceId)) : undefined;
38
45
  displays.push({
@@ -47,16 +54,17 @@ const parseLinesWindowsDisplaysPowershell = (ssections, monitors, dsections, con
47
54
  mirror: !hasOwnScreen || (monitors.length > ssections.length && i === 0),
48
55
  builtin: videoOutputTechnology === '2147483648',
49
56
  connection: videoOutputTechnology && mappings_1.graphicsVideoTypes[videoOutputTechnology] ? mappings_1.graphicsVideoTypes[videoOutputTechnology] : '',
50
- resolutionX: (0, common_1.toInt)((0, common_1.getValue)(bounds, 'Width', ':')),
51
- resolutionY: (0, common_1.toInt)((0, common_1.getValue)(bounds, 'Height', ':')),
57
+ resolutionX: resX,
58
+ resolutionY: resY,
52
59
  sizeX: sizeX ? parseInt(sizeX, 10) : null,
53
60
  sizeY: sizeY ? parseInt(sizeY, 10) : null,
54
61
  pixelDepth: bitsPerPixel,
55
- currentResX: (0, common_1.toInt)((0, common_1.getValue)(bounds, 'Width', ':')),
56
- currentResY: (0, common_1.toInt)((0, common_1.getValue)(bounds, 'Height', ':')),
57
- positionX: (0, common_1.toInt)((0, common_1.getValue)(bounds, 'X', ':')),
58
- positionY: (0, common_1.toInt)((0, common_1.getValue)(bounds, 'Y', ':')),
59
- currentRefreshRate: currentModes[deviceName.toLowerCase()] || null
62
+ currentResX: resX,
63
+ currentResY: resY,
64
+ positionX: mode ? mode.positionX : boundsX,
65
+ positionY: mode ? mode.positionY : boundsY,
66
+ currentRefreshRate: (mode && mode.refreshRate) || null,
67
+ scale: mode && boundsWidth ? Math.round((mode.width / boundsWidth) * 100) / 100 : null
60
68
  });
61
69
  }
62
70
  }
@@ -83,7 +91,8 @@ const parseLinesWindowsDisplaysPowershell = (ssections, monitors, dsections, con
83
91
  currentResY: first ? first.resolutionY : 0,
84
92
  positionX: 0,
85
93
  positionY: 0,
86
- currentRefreshRate: null
94
+ currentRefreshRate: null,
95
+ scale: null
87
96
  });
88
97
  }
89
98
  return displays;
@@ -179,9 +188,15 @@ const displays = async () => {
179
188
  .split(/\n/)
180
189
  .forEach((element) => {
181
190
  const parts = element.split('|');
182
- const frequency = parts.length === 5 ? (0, common_1.toInt)(parts[1]) : 0;
183
- if (frequency > 1 && parts[0]) {
184
- currentModes[parts[0].trim().toLowerCase()] = frequency;
191
+ if (parts.length === 7 && parts[0].trim() && (0, common_1.toInt)(parts[3])) {
192
+ const frequency = (0, common_1.toInt)(parts[1]);
193
+ currentModes[parts[0].trim().toLowerCase()] = {
194
+ refreshRate: frequency > 1 ? frequency : 0,
195
+ width: (0, common_1.toInt)(parts[3]),
196
+ height: (0, common_1.toInt)(parts[4]),
197
+ positionX: (0, common_1.toInt)(parts[5]),
198
+ positionY: (0, common_1.toInt)(parts[6])
199
+ };
185
200
  }
186
201
  });
187
202
  result = parseLinesWindowsDisplaysPowershell(ssections, monitors, dsections, connections, isections, currentModes);
@@ -0,0 +1,2 @@
1
+ import type { FanData } from '../common/types';
2
+ export declare const fans: () => Promise<FanData[]>;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fans = void 0;
4
+ const common_1 = require("../common");
5
+ const windows_1 = require("../common/windows");
6
+ const HARDWARE_MONITORS = [
7
+ { namespace: 'root\\LibreHardwareMonitor', source: 'LibreHardwareMonitor' },
8
+ { namespace: 'root\\OpenHardwareMonitor', source: 'OpenHardwareMonitor' }
9
+ ];
10
+ const toNumber = (value) => {
11
+ const result = Number.parseFloat(value);
12
+ return Number.isNaN(result) ? null : result;
13
+ };
14
+ const win32Fans = async () => {
15
+ const fans = [];
16
+ try {
17
+ const entries = (0, windows_1.psArray)(await windows_1.ps.exec('Get-CimInstance Win32_Fan | Select-Object DeviceID,Name,DesiredSpeed | ConvertTo-Json -compress'));
18
+ entries.forEach((entry, index) => {
19
+ const rpm = toNumber(entry?.DesiredSpeed);
20
+ fans.push({
21
+ id: entry?.DeviceID || `fan${index}`,
22
+ label: entry?.Name || null,
23
+ rpm: rpm && rpm > 0 ? rpm : null,
24
+ pwm: null,
25
+ source: 'Win32_Fan'
26
+ });
27
+ });
28
+ }
29
+ catch { }
30
+ return fans;
31
+ };
32
+ const monitorFans = async (namespace, source) => {
33
+ const fans = [];
34
+ try {
35
+ const entries = (0, windows_1.psArray)(await windows_1.ps.exec(`Get-CimInstance -Namespace "${namespace}" -ClassName Sensor | Where-Object { $_.SensorType -eq 'Fan' -or $_.SensorType -eq 'Control' } | Select-Object Identifier,Name,SensorType,Value | ConvertTo-Json -compress`));
36
+ const controls = {};
37
+ entries.forEach((entry) => {
38
+ const value = toNumber(entry?.Value);
39
+ if (entry?.SensorType === 'Control' && entry?.Identifier && value !== null) {
40
+ controls[String(entry.Identifier).replace('/control/', '/fan/')] = Math.round(value);
41
+ }
42
+ });
43
+ entries.forEach((entry, index) => {
44
+ if (entry?.SensorType !== 'Fan') {
45
+ return;
46
+ }
47
+ const identifier = entry?.Identifier ? String(entry.Identifier) : `fan${index}`;
48
+ const pwm = controls[identifier];
49
+ fans.push({
50
+ id: identifier,
51
+ label: entry?.Name || null,
52
+ rpm: toNumber(entry?.Value),
53
+ pwm: pwm === undefined ? null : pwm,
54
+ source
55
+ });
56
+ });
57
+ }
58
+ catch { }
59
+ return fans;
60
+ };
61
+ const fans = async () => {
62
+ await (0, common_1.nextTick)();
63
+ for (const monitor of HARDWARE_MONITORS) {
64
+ const result = await monitorFans(monitor.namespace, monitor.source);
65
+ if (result.length) {
66
+ return result;
67
+ }
68
+ }
69
+ return win32Fans();
70
+ };
71
+ exports.fans = fans;
@@ -19,6 +19,7 @@ export { cpu } from './cpu';
19
19
  export { cpuCache } from './cpu-cache';
20
20
  export { cpuFlags } from './cpu-flags';
21
21
  export { cpuTemperature } from './cpu-temperature';
22
+ export { fans } from './fans';
22
23
  export { diskLayout } from './disk-layout';
23
24
  export { disksIO } from './disks-io';
24
25
  export { displays } from './displays';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.processLoad = 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.gpu = exports.fsStats = exports.fsSize = exports.fsOpenFiles = exports.displays = exports.disksIO = exports.diskLayout = exports.cpuTemperature = exports.cpuFlags = exports.cpuCache = exports.cpu = exports.chassis = exports.camera = exports.bluetoothDevices = exports.blockDevices = exports.bios = exports.battery = exports.baseboard = exports.audio = exports.vboxInfo = exports.versions = exports.version = exports.time = exports.inetChecksite = exports.dockerVolumes = exports.dockerInfo = exports.dockerImages = exports.dockerContainerStats = exports.dockerContainers = exports.dockerContainerProcesses = exports.dockerAll = exports.fullLoad = exports.cpuCurrentSpeed = exports.currentLoad = void 0;
4
- exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.uuid = exports.users = exports.usb = exports.thunderbolt = exports.system = exports.software = exports.shell = exports.services = exports.processes = void 0;
3
+ 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.gpu = exports.fsStats = exports.fsSize = exports.fsOpenFiles = exports.displays = exports.disksIO = exports.diskLayout = exports.fans = exports.cpuTemperature = exports.cpuFlags = exports.cpuCache = exports.cpu = exports.chassis = exports.camera = exports.bluetoothDevices = exports.blockDevices = exports.bios = exports.battery = exports.baseboard = exports.audio = exports.vboxInfo = exports.versions = exports.version = exports.time = exports.inetChecksite = exports.dockerVolumes = exports.dockerInfo = exports.dockerImages = exports.dockerContainerStats = exports.dockerContainers = exports.dockerContainerProcesses = exports.dockerAll = exports.fullLoad = exports.cpuCurrentSpeed = exports.currentLoad = void 0;
4
+ exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.uuid = exports.users = exports.usb = exports.thunderbolt = exports.system = exports.software = exports.shell = exports.services = exports.processes = exports.processLoad = void 0;
5
5
  var cpu_current_load_1 = require("../cpu-current-load");
6
6
  Object.defineProperty(exports, "currentLoad", { enumerable: true, get: function () { return cpu_current_load_1.currentLoad; } });
7
7
  var cpu_current_speed_1 = require("../cpu-current-speed");
@@ -50,6 +50,8 @@ var cpu_flags_1 = require("./cpu-flags");
50
50
  Object.defineProperty(exports, "cpuFlags", { enumerable: true, get: function () { return cpu_flags_1.cpuFlags; } });
51
51
  var cpu_temperature_1 = require("./cpu-temperature");
52
52
  Object.defineProperty(exports, "cpuTemperature", { enumerable: true, get: function () { return cpu_temperature_1.cpuTemperature; } });
53
+ var fans_1 = require("./fans");
54
+ Object.defineProperty(exports, "fans", { enumerable: true, get: function () { return fans_1.fans; } });
53
55
  var disk_layout_1 = require("./disk-layout");
54
56
  Object.defineProperty(exports, "diskLayout", { enumerable: true, get: function () { return disk_layout_1.diskLayout; } });
55
57
  var disks_io_1 = require("./disks-io");
@@ -24,16 +24,17 @@ const processLoad = async (proc) => {
24
24
  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
25
  const procStats = [];
26
26
  const list_new = {};
27
- let allcpuu = 0;
28
- let allcpus = 0;
27
+ let allcpuu = _process_cpu.all_utime;
28
+ let allcpus = _process_cpu.all_stime;
29
29
  processArray.forEach((element) => {
30
30
  const pid = element.ProcessId;
31
31
  const name = element.Caption;
32
32
  const utime = element.UserModeTime;
33
33
  const stime = element.KernelModeTime;
34
34
  const mem = element.WorkingSetSize;
35
- allcpuu = allcpuu + utime;
36
- allcpus = allcpus + stime;
35
+ const cpuOld = _process_cpu.list[pid];
36
+ allcpuu += utime - (cpuOld ? cpuOld.utime : 0);
37
+ allcpus += stime - (cpuOld ? cpuOld.stime : 0);
37
38
  procStats.push({
38
39
  pid: pid,
39
40
  name,
@@ -18,12 +18,13 @@ const calcProcStatWin = (procStat, all, _cpu_old) => {
18
18
  let cpuu = 0;
19
19
  let cpus = 0;
20
20
  if (_cpu_old.all > 0 && _cpu_old.list[procStat.pid]) {
21
- cpuu = ((procStat.utime - _cpu_old.list[procStat.pid].utime) / (all - _cpu_old.all)) * 100;
22
- cpus = ((procStat.stime - _cpu_old.list[procStat.pid].stime) / (all - _cpu_old.all)) * 100;
21
+ const delta = all - _cpu_old.all;
22
+ cpuu = delta > 0 ? ((procStat.utime - _cpu_old.list[procStat.pid].utime) / delta) * 100 : 0;
23
+ cpus = delta > 0 ? ((procStat.stime - _cpu_old.list[procStat.pid].stime) / delta) * 100 : 0;
23
24
  }
24
25
  else {
25
- cpuu = (procStat.utime / all) * 100;
26
- cpus = (procStat.stime / all) * 100;
26
+ cpuu = all > 0 ? (procStat.utime / all) * 100 : 0;
27
+ cpus = all > 0 ? (procStat.stime / all) * 100 : 0;
27
28
  }
28
29
  return {
29
30
  pid: procStat.pid,
@@ -45,8 +46,8 @@ const processes = async () => {
45
46
  const procs = [];
46
47
  const procStats = [];
47
48
  const list_new = {};
48
- let allcpuu = 0;
49
- let allcpus = 0;
49
+ let allcpuu = _processes_cpu.all_utime;
50
+ let allcpus = _processes_cpu.all_stime;
50
51
  processArray.forEach((element) => {
51
52
  const pid = element.ProcessId;
52
53
  const parentPid = element.ParentProcessId;
@@ -57,8 +58,9 @@ const processes = async () => {
57
58
  const utime = element.UserModeTime;
58
59
  const stime = element.KernelModeTime;
59
60
  const memw = element.WorkingSetSize;
60
- allcpuu = allcpuu + utime;
61
- allcpus = allcpus + stime;
61
+ const cpuOld = _processes_cpu.list[pid];
62
+ allcpuu += utime - (cpuOld ? cpuOld.utime : 0);
63
+ allcpus += stime - (cpuOld ? cpuOld.stime : 0);
62
64
  result.all++;
63
65
  if (!statusValue) {
64
66
  result.unknown++;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "6.0.0-beta.4",
3
+ "version": "6.0.0-beta.6",
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)",