diff --git a/CHANGELOG.md b/CHANGELOG.md
index 32d957c..cf20c81 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -90,6 +90,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page.
| Version | Date | Comment |
| ------- | ---------- | --------------------------------------------------------------------------------------------------- |
+| 5.27.13 | 2025-12-10 | `cpuCurrentSpeed()` fix hasOwnProperty |
| 5.27.12 | 2025-12-09 | `networkConnections()` fix pid issue (macOS) |
| 5.27.11 | 2025-10-05 | `system()` added latest mac studio versions (macOS) |
| 5.27.10 | 2025-09-16 | `powerShell()` adapted params (windows) |
diff --git a/biome.json b/biome.json
new file mode 100644
index 0000000..33fde80
--- /dev/null
+++ b/biome.json
@@ -0,0 +1,62 @@
+{
+ "$schema": "https://biomejs.dev/schemas/2.3.1/schema.json",
+ "vcs": {
+ "enabled": true,
+ "clientKind": "git",
+ "useIgnoreFile": true
+ },
+ "files": {
+ "ignoreUnknown": false
+ },
+ "formatter": {
+ "enabled": true,
+ "indentWidth": 2,
+ "lineWidth": 200,
+ "indentStyle": "space",
+ "attributePosition": "auto"
+ },
+ "linter": {
+ "enabled": true,
+ "rules": {
+ "recommended": true,
+ "suspicious": {
+ "noExplicitAny": "off"
+ },
+ "complexity": {
+ "useLiteralKeys": "off"
+ }
+ }
+ },
+ "javascript": {
+ "formatter": {
+ "quoteStyle": "single",
+ "trailingCommas": "none",
+ "arrowParentheses": "always"
+ }
+ },
+ "json": {
+ "formatter": {
+ "trailingCommas": "none"
+ }
+ },
+ "html": {
+ "formatter": {
+ "enabled": true,
+ "indentStyle": "space",
+ "indentWidth": 2,
+ "lineWidth": 300,
+ "attributePosition": "auto"
+ },
+ "parser": {
+ "interpolation": true
+ }
+ },
+ "assist": {
+ "enabled": true,
+ "actions": {
+ "source": {
+ "organizeImports": "on"
+ }
+ }
+ }
+}
diff --git a/docs/history.html b/docs/history.html
index 7a63ccc..3951f6b 100644
--- a/docs/history.html
+++ b/docs/history.html
@@ -57,6 +57,11 @@
+
+ | 5.27.13 |
+ 2025-12-10 |
+ cpuCurrentSpeed() hasOwnProperty fix |
+
| 5.27.12 |
2025-12-09 |
diff --git a/docs/index.html b/docs/index.html
index 2150c53..45dccd5 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -170,7 +170,7 @@
systeminformation
- New Version: 5.27.12
+ New Version: 5.27.13
@@ -212,7 +212,7 @@
Downloads last month
diff --git a/lib/cpu.js b/lib/cpu.js
index ef8d7b7..5769fa9 100644
--- a/lib/cpu.js
+++ b/lib/cpu.js
@@ -19,15 +19,15 @@ const execSync = require('child_process').execSync;
const fs = require('fs');
const util = require('./util');
-let _platform = process.platform;
+const _platform = process.platform;
-const _linux = (_platform === 'linux' || _platform === 'android');
-const _darwin = (_platform === 'darwin');
-const _windows = (_platform === 'win32');
-const _freebsd = (_platform === 'freebsd');
-const _openbsd = (_platform === 'openbsd');
-const _netbsd = (_platform === 'netbsd');
-const _sunos = (_platform === 'sunos');
+const _linux = _platform === 'linux' || _platform === 'android';
+const _darwin = _platform === 'darwin';
+const _windows = _platform === 'win32';
+const _freebsd = _platform === 'freebsd';
+const _openbsd = _platform === 'openbsd';
+const _netbsd = _platform === 'netbsd';
+const _sunos = _platform === 'sunos';
let _cpu_speed = 0;
let _current_cpu = {
@@ -62,113 +62,113 @@ let _cpus = [];
let _corecount = 0;
const AMDBaseFrequencies = {
- '8346': '1.8',
- '8347': '1.9',
- '8350': '2.0',
- '8354': '2.2',
+ 8346: '1.8',
+ 8347: '1.9',
+ 8350: '2.0',
+ 8354: '2.2',
'8356|SE': '2.4',
- '8356': '2.3',
- '8360': '2.5',
- '2372': '2.1',
- '2373': '2.1',
- '2374': '2.2',
- '2376': '2.3',
- '2377': '2.3',
- '2378': '2.4',
- '2379': '2.4',
- '2380': '2.5',
- '2381': '2.5',
- '2382': '2.6',
- '2384': '2.7',
- '2386': '2.8',
- '2387': '2.8',
- '2389': '2.9',
- '2393': '3.1',
- '8374': '2.2',
- '8376': '2.3',
- '8378': '2.4',
- '8379': '2.4',
- '8380': '2.5',
- '8381': '2.5',
- '8382': '2.6',
- '8384': '2.7',
- '8386': '2.8',
- '8387': '2.8',
- '8389': '2.9',
- '8393': '3.1',
+ 8356: '2.3',
+ 8360: '2.5',
+ 2372: '2.1',
+ 2373: '2.1',
+ 2374: '2.2',
+ 2376: '2.3',
+ 2377: '2.3',
+ 2378: '2.4',
+ 2379: '2.4',
+ 2380: '2.5',
+ 2381: '2.5',
+ 2382: '2.6',
+ 2384: '2.7',
+ 2386: '2.8',
+ 2387: '2.8',
+ 2389: '2.9',
+ 2393: '3.1',
+ 8374: '2.2',
+ 8376: '2.3',
+ 8378: '2.4',
+ 8379: '2.4',
+ 8380: '2.5',
+ 8381: '2.5',
+ 8382: '2.6',
+ 8384: '2.7',
+ 8386: '2.8',
+ 8387: '2.8',
+ 8389: '2.9',
+ 8393: '3.1',
'2419EE': '1.8',
'2423HE': '2.0',
'2425HE': '2.1',
- '2427': '2.2',
- '2431': '2.4',
- '2435': '2.6',
+ 2427: '2.2',
+ 2431: '2.4',
+ 2435: '2.6',
'2439SE': '2.8',
'8425HE': '2.1',
- '8431': '2.4',
- '8435': '2.6',
+ 8431: '2.4',
+ 8435: '2.6',
'8439SE': '2.8',
- '4122': '2.2',
- '4130': '2.6',
+ 4122: '2.2',
+ 4130: '2.6',
'4162EE': '1.7',
'4164EE': '1.8',
'4170HE': '2.1',
'4174HE': '2.3',
'4176HE': '2.4',
- '4180': '2.6',
- '4184': '2.8',
+ 4180: '2.6',
+ 4184: '2.8',
'6124HE': '1.8',
'6128HE': '2.0',
'6132HE': '2.2',
- '6128': '2.0',
- '6134': '2.3',
- '6136': '2.4',
- '6140': '2.6',
+ 6128: '2.0',
+ 6134: '2.3',
+ 6136: '2.4',
+ 6140: '2.6',
'6164HE': '1.7',
'6166HE': '1.8',
- '6168': '1.9',
- '6172': '2.1',
- '6174': '2.2',
- '6176': '2.3',
+ 6168: '1.9',
+ 6172: '2.1',
+ 6174: '2.2',
+ 6176: '2.3',
'6176SE': '2.3',
'6180SE': '2.5',
- '3250': '2.5',
- '3260': '2.7',
- '3280': '2.4',
- '4226': '2.7',
- '4228': '2.8',
- '4230': '2.9',
- '4234': '3.1',
- '4238': '3.3',
- '4240': '3.4',
- '4256': '1.6',
- '4274': '2.5',
- '4276': '2.6',
- '4280': '2.8',
- '4284': '3.0',
- '6204': '3.3',
- '6212': '2.6',
- '6220': '3.0',
- '6234': '2.4',
- '6238': '2.6',
+ 3250: '2.5',
+ 3260: '2.7',
+ 3280: '2.4',
+ 4226: '2.7',
+ 4228: '2.8',
+ 4230: '2.9',
+ 4234: '3.1',
+ 4238: '3.3',
+ 4240: '3.4',
+ 4256: '1.6',
+ 4274: '2.5',
+ 4276: '2.6',
+ 4280: '2.8',
+ 4284: '3.0',
+ 6204: '3.3',
+ 6212: '2.6',
+ 6220: '3.0',
+ 6234: '2.4',
+ 6238: '2.6',
'6262HE': '1.6',
- '6272': '2.1',
- '6274': '2.2',
- '6276': '2.3',
- '6278': '2.4',
+ 6272: '2.1',
+ 6274: '2.2',
+ 6276: '2.3',
+ 6278: '2.4',
'6282SE': '2.6',
'6284SE': '2.7',
- '6308': '3.5',
- '6320': '2.8',
- '6328': '3.2',
+ 6308: '3.5',
+ 6320: '2.8',
+ 6328: '3.2',
'6338P': '2.3',
- '6344': '2.6',
- '6348': '2.8',
- '6366': '1.8',
+ 6344: '2.6',
+ 6348: '2.8',
+ 6366: '1.8',
'6370P': '2.0',
- '6376': '2.3',
- '6378': '2.4',
- '6380': '2.5',
- '6386': '2.8',
+ 6376: '2.3',
+ 6378: '2.4',
+ 6380: '2.5',
+ 6386: '2.8',
'FX|4100': '3.6',
'FX|4120': '3.9',
'FX|4130': '3.8',
@@ -199,23 +199,23 @@ const AMDBaseFrequencies = {
'FX|8370E': '3.3',
// ZEN Desktop CPUs
- '1200': '3.1',
+ 1200: '3.1',
'Pro 1200': '3.1',
'1300X': '3.5',
'Pro 1300': '3.5',
- '1400': '3.2',
+ 1400: '3.2',
'1500X': '3.5',
'Pro 1500': '3.5',
- '1600': '3.2',
+ 1600: '3.2',
'1600X': '3.6',
'Pro 1600': '3.2',
- '1700': '3.0',
+ 1700: '3.0',
'Pro 1700': '3.0',
'1700X': '3.4',
'Pro 1700X': '3.4',
'1800X': '3.6',
'1900X': '3.8',
- '1920': '3.2',
+ 1920: '3.2',
'1920X': '3.5',
'1950X': '3.4',
@@ -251,50 +251,50 @@ const AMDBaseFrequencies = {
'2800H': '3.3',
// ZEN Server Processors
- '7351': '2.4',
+ 7351: '2.4',
'7351P': '2.4',
- '7401': '2.0',
+ 7401: '2.0',
'7401P': '2.0',
'7551P': '2.0',
- '7551': '2.0',
- '7251': '2.1',
- '7261': '2.5',
- '7281': '2.1',
- '7301': '2.2',
- '7371': '3.1',
- '7451': '2.3',
- '7501': '2.0',
- '7571': '2.2',
- '7601': '2.2',
+ 7551: '2.0',
+ 7251: '2.1',
+ 7261: '2.5',
+ 7281: '2.1',
+ 7301: '2.2',
+ 7371: '3.1',
+ 7451: '2.3',
+ 7501: '2.0',
+ 7571: '2.2',
+ 7601: '2.2',
// ZEN Embedded Processors
- 'V1500B': '2.2',
- 'V1780B': '3.35',
- 'V1202B': '2.3',
- 'V1404I': '2.0',
- 'V1605B': '2.0',
- 'V1756B': '3.25',
- 'V1807B': '3.35',
+ V1500B: '2.2',
+ V1780B: '3.35',
+ V1202B: '2.3',
+ V1404I: '2.0',
+ V1605B: '2.0',
+ V1756B: '3.25',
+ V1807B: '3.35',
- '3101': '2.1',
- '3151': '2.7',
- '3201': '1.5',
- '3251': '2.5',
- '3255': '2.5',
- '3301': '2.0',
- '3351': '1.9',
- '3401': '1.85',
- '3451': '2.15',
+ 3101: '2.1',
+ 3151: '2.7',
+ 3201: '1.5',
+ 3251: '2.5',
+ 3255: '2.5',
+ 3301: '2.0',
+ 3351: '1.9',
+ 3401: '1.85',
+ 3451: '2.15',
// ZEN+ Desktop
'1200|AF': '3.1',
'2300X': '3.5',
'2500X': '3.6',
- '2600': '3.4',
+ 2600: '3.4',
'2600E': '3.1',
'1600|AF': '3.2',
'2600X': '3.6',
- '2700': '3.2',
+ 2700: '3.2',
'2700E': '2.8',
'Pro 2700': '3.2',
'2700X': '3.7',
@@ -340,11 +340,11 @@ const AMDBaseFrequencies = {
'3780U': '2.3',
// ZEN2 Desktop CPUS
- '3100': '3.6',
+ 3100: '3.6',
'3300X': '3.8',
- '3500': '3.6',
+ 3500: '3.6',
'3500X': '3.6',
- '3600': '3.6',
+ 3600: '3.6',
'Pro 3600': '3.6',
'3600X': '3.8',
'3600XT': '3.8',
@@ -352,7 +352,7 @@ const AMDBaseFrequencies = {
'3700X': '3.6',
'3800X': '3.9',
'3800XT': '3.9',
- '3900': '3.1',
+ 3900: '3.1',
'Pro 3900': '3.1',
'3900X': '3.8',
'3900XT': '3.8',
@@ -404,22 +404,22 @@ const AMDBaseFrequencies = {
'7402P': '2.8',
'7502P': '2.5',
'7702P': '2.0',
- '7252': '3.1',
- '7262': '3.2',
- '7272': '2.9',
- '7282': '2.8',
- '7302': '3.0',
- '7352': '2.3',
- '7402': '2.8',
- '7452': '2.35',
- '7502': '2.5',
- '7532': '2.4',
- '7542': '2.9',
- '7552': '2.2',
- '7642': '2.3',
- '7662': '2.0',
- '7702': '2.0',
- '7742': '2.25',
+ 7252: '3.1',
+ 7262: '3.2',
+ 7272: '2.9',
+ 7282: '2.8',
+ 7302: '3.0',
+ 7352: '2.3',
+ 7402: '2.8',
+ 7452: '2.35',
+ 7502: '2.5',
+ 7532: '2.4',
+ 7542: '2.9',
+ 7552: '2.2',
+ 7642: '2.3',
+ 7662: '2.0',
+ 7702: '2.0',
+ 7742: '2.25',
'7H12': '2.6',
'7F32': '3.7',
'7F52': '3.5',
@@ -428,26 +428,26 @@ const AMDBaseFrequencies = {
// Epyc (Milan)
'7773X': '2.2',
- '7763': '2.45',
- '7713': '2.0',
+ 7763: '2.45',
+ 7713: '2.0',
'7713P': '2.0',
- '7663': '2.0',
- '7643': '2.3',
+ 7663: '2.0',
+ 7643: '2.3',
'7573X': '2.8',
'75F3': '2.95',
- '7543': '2.8',
+ 7543: '2.8',
'7543P': '2.8',
- '7513': '2.6',
+ 7513: '2.6',
'7473X': '2.8',
- '7453': '2.75',
+ 7453: '2.75',
'74F3': '3.2',
- '7443': '2.85',
+ 7443: '2.85',
'7443P': '2.85',
- '7413': '2.65',
+ 7413: '2.65',
'7373X': '3.05',
'73F3': '3.5',
- '7343': '3.2',
- '7313': '3.0',
+ 7343: '3.2',
+ 7313: '3.0',
'7313P': '3.0',
'72F3': '3.7',
@@ -472,30 +472,30 @@ const AMDBaseFrequencies = {
'7995WX': '2.5',
// ZEN4
- '9754': '2.25',
+ 9754: '2.25',
'9754S': '2.25',
- '9734': '2.2',
+ 9734: '2.2',
'9684X': '2.55',
'9384X': '3.1',
'9184X': '3.55',
'9654P': '2.4',
- '9654': '2.4',
- '9634': '2.25',
+ 9654: '2.4',
+ 9634: '2.25',
'9554P': '3.1',
- '9554': '3.1',
- '9534': '2.45',
+ 9554: '3.1',
+ 9534: '2.45',
'9474F': '3.6',
'9454P': '2.75',
- '9454': '2.75',
+ 9454: '2.75',
'9374F': '3.85',
'9354P': '3.25',
- '9354': '3.25',
- '9334': '2.7',
+ 9354: '3.25',
+ 9334: '2.7',
'9274F': '4.05',
- '9254': '2.9',
- '9224': '2.5',
+ 9254: '2.9',
+ 9224: '2.5',
'9174F': '4.1',
- '9124': '3.0'
+ 9124: '3.0'
};
const socketTypes = {
@@ -589,16 +589,18 @@ const socketTypes = {
};
const socketTypesByName = {
- 'LGA1150': 'i7-5775C i3-4340 i3-4170 G3250 i3-4160T i3-4160 E3-1231 G3258 G3240 i7-4790S i7-4790K i7-4790 i5-4690K i5-4690 i5-4590T i5-4590S i5-4590 i5-4460 i3-4360 i3-4150 G1820 G3420 G3220 i7-4771 i5-4440 i3-4330 i3-4130T i3-4130 E3-1230 i7-4770S i7-4770K i7-4770 i5-4670K i5-4670 i5-4570T i5-4570S i5-4570 i5-4430',
- 'LGA1151': 'i9-9900KS E-2288G E-2224 G5420 i9-9900T i9-9900 i7-9700T i7-9700F i7-9700E i7-9700 i5-9600 i5-9500T i5-9500F i5-9500 i5-9400T i3-9350K i3-9300 i3-9100T i3-9100F i3-9100 G4930 i9-9900KF i7-9700KF i5-9600KF i5-9400F i5-9400 i3-9350KF i9-9900K i7-9700K i5-9600K G5500 G5400 i7-8700T i7-8086K i5-8600 i5-8500T i5-8500 i5-8400T i3-8300 i3-8100T G4900 i7-8700K i7-8700 i5-8600K i5-8400 i3-8350K i3-8100 E3-1270 G4600 G4560 i7-7700T i7-7700K i7-7700 i5-7600K i5-7600 i5-7500T i5-7500 i5-7400 i3-7350K i3-7300 i3-7100T i3-7100 G3930 G3900 G4400 i7-6700T i7-6700K i7-6700 i5-6600K i5-6600 i5-6500T i5-6500 i5-6400T i5-6400 i3-6300 i3-6100T i3-6100 E3-1270 E3-1270 T4500 T4400',
- '1155': 'G440 G460 G465 G470 G530T G540T G550T G1610T G1620T G530 G540 G1610 G550 G1620 G555 G1630 i3-2100T i3-2120T i3-3220T i3-3240T i3-3250T i3-2100 i3-2105 i3-2102 i3-3210 i3-3220 i3-2125 i3-2120 i3-3225 i3-2130 i3-3245 i3-3240 i3-3250 i5-3570T i5-2500T i5-2400S i5-2405S i5-2390T i5-3330S i5-2500S i5-3335S i5-2300 i5-3450S i5-3340S i5-3470S i5-3475S i5-3470T i5-2310 i5-3550S i5-2320 i5-3330 i5-3350P i5-3450 i5-2400 i5-3340 i5-3570S i5-2380P i5-2450P i5-3470 i5-2500K i5-3550 i5-2500 i5-3570 i5-3570K i5-2550K i7-3770T i7-2600S i7-3770S i7-2600K i7-2600 i7-3770 i7-3770K i7-2700K G620T G630T G640T G2020T G645T G2100T G2030T G622 G860T G620 G632 G2120T G630 G640 G2010 G840 G2020 G850 G645 G2030 G860 G2120 G870 G2130 G2140 E3-1220L E3-1220L E3-1260L E3-1265L E3-1220 E3-1225 E3-1220 E3-1235 E3-1225 E3-1230 E3-1230 E3-1240 E3-1245 E3-1270 E3-1275 E3-1240 E3-1245 E3-1270 E3-1280 E3-1275 E3-1290 E3-1280 E3-1290'
+ LGA1150:
+ 'i7-5775C i3-4340 i3-4170 G3250 i3-4160T i3-4160 E3-1231 G3258 G3240 i7-4790S i7-4790K i7-4790 i5-4690K i5-4690 i5-4590T i5-4590S i5-4590 i5-4460 i3-4360 i3-4150 G1820 G3420 G3220 i7-4771 i5-4440 i3-4330 i3-4130T i3-4130 E3-1230 i7-4770S i7-4770K i7-4770 i5-4670K i5-4670 i5-4570T i5-4570S i5-4570 i5-4430',
+ LGA1151:
+ 'i9-9900KS E-2288G E-2224 G5420 i9-9900T i9-9900 i7-9700T i7-9700F i7-9700E i7-9700 i5-9600 i5-9500T i5-9500F i5-9500 i5-9400T i3-9350K i3-9300 i3-9100T i3-9100F i3-9100 G4930 i9-9900KF i7-9700KF i5-9600KF i5-9400F i5-9400 i3-9350KF i9-9900K i7-9700K i5-9600K G5500 G5400 i7-8700T i7-8086K i5-8600 i5-8500T i5-8500 i5-8400T i3-8300 i3-8100T G4900 i7-8700K i7-8700 i5-8600K i5-8400 i3-8350K i3-8100 E3-1270 G4600 G4560 i7-7700T i7-7700K i7-7700 i5-7600K i5-7600 i5-7500T i5-7500 i5-7400 i3-7350K i3-7300 i3-7100T i3-7100 G3930 G3900 G4400 i7-6700T i7-6700K i7-6700 i5-6600K i5-6600 i5-6500T i5-6500 i5-6400T i5-6400 i3-6300 i3-6100T i3-6100 E3-1270 E3-1270 T4500 T4400',
+ 1155: 'G440 G460 G465 G470 G530T G540T G550T G1610T G1620T G530 G540 G1610 G550 G1620 G555 G1630 i3-2100T i3-2120T i3-3220T i3-3240T i3-3250T i3-2100 i3-2105 i3-2102 i3-3210 i3-3220 i3-2125 i3-2120 i3-3225 i3-2130 i3-3245 i3-3240 i3-3250 i5-3570T i5-2500T i5-2400S i5-2405S i5-2390T i5-3330S i5-2500S i5-3335S i5-2300 i5-3450S i5-3340S i5-3470S i5-3475S i5-3470T i5-2310 i5-3550S i5-2320 i5-3330 i5-3350P i5-3450 i5-2400 i5-3340 i5-3570S i5-2380P i5-2450P i5-3470 i5-2500K i5-3550 i5-2500 i5-3570 i5-3570K i5-2550K i7-3770T i7-2600S i7-3770S i7-2600K i7-2600 i7-3770 i7-3770K i7-2700K G620T G630T G640T G2020T G645T G2100T G2030T G622 G860T G620 G632 G2120T G630 G640 G2010 G840 G2020 G850 G645 G2030 G860 G2120 G870 G2130 G2140 E3-1220L E3-1220L E3-1260L E3-1265L E3-1220 E3-1225 E3-1220 E3-1235 E3-1225 E3-1230 E3-1230 E3-1240 E3-1245 E3-1270 E3-1275 E3-1240 E3-1245 E3-1270 E3-1280 E3-1275 E3-1290 E3-1280 E3-1290'
};
function getSocketTypesByName(str) {
let result = '';
for (const key in socketTypesByName) {
const names = socketTypesByName[key].split(' ');
- names.forEach(element => {
+ names.forEach((element) => {
if (str.indexOf(element) >= 0) {
result = key;
}
@@ -611,26 +613,59 @@ function cpuManufacturer(str) {
let result = str;
str = str.toLowerCase();
- if (str.indexOf('intel') >= 0) { result = 'Intel'; }
- if (str.indexOf('amd') >= 0) { result = 'AMD'; }
- if (str.indexOf('qemu') >= 0) { result = 'QEMU'; }
- if (str.indexOf('hygon') >= 0) { result = 'Hygon'; }
- if (str.indexOf('centaur') >= 0) { result = 'WinChip/Via'; }
- if (str.indexOf('vmware') >= 0) { result = 'VMware'; }
- if (str.indexOf('Xen') >= 0) { result = 'Xen Hypervisor'; }
- if (str.indexOf('tcg') >= 0) { result = 'QEMU'; }
- if (str.indexOf('apple') >= 0) { result = 'Apple'; }
- if (str.indexOf('sifive') >= 0) { result = 'SiFive'; }
- if (str.indexOf('thead') >= 0) { result = 'T-Head'; }
- if (str.indexOf('andestech') >= 0) { result = 'Andes Technology'; }
+ if (str.indexOf('intel') >= 0) {
+ result = 'Intel';
+ }
+ if (str.indexOf('amd') >= 0) {
+ result = 'AMD';
+ }
+ if (str.indexOf('qemu') >= 0) {
+ result = 'QEMU';
+ }
+ if (str.indexOf('hygon') >= 0) {
+ result = 'Hygon';
+ }
+ if (str.indexOf('centaur') >= 0) {
+ result = 'WinChip/Via';
+ }
+ if (str.indexOf('vmware') >= 0) {
+ result = 'VMware';
+ }
+ if (str.indexOf('Xen') >= 0) {
+ result = 'Xen Hypervisor';
+ }
+ if (str.indexOf('tcg') >= 0) {
+ result = 'QEMU';
+ }
+ if (str.indexOf('apple') >= 0) {
+ result = 'Apple';
+ }
+ if (str.indexOf('sifive') >= 0) {
+ result = 'SiFive';
+ }
+ if (str.indexOf('thead') >= 0) {
+ result = 'T-Head';
+ }
+ if (str.indexOf('andestech') >= 0) {
+ result = 'Andes Technology';
+ }
return result;
}
function cpuBrandManufacturer(res) {
- res.brand = res.brand.replace(/\(R\)+/g, '®').replace(/\s+/g, ' ').trim();
- res.brand = res.brand.replace(/\(TM\)+/g, '™').replace(/\s+/g, ' ').trim();
- res.brand = res.brand.replace(/\(C\)+/g, '©').replace(/\s+/g, ' ').trim();
+ res.brand = res.brand
+ .replace(/\(R\)+/g, '®')
+ .replace(/\s+/g, ' ')
+ .trim();
+ res.brand = res.brand
+ .replace(/\(TM\)+/g, '™')
+ .replace(/\s+/g, ' ')
+ .trim();
+ res.brand = res.brand
+ .replace(/\(C\)+/g, '©')
+ .replace(/\s+/g, ' ')
+ .trim();
res.brand = res.brand.replace(/CPU+/g, '').replace(/\s+/g, ' ').trim();
res.manufacturer = cpuManufacturer(res.brand);
@@ -646,7 +681,7 @@ function getAMDSpeed(brand) {
if ({}.hasOwnProperty.call(AMDBaseFrequencies, key)) {
let parts = key.split('|');
let found = 0;
- parts.forEach(item => {
+ parts.forEach((item) => {
if (brand.indexOf(item) > -1) {
found++;
}
@@ -663,7 +698,6 @@ function getAMDSpeed(brand) {
// CPU - brand, speed
function getCpu() {
-
return new Promise((resolve) => {
process.nextTick(() => {
const UNKNOWN = 'unknown';
@@ -690,7 +724,7 @@ function getCpu() {
virtualization: false,
cache: {}
};
- cpuFlags().then(flags => {
+ cpuFlags().then((flags) => {
result.flags = flags;
result.virtualization = flags.indexOf('vmx') > -1 || flags.indexOf('svm') > -1;
if (_darwin) {
@@ -707,8 +741,8 @@ function getCpu() {
_cpu_speed = result.speed;
result = cpuBrandManufacturer(result);
- result.speedMin = util.getValue(lines, 'hw.cpufrequency_min') ? (util.getValue(lines, 'hw.cpufrequency_min') / 1000000000.0) : result.speed;
- result.speedMax = util.getValue(lines, 'hw.cpufrequency_max') ? (util.getValue(lines, 'hw.cpufrequency_max') / 1000000000.0) : result.speed;
+ result.speedMin = util.getValue(lines, 'hw.cpufrequency_min') ? util.getValue(lines, 'hw.cpufrequency_min') / 1000000000.0 : result.speed;
+ result.speedMax = util.getValue(lines, 'hw.cpufrequency_max') ? util.getValue(lines, 'hw.cpufrequency_max') / 1000000000.0 : result.speed;
result.vendor = util.getValue(lines, 'machdep.cpu.vendor') || 'Apple';
result.family = util.getValue(lines, 'machdep.cpu.family') || util.getValue(lines, 'hw.cpufamily');
result.model = util.getValue(lines, 'machdep.cpu.model');
@@ -721,8 +755,8 @@ function getCpu() {
result.socket = 'SOC';
try {
const clusters = execSync('ioreg -c IOPlatformDevice -d 3 -r | grep cluster-type').toString().split('\n');
- const efficiencyCores = clusters.filter(line => line.indexOf('"E"') >= 0).length;
- const performanceCores = clusters.filter(line => line.indexOf('"P"') >= 0).length;
+ const efficiencyCores = clusters.filter((line) => line.indexOf('"E"') >= 0).length;
+ const performanceCores = clusters.filter((line) => line.indexOf('"P"') >= 0).length;
result.efficiencyCores = efficiencyCores;
result.performanceCores = performanceCores;
} catch (e) {
@@ -745,7 +779,9 @@ function getCpu() {
if (_linux) {
let modelline = '';
let lines = [];
- if (os.cpus()[0] && os.cpus()[0].model) { modelline = os.cpus()[0].model; }
+ if (os.cpus()[0] && os.cpus()[0].model) {
+ modelline = os.cpus()[0].model;
+ }
exec('export LC_ALL=C; lscpu; echo -n "Governor: "; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 2>/dev/null; echo; unset LC_ALL', function (error, stdout) {
if (!error) {
lines = stdout.toString().split('\n');
@@ -764,7 +800,9 @@ function getCpu() {
}
if (result.speed === 0) {
const current = getCpuCurrentSpeedSync();
- if (current.avg !== 0) { result.speed = current.avg; }
+ if (current.avg !== 0) {
+ result.speed = current.avg;
+ }
}
_cpu_speed = result.speed;
result.speedMin = Math.round(parseFloat(util.getValue(lines, 'cpu min mhz').replace(/,/g, '.')) / 10.0) / 100;
@@ -778,22 +816,30 @@ function getCpu() {
result.stepping = util.getValue(lines, 'stepping');
result.revision = util.getValue(lines, 'cpu revision');
result.cache.l1d = util.getValue(lines, 'l1d cache');
- if (result.cache.l1d) { result.cache.l1d = parseInt(result.cache.l1d) * (result.cache.l1d.indexOf('M') !== -1 ? 1024 * 1024 : (result.cache.l1d.indexOf('K') !== -1 ? 1024 : 1)); }
+ if (result.cache.l1d) {
+ result.cache.l1d = parseInt(result.cache.l1d) * (result.cache.l1d.indexOf('M') !== -1 ? 1024 * 1024 : result.cache.l1d.indexOf('K') !== -1 ? 1024 : 1);
+ }
result.cache.l1i = util.getValue(lines, 'l1i cache');
- if (result.cache.l1i) { result.cache.l1i = parseInt(result.cache.l1i) * (result.cache.l1i.indexOf('M') !== -1 ? 1024 * 1024 : (result.cache.l1i.indexOf('K') !== -1 ? 1024 : 1)); }
+ if (result.cache.l1i) {
+ result.cache.l1i = parseInt(result.cache.l1i) * (result.cache.l1i.indexOf('M') !== -1 ? 1024 * 1024 : result.cache.l1i.indexOf('K') !== -1 ? 1024 : 1);
+ }
result.cache.l2 = util.getValue(lines, 'l2 cache');
- if (result.cache.l2) { result.cache.l2 = parseInt(result.cache.l2) * (result.cache.l2.indexOf('M') !== -1 ? 1024 * 1024 : (result.cache.l2.indexOf('K') !== -1 ? 1024 : 1)); }
+ if (result.cache.l2) {
+ result.cache.l2 = parseInt(result.cache.l2) * (result.cache.l2.indexOf('M') !== -1 ? 1024 * 1024 : result.cache.l2.indexOf('K') !== -1 ? 1024 : 1);
+ }
result.cache.l3 = util.getValue(lines, 'l3 cache');
- if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3) * (result.cache.l3.indexOf('M') !== -1 ? 1024 * 1024 : (result.cache.l3.indexOf('K') !== -1 ? 1024 : 1)); }
+ if (result.cache.l3) {
+ result.cache.l3 = parseInt(result.cache.l3) * (result.cache.l3.indexOf('M') !== -1 ? 1024 * 1024 : result.cache.l3.indexOf('K') !== -1 ? 1024 : 1);
+ }
const threadsPerCore = util.getValue(lines, 'thread(s) per core') || '1';
const processors = util.getValue(lines, 'socket(s)') || '1';
const threadsPerCoreInt = parseInt(threadsPerCore, 10); // threads per code (normally only for performance cores)
- const processorsInt = parseInt(processors, 10) || 1; // number of sockets / processor units in machine (normally 1)
+ const processorsInt = parseInt(processors, 10) || 1; // number of sockets / processor units in machine (normally 1)
const coresPerSocket = parseInt(util.getValue(lines, 'core(s) per socket'), 10); // number of cores (e.g. 16 on i12900)
result.physicalCores = coresPerSocket ? coresPerSocket * processorsInt : result.cores / threadsPerCoreInt;
result.performanceCores = threadsPerCoreInt > 1 ? result.cores - result.physicalCores : result.cores;
- result.efficiencyCores = threadsPerCoreInt > 1 ? result.cores - (threadsPerCoreInt * result.performanceCores) : 0;
+ result.efficiencyCores = threadsPerCoreInt > 1 ? result.cores - threadsPerCoreInt * result.performanceCores : 0;
result.processors = processorsInt;
result.governor = util.getValue(lines, 'governor') || '';
@@ -832,7 +878,9 @@ function getCpu() {
if (_freebsd || _openbsd || _netbsd) {
let modelline = '';
let lines = [];
- if (os.cpus()[0] && os.cpus()[0].model) { modelline = os.cpus()[0].model; }
+ if (os.cpus()[0] && os.cpus()[0].model) {
+ modelline = os.cpus()[0].model;
+ }
exec('export LC_ALL=C; dmidecode -t 4; dmidecode -t 7 unset LC_ALL', function (error, stdout) {
let cache = [];
if (!error) {
@@ -849,7 +897,9 @@ function getCpu() {
}
if (result.speed === 0) {
const current = getCpuCurrentSpeedSync();
- if (current.avg !== 0) { result.speed = current.avg; }
+ if (current.avg !== 0) {
+ result.speed = current.avg;
+ }
}
_cpu_speed = result.speed;
result.speedMin = result.speed;
@@ -875,7 +925,7 @@ function getCpu() {
const sizeParts = util.getValue(lines, 'Installed Size').split(' ');
let size = parseInt(sizeParts[0], 10);
const unit = sizeParts.length > 1 ? sizeParts[1] : 'kb';
- size = size * (unit === 'kb' ? 1024 : (unit === 'mb' ? 1024 * 1024 : (unit === 'gb' ? 1024 * 1024 * 1024 : 1)));
+ size = size * (unit === 'kb' ? 1024 : unit === 'mb' ? 1024 * 1024 : unit === 'gb' ? 1024 * 1024 * 1024 : 1);
if (cacheType) {
if (cacheType === 'l1') {
result.cache[cacheType + 'd'] = size / 2;
@@ -903,13 +953,15 @@ function getCpu() {
if (_windows) {
try {
const workload = [];
- workload.push(util.powerShell('Get-CimInstance Win32_processor | select Name, Revision, L2CacheSize, L3CacheSize, Manufacturer, MaxClockSpeed, Description, UpgradeMethod, Caption, NumberOfLogicalProcessors, NumberOfCores | fl'));
+ workload.push(
+ util.powerShell(
+ 'Get-CimInstance Win32_processor | select Name, Revision, L2CacheSize, L3CacheSize, Manufacturer, MaxClockSpeed, Description, UpgradeMethod, Caption, NumberOfLogicalProcessors, NumberOfCores | fl'
+ )
+ );
workload.push(util.powerShell('Get-CimInstance Win32_CacheMemory | select CacheType,InstalledSize,Level | fl'));
workload.push(util.powerShell('(Get-CimInstance Win32_ComputerSystem).HypervisorPresent'));
- Promise.all(
- workload
- ).then((data) => {
+ Promise.all(workload).then((data) => {
let lines = data[0].split('\r\n');
let name = util.getValue(lines, 'name', ':') || '';
if (name.indexOf('@') >= 0) {
@@ -934,13 +986,13 @@ function getCpu() {
let description = util.getValue(lines, 'description', ':').split(' ');
for (let i = 0; i < description.length; i++) {
- if (description[i].toLowerCase().startsWith('family') && (i + 1) < description.length && description[i + 1]) {
+ if (description[i].toLowerCase().startsWith('family') && i + 1 < description.length && description[i + 1]) {
result.family = description[i + 1];
}
- if (description[i].toLowerCase().startsWith('model') && (i + 1) < description.length && description[i + 1]) {
+ if (description[i].toLowerCase().startsWith('model') && i + 1 < description.length && description[i + 1]) {
result.model = description[i + 1];
}
- if (description[i].toLowerCase().startsWith('stepping') && (i + 1) < description.length && description[i + 1]) {
+ if (description[i].toLowerCase().startsWith('stepping') && i + 1 < description.length && description[i + 1]) {
result.stepping = description[i + 1];
}
}
@@ -987,11 +1039,12 @@ function getCpu() {
// CPU - Processor Data
function cpu(callback) {
-
return new Promise((resolve) => {
process.nextTick(() => {
- getCpu().then(result => {
- if (callback) { callback(result); }
+ getCpu().then((result) => {
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
});
@@ -1004,21 +1057,23 @@ exports.cpu = cpu;
// CPU - current speed - in GHz
function getCpuCurrentSpeedSync() {
-
- let cpus = os.cpus();
+ const cpus = os.cpus();
let minFreq = 999999999;
let maxFreq = 0;
let avgFreq = 0;
- let cores = [];
- let speeds = [];
+ const cores = [];
+ const speeds = [];
- if (cpus && cpus.length && cpus[0].hasOwnProperty('speed')) {
+ if (cpus?.length && Object.prototype.hasOwnProperty.call(cpus[0], 'speed')) {
for (let i in cpus) {
speeds.push(cpus[i].speed > 100 ? (cpus[i].speed + 1) / 1000 : cpus[i].speed / 10);
}
} else if (_linux) {
try {
- const speedStrings = execSync('cat /proc/cpuinfo | grep "cpu MHz" | cut -d " " -f 3', util.execOptsLinux).toString().split('\n').filter((line) => line.length > 0);
+ const speedStrings = execSync('cat /proc/cpuinfo | grep "cpu MHz" | cut -d " " -f 3', util.execOptsLinux)
+ .toString()
+ .split('\n')
+ .filter((line) => line.length > 0);
for (let i in speedStrings) {
speeds.push(Math.floor(parseInt(speedStrings[i], 10) / 10) / 100);
}
@@ -1027,19 +1082,23 @@ function getCpuCurrentSpeedSync() {
}
}
- if (speeds && speeds.length) {
+ if (speeds?.length) {
try {
- for (let i in speeds) {
+ for (const i in speeds) {
avgFreq = avgFreq + speeds[i];
- if (speeds[i] > maxFreq) { maxFreq = speeds[i]; }
- if (speeds[i] < minFreq) { minFreq = speeds[i]; }
+ if (speeds[i] > maxFreq) {
+ maxFreq = speeds[i];
+ }
+ if (speeds[i] < minFreq) {
+ minFreq = speeds[i];
+ }
cores.push(parseFloat(speeds[i].toFixed(2)));
}
avgFreq = avgFreq / speeds.length;
return {
min: parseFloat(minFreq.toFixed(2)),
max: parseFloat(maxFreq.toFixed(2)),
- avg: parseFloat((avgFreq).toFixed(2)),
+ avg: parseFloat(avgFreq.toFixed(2)),
cores: cores
};
} catch (e) {
@@ -1061,7 +1120,6 @@ function getCpuCurrentSpeedSync() {
}
function cpuCurrentSpeed(callback) {
-
return new Promise((resolve) => {
process.nextTick(() => {
let result = getCpuCurrentSpeedSync();
@@ -1074,7 +1132,9 @@ function cpuCurrentSpeed(callback) {
cores: []
};
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
});
@@ -1087,7 +1147,6 @@ exports.cpuCurrentSpeed = cpuCurrentSpeed;
// if sensors are installed
function cpuTemperature(callback) {
-
return new Promise((resolve) => {
process.nextTick(() => {
let result = {
@@ -1119,7 +1178,8 @@ function cpuTemperature(callback) {
util.noop();
}
- const cmd = 'for mon in /sys/class/hwmon/hwmon*; do for label in "$mon"/temp*_label; do if [ -f $label ]; then value=${label%_*}_input; echo $(cat "$label")___$(cat "$value"); fi; done; done;';
+ const cmd =
+ 'for mon in /sys/class/hwmon/hwmon*; do for label in "$mon"/temp*_label; do if [ -f $label ]; then value=${label%_*}_input; echo $(cat "$label")___$(cat "$value"); fi; done; done;';
try {
exec(cmd, function (error, stdout) {
stdout = stdout.toString();
@@ -1129,7 +1189,7 @@ function cpuTemperature(callback) {
}
let lines = stdout.split('\n');
let tctl = 0;
- lines.forEach(line => {
+ lines.forEach((line) => {
const parts = line.split('___');
const label = parts[0];
const value = parts.length > 1 && parts[1] ? parts[1] : '0';
@@ -1151,13 +1211,15 @@ function cpuTemperature(callback) {
result.main = Math.round(result.cores.reduce((a, b) => a + b, 0) / result.cores.length);
}
let maxtmp = Math.max.apply(Math, result.cores);
- result.max = (maxtmp > result.main) ? maxtmp : result.main;
+ result.max = maxtmp > result.main ? maxtmp : result.main;
}
if (result.main !== null) {
if (result.max === null) {
result.max = result.main;
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
return;
}
@@ -1172,9 +1234,15 @@ function cpuTemperature(callback) {
if (line.trim() === '') {
newSectionStarts = true;
} else if (newSectionStarts) {
- if (line.trim().toLowerCase().startsWith('acpi')) { section = 'acpi'; }
- if (line.trim().toLowerCase().startsWith('pch')) { section = 'pch'; }
- if (line.trim().toLowerCase().startsWith('core')) { section = 'core'; }
+ if (line.trim().toLowerCase().startsWith('acpi')) {
+ section = 'acpi';
+ }
+ if (line.trim().toLowerCase().startsWith('pch')) {
+ section = 'pch';
+ }
+ if (line.trim().toLowerCase().startsWith('core')) {
+ section = 'core';
+ }
newSectionStarts = false;
}
let regex = /[+-]([^°]*)/g;
@@ -1205,7 +1273,7 @@ function cpuTemperature(callback) {
if (result.cores.length > 0) {
result.main = Math.round(result.cores.reduce((a, b) => a + b, 0) / result.cores.length);
let maxtmp = Math.max.apply(Math, result.cores);
- result.max = (maxtmp > result.main) ? maxtmp : result.main;
+ result.max = maxtmp > result.main ? maxtmp : result.main;
} else {
if (result.main === null && tdieTemp !== null) {
result.main = tdieTemp;
@@ -1213,7 +1281,9 @@ function cpuTemperature(callback) {
}
}
if (result.main !== null || result.max !== null) {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
return;
}
@@ -1228,7 +1298,9 @@ function cpuTemperature(callback) {
result.max = result.main;
}
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
} else {
@@ -1240,7 +1312,9 @@ function cpuTemperature(callback) {
result.max = result.main;
}
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
}
@@ -1248,7 +1322,9 @@ function cpuTemperature(callback) {
});
});
} catch (er) {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
}
@@ -1261,16 +1337,20 @@ function cpuTemperature(callback) {
const parts = line.split(':');
if (parts.length > 1) {
const temp = parseFloat(parts[1].replace(',', '.'));
- if (temp > result.max) { result.max = temp; }
+ if (temp > result.max) {
+ result.max = temp;
+ }
sum = sum + temp;
result.cores.push(temp);
}
});
if (result.cores.length) {
- result.main = Math.round(sum / result.cores.length * 100) / 100;
+ result.main = Math.round((sum / result.cores.length) * 100) / 100;
}
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
}
@@ -1297,11 +1377,15 @@ function cpuTemperature(callback) {
}
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
if (_sunos) {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
if (_windows) {
@@ -1309,12 +1393,17 @@ function cpuTemperature(callback) {
util.powerShell('Get-CimInstance MSAcpi_ThermalZoneTemperature -Namespace "root/wmi" | Select CurrentTemperature').then((stdout, error) => {
if (!error) {
let sum = 0;
- let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
+ let lines = stdout
+ .split('\r\n')
+ .filter((line) => line.trim() !== '')
+ .filter((line, idx) => idx > 0);
lines.forEach(function (line) {
let value = (parseInt(line, 10) - 2732) / 10;
if (!isNaN(value)) {
sum = sum + value;
- if (value > result.max) { result.max = value; }
+ if (value > result.max) {
+ result.max = value;
+ }
result.cores.push(value);
}
});
@@ -1322,11 +1411,15 @@ function cpuTemperature(callback) {
result.main = sum / result.cores.length;
}
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
} catch (e) {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
}
@@ -1340,7 +1433,6 @@ exports.cpuTemperature = cpuTemperature;
// CPU Flags
function cpuFlags(callback) {
-
return new Promise((resolve) => {
process.nextTick(() => {
let result = '';
@@ -1355,9 +1447,38 @@ function cpuFlags(callback) {
// as found on wikipedia:
// https://en.wikipedia.org/wiki/CPUID
let all_flags = [
- 'fpu', 'vme', 'de', 'pse', 'tsc', 'msr', 'pae', 'mce', 'cx8', 'apic',
- '', 'sep', 'mtrr', 'pge', 'mca', 'cmov', 'pat', 'pse-36', 'psn', 'clfsh',
- '', 'ds', 'acpi', 'mmx', 'fxsr', 'sse', 'sse2', 'ss', 'htt', 'tm', 'ia64', 'pbe'
+ 'fpu',
+ 'vme',
+ 'de',
+ 'pse',
+ 'tsc',
+ 'msr',
+ 'pae',
+ 'mce',
+ 'cx8',
+ 'apic',
+ '',
+ 'sep',
+ 'mtrr',
+ 'pge',
+ 'mca',
+ 'cmov',
+ 'pat',
+ 'pse-36',
+ 'psn',
+ 'clfsh',
+ '',
+ 'ds',
+ 'acpi',
+ 'mmx',
+ 'fxsr',
+ 'sse',
+ 'sse2',
+ 'ss',
+ 'htt',
+ 'tm',
+ 'ia64',
+ 'pbe'
];
for (let f = 0; f < all_flags.length; f++) {
if (flag_bin[f] === '1' && all_flags[f] !== '') {
@@ -1366,17 +1487,20 @@ function cpuFlags(callback) {
}
result = result.trim().toLowerCase();
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
} catch (e) {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
}
if (_linux) {
try {
-
exec('export LC_ALL=C; lscpu; unset LC_ALL', function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
@@ -1392,16 +1516,22 @@ function cpuFlags(callback) {
let lines = stdout.toString().split('\n');
result = util.getValue(lines, 'features', ':', true).toLowerCase();
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
} else {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
});
} catch (e) {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
}
@@ -1419,7 +1549,9 @@ function cpuFlags(callback) {
});
}
result = flags.join(' ').trim().toLowerCase();
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
}
@@ -1431,12 +1563,16 @@ function cpuFlags(callback) {
result = lines[0].split(':')[1].trim().toLowerCase();
}
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
}
if (_sunos) {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
});
@@ -1449,15 +1585,13 @@ exports.cpuFlags = cpuFlags;
// CPU Cache
function cpuCache(callback) {
-
return new Promise((resolve) => {
process.nextTick(() => {
-
let result = {
l1d: null,
l1i: null,
l2: null,
- l3: null,
+ l3: null
};
if (_linux) {
try {
@@ -1467,24 +1601,28 @@ function cpuCache(callback) {
lines.forEach(function (line) {
let parts = line.split(':');
if (parts[0].toUpperCase().indexOf('L1D CACHE') !== -1) {
- result.l1d = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : (parts[1].indexOf('K') !== -1 ? 1024 : 1));
+ result.l1d = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : parts[1].indexOf('K') !== -1 ? 1024 : 1);
}
if (parts[0].toUpperCase().indexOf('L1I CACHE') !== -1) {
- result.l1i = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : (parts[1].indexOf('K') !== -1 ? 1024 : 1));
+ result.l1i = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : parts[1].indexOf('K') !== -1 ? 1024 : 1);
}
if (parts[0].toUpperCase().indexOf('L2 CACHE') !== -1) {
- result.l2 = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : (parts[1].indexOf('K') !== -1 ? 1024 : 1));
+ result.l2 = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : parts[1].indexOf('K') !== -1 ? 1024 : 1);
}
if (parts[0].toUpperCase().indexOf('L3 CACHE') !== -1) {
- result.l3 = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : (parts[1].indexOf('K') !== -1 ? 1024 : 1));
+ result.l3 = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : parts[1].indexOf('K') !== -1 ? 1024 : 1);
}
});
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
} catch (e) {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
}
@@ -1503,7 +1641,7 @@ function cpuCache(callback) {
const sizeParts = util.getValue(lines, 'Installed Size').split(' ');
let size = parseInt(sizeParts[0], 10);
const unit = sizeParts.length > 1 ? sizeParts[1] : 'kb';
- size = size * (unit === 'kb' ? 1024 : (unit === 'mb' ? 1024 * 1024 : (unit === 'gb' ? 1024 * 1024 * 1024 : 1)));
+ size = size * (unit === 'kb' ? 1024 : unit === 'mb' ? 1024 * 1024 : unit === 'gb' ? 1024 * 1024 * 1024 : 1);
if (cacheType) {
if (cacheType === 'l1') {
result.cache[cacheType + 'd'] = size / 2;
@@ -1513,7 +1651,9 @@ function cpuCache(callback) {
}
}
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
}
@@ -1537,12 +1677,16 @@ function cpuCache(callback) {
}
});
}
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
}
if (_sunos) {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
if (_windows) {
@@ -1551,16 +1695,18 @@ function cpuCache(callback) {
workload.push(util.powerShell('Get-CimInstance Win32_processor | select L2CacheSize, L3CacheSize | fl'));
workload.push(util.powerShell('Get-CimInstance Win32_CacheMemory | select CacheType,InstalledSize,Level | fl'));
- Promise.all(
- workload
- ).then((data) => {
+ Promise.all(workload).then((data) => {
result = parseWinCache(data[0], data[1]);
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
} catch (e) {
- if (callback) { callback(result); }
+ if (callback) {
+ callback(result);
+ }
resolve(result);
}
}
@@ -1573,7 +1719,7 @@ function parseWinCache(linesProc, linesCache) {
l1d: null,
l1i: null,
l2: null,
- l3: null,
+ l3: null
};
// Win32_processor
@@ -1582,8 +1728,16 @@ function parseWinCache(linesProc, linesCache) {
result.l1i = 0;
result.l2 = util.getValue(lines, 'l2cachesize', ':');
result.l3 = util.getValue(lines, 'l3cachesize', ':');
- if (result.l2) { result.l2 = parseInt(result.l2, 10) * 1024; } else { result.l2 = 0; }
- if (result.l3) { result.l3 = parseInt(result.l3, 10) * 1024; } else { result.l3 = 0; }
+ if (result.l2) {
+ result.l2 = parseInt(result.l2, 10) * 1024;
+ } else {
+ result.l2 = 0;
+ }
+ if (result.l3) {
+ result.l3 = parseInt(result.l3, 10) * 1024;
+ } else {
+ result.l3 = 0;
+ }
// Win32_CacheMemory
const parts = linesCache.split(/\n\s*\n/);
@@ -1629,11 +1783,12 @@ exports.cpuCache = cpuCache;
// CPU - current load - in %
function getLoad() {
-
return new Promise((resolve) => {
process.nextTick(() => {
- let loads = os.loadavg().map(function (x) { return x / util.cores(); });
- let avgLoad = parseFloat((Math.max.apply(Math, loads)).toFixed(2));
+ let loads = os.loadavg().map(function (x) {
+ return x / util.cores();
+ });
+ let avgLoad = parseFloat(Math.max.apply(Math, loads).toFixed(2));
let result = {};
let now = Date.now() - _current_cpu.ms;
@@ -1652,7 +1807,7 @@ function getLoad() {
let totalSteal = 0;
let totalGuest = 0;
let cores = [];
- _corecount = (cpus && cpus.length) ? cpus.length : 0;
+ _corecount = cpus && cpus.length ? cpus.length : 0;
// linux: try to get other cpu stats
if (_linux) {
@@ -1686,36 +1841,36 @@ function getLoad() {
totalIrq += cpu.irq;
totalSteal += cpu.steal || 0;
totalGuest += cpu.guest || 0;
- let tmpTick = (_cpus && _cpus[i] && _cpus[i].totalTick ? _cpus[i].totalTick : 0);
- let tmpLoad = (_cpus && _cpus[i] && _cpus[i].totalLoad ? _cpus[i].totalLoad : 0);
- let tmpUser = (_cpus && _cpus[i] && _cpus[i].user ? _cpus[i].user : 0);
- let tmpSystem = (_cpus && _cpus[i] && _cpus[i].sys ? _cpus[i].sys : 0);
- let tmpNice = (_cpus && _cpus[i] && _cpus[i].nice ? _cpus[i].nice : 0);
- let tmpIdle = (_cpus && _cpus[i] && _cpus[i].idle ? _cpus[i].idle : 0);
- let tmpIrq = (_cpus && _cpus[i] && _cpus[i].irq ? _cpus[i].irq : 0);
- let tmpSteal = (_cpus && _cpus[i] && _cpus[i].steal ? _cpus[i].steal : 0);
- let tmpGuest = (_cpus && _cpus[i] && _cpus[i].guest ? _cpus[i].guest : 0);
+ let tmpTick = _cpus && _cpus[i] && _cpus[i].totalTick ? _cpus[i].totalTick : 0;
+ let tmpLoad = _cpus && _cpus[i] && _cpus[i].totalLoad ? _cpus[i].totalLoad : 0;
+ let tmpUser = _cpus && _cpus[i] && _cpus[i].user ? _cpus[i].user : 0;
+ let tmpSystem = _cpus && _cpus[i] && _cpus[i].sys ? _cpus[i].sys : 0;
+ let tmpNice = _cpus && _cpus[i] && _cpus[i].nice ? _cpus[i].nice : 0;
+ let tmpIdle = _cpus && _cpus[i] && _cpus[i].idle ? _cpus[i].idle : 0;
+ let tmpIrq = _cpus && _cpus[i] && _cpus[i].irq ? _cpus[i].irq : 0;
+ let tmpSteal = _cpus && _cpus[i] && _cpus[i].steal ? _cpus[i].steal : 0;
+ let tmpGuest = _cpus && _cpus[i] && _cpus[i].guest ? _cpus[i].guest : 0;
_cpus[i] = cpu;
_cpus[i].totalTick = _cpus[i].user + _cpus[i].sys + _cpus[i].nice + _cpus[i].irq + _cpus[i].steal + _cpus[i].guest + _cpus[i].idle;
_cpus[i].totalLoad = _cpus[i].user + _cpus[i].sys + _cpus[i].nice + _cpus[i].irq + _cpus[i].steal + _cpus[i].guest;
_cpus[i].currentTick = _cpus[i].totalTick - tmpTick;
- _cpus[i].load = (_cpus[i].totalLoad - tmpLoad);
- _cpus[i].loadUser = (_cpus[i].user - tmpUser);
- _cpus[i].loadSystem = (_cpus[i].sys - tmpSystem);
- _cpus[i].loadNice = (_cpus[i].nice - tmpNice);
- _cpus[i].loadIdle = (_cpus[i].idle - tmpIdle);
- _cpus[i].loadIrq = (_cpus[i].irq - tmpIrq);
- _cpus[i].loadSteal = (_cpus[i].steal - tmpSteal);
- _cpus[i].loadGuest = (_cpus[i].guest - tmpGuest);
+ _cpus[i].load = _cpus[i].totalLoad - tmpLoad;
+ _cpus[i].loadUser = _cpus[i].user - tmpUser;
+ _cpus[i].loadSystem = _cpus[i].sys - tmpSystem;
+ _cpus[i].loadNice = _cpus[i].nice - tmpNice;
+ _cpus[i].loadIdle = _cpus[i].idle - tmpIdle;
+ _cpus[i].loadIrq = _cpus[i].irq - tmpIrq;
+ _cpus[i].loadSteal = _cpus[i].steal - tmpSteal;
+ _cpus[i].loadGuest = _cpus[i].guest - tmpGuest;
cores[i] = {};
- cores[i].load = _cpus[i].load / _cpus[i].currentTick * 100;
- cores[i].loadUser = _cpus[i].loadUser / _cpus[i].currentTick * 100;
- cores[i].loadSystem = _cpus[i].loadSystem / _cpus[i].currentTick * 100;
- cores[i].loadNice = _cpus[i].loadNice / _cpus[i].currentTick * 100;
- cores[i].loadIdle = _cpus[i].loadIdle / _cpus[i].currentTick * 100;
- cores[i].loadIrq = _cpus[i].loadIrq / _cpus[i].currentTick * 100;
- cores[i].loadSteal = _cpus[i].loadSteal / _cpus[i].currentTick * 100;
- cores[i].loadGuest = _cpus[i].loadGuest / _cpus[i].currentTick * 100;
+ cores[i].load = (_cpus[i].load / _cpus[i].currentTick) * 100;
+ cores[i].loadUser = (_cpus[i].loadUser / _cpus[i].currentTick) * 100;
+ cores[i].loadSystem = (_cpus[i].loadSystem / _cpus[i].currentTick) * 100;
+ cores[i].loadNice = (_cpus[i].loadNice / _cpus[i].currentTick) * 100;
+ cores[i].loadIdle = (_cpus[i].loadIdle / _cpus[i].currentTick) * 100;
+ cores[i].loadIrq = (_cpus[i].loadIrq / _cpus[i].currentTick) * 100;
+ cores[i].loadSteal = (_cpus[i].loadSteal / _cpus[i].currentTick) * 100;
+ cores[i].loadGuest = (_cpus[i].loadGuest / _cpus[i].currentTick) * 100;
cores[i].rawLoad = _cpus[i].load;
cores[i].rawLoadUser = _cpus[i].loadUser;
cores[i].rawLoadSystem = _cpus[i].loadSystem;
@@ -1730,22 +1885,22 @@ function getLoad() {
let currentTick = totalTick - _current_cpu.tick;
result = {
avgLoad: avgLoad,
- currentLoad: (totalLoad - _current_cpu.load) / currentTick * 100,
- currentLoadUser: (totalUser - _current_cpu.user) / currentTick * 100,
- currentLoadSystem: (totalSystem - _current_cpu.system) / currentTick * 100,
- currentLoadNice: (totalNice - _current_cpu.nice) / currentTick * 100,
- currentLoadIdle: (totalIdle - _current_cpu.idle) / currentTick * 100,
- currentLoadIrq: (totalIrq - _current_cpu.irq) / currentTick * 100,
- currentLoadSteal: (totalSteal - _current_cpu.steal) / currentTick * 100,
- currentLoadGuest: (totalGuest - _current_cpu.guest) / currentTick * 100,
- rawCurrentLoad: (totalLoad - _current_cpu.load),
- rawCurrentLoadUser: (totalUser - _current_cpu.user),
- rawCurrentLoadSystem: (totalSystem - _current_cpu.system),
- rawCurrentLoadNice: (totalNice - _current_cpu.nice),
- rawCurrentLoadIdle: (totalIdle - _current_cpu.idle),
- rawCurrentLoadIrq: (totalIrq - _current_cpu.irq),
- rawCurrentLoadSteal: (totalSteal - _current_cpu.steal),
- rawCurrentLoadGuest: (totalGuest - _current_cpu.guest),
+ currentLoad: ((totalLoad - _current_cpu.load) / currentTick) * 100,
+ currentLoadUser: ((totalUser - _current_cpu.user) / currentTick) * 100,
+ currentLoadSystem: ((totalSystem - _current_cpu.system) / currentTick) * 100,
+ currentLoadNice: ((totalNice - _current_cpu.nice) / currentTick) * 100,
+ currentLoadIdle: ((totalIdle - _current_cpu.idle) / currentTick) * 100,
+ currentLoadIrq: ((totalIrq - _current_cpu.irq) / currentTick) * 100,
+ currentLoadSteal: ((totalSteal - _current_cpu.steal) / currentTick) * 100,
+ currentLoadGuest: ((totalGuest - _current_cpu.guest) / currentTick) * 100,
+ rawCurrentLoad: totalLoad - _current_cpu.load,
+ rawCurrentLoadUser: totalUser - _current_cpu.user,
+ rawCurrentLoadSystem: totalSystem - _current_cpu.system,
+ rawCurrentLoadNice: totalNice - _current_cpu.nice,
+ rawCurrentLoadIdle: totalIdle - _current_cpu.idle,
+ rawCurrentLoadIrq: totalIrq - _current_cpu.irq,
+ rawCurrentLoadSteal: totalSteal - _current_cpu.steal,
+ rawCurrentLoadGuest: totalGuest - _current_cpu.guest,
cpus: cores
};
_current_cpu = {
@@ -1774,18 +1929,18 @@ function getLoad() {
rawCurrentLoadIdle: result.rawCurrentLoadIdle,
rawCurrentLoadIrq: result.rawCurrentLoadIrq,
rawCurrentLoadSteal: result.rawCurrentLoadSteal,
- rawCurrentLoadGuest: result.rawCurrentLoadGuest,
+ rawCurrentLoadGuest: result.rawCurrentLoadGuest
};
} else {
let cores = [];
for (let i = 0; i < _corecount; i++) {
cores[i] = {};
- cores[i].load = _cpus[i].load / _cpus[i].currentTick * 100;
- cores[i].loadUser = _cpus[i].loadUser / _cpus[i].currentTick * 100;
- cores[i].loadSystem = _cpus[i].loadSystem / _cpus[i].currentTick * 100;
- cores[i].loadNice = _cpus[i].loadNice / _cpus[i].currentTick * 100;
- cores[i].loadIdle = _cpus[i].loadIdle / _cpus[i].currentTick * 100;
- cores[i].loadIrq = _cpus[i].loadIrq / _cpus[i].currentTick * 100;
+ cores[i].load = (_cpus[i].load / _cpus[i].currentTick) * 100;
+ cores[i].loadUser = (_cpus[i].loadUser / _cpus[i].currentTick) * 100;
+ cores[i].loadSystem = (_cpus[i].loadSystem / _cpus[i].currentTick) * 100;
+ cores[i].loadNice = (_cpus[i].loadNice / _cpus[i].currentTick) * 100;
+ cores[i].loadIdle = (_cpus[i].loadIdle / _cpus[i].currentTick) * 100;
+ cores[i].loadIrq = (_cpus[i].loadIrq / _cpus[i].currentTick) * 100;
cores[i].rawLoad = _cpus[i].load;
cores[i].rawLoadUser = _cpus[i].loadUser;
cores[i].rawLoadSystem = _cpus[i].loadSystem;
@@ -1822,11 +1977,12 @@ function getLoad() {
}
function currentLoad(callback) {
-
return new Promise((resolve) => {
process.nextTick(() => {
- getLoad().then(result => {
- if (callback) { callback(result); }
+ getLoad().then((result) => {
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
});
@@ -1840,10 +1996,8 @@ exports.currentLoad = currentLoad;
// since bootup
function getFullLoad() {
-
return new Promise((resolve) => {
process.nextTick(() => {
-
const cpus = os.cpus();
let totalUser = 0;
let totalSystem = 0;
@@ -1863,8 +2017,7 @@ function getFullLoad() {
totalIdle += cpu.idle;
}
let totalTicks = totalIdle + totalIrq + totalNice + totalSystem + totalUser;
- result = (totalTicks - totalIdle) / totalTicks * 100.0;
-
+ result = ((totalTicks - totalIdle) / totalTicks) * 100.0;
}
resolve(result);
});
@@ -1872,11 +2025,12 @@ function getFullLoad() {
}
function fullLoad(callback) {
-
return new Promise((resolve) => {
process.nextTick(() => {
- getFullLoad().then(result => {
- if (callback) { callback(result); }
+ getFullLoad().then((result) => {
+ if (callback) {
+ callback(result);
+ }
resolve(result);
});
});