sysiddr5 1.0.1-beta-4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sysiddr5 might be problematic. Click here for more details.

package/lib/cpu.js ADDED
@@ -0,0 +1,1704 @@
1
+ 'use strict';
2
+ // @ts-check
3
+ // ==================================================================================
4
+ // cpu.js
5
+ // ----------------------------------------------------------------------------------
6
+ // Description: System Information - library
7
+ // for Node.js
8
+ // Copyright: (c) 2014 - 2023
9
+ // Author: Sebastian Hildebrandt
10
+ // ----------------------------------------------------------------------------------
11
+ // License: MIT
12
+ // ==================================================================================
13
+ // 4. CPU
14
+ // ----------------------------------------------------------------------------------
15
+
16
+ const os = require('os');
17
+ const exec = require('child_process').exec;
18
+ const execSync = require('child_process').execSync;
19
+ const fs = require('fs');
20
+ const util = require('./util');
21
+
22
+ let _platform = process.platform;
23
+
24
+ const _linux = (_platform === 'linux' || _platform === 'android');
25
+ const _darwin = (_platform === 'darwin');
26
+ const _windows = (_platform === 'win32');
27
+ const _freebsd = (_platform === 'freebsd');
28
+ const _openbsd = (_platform === 'openbsd');
29
+ const _netbsd = (_platform === 'netbsd');
30
+ const _sunos = (_platform === 'sunos');
31
+
32
+ let _cpu_speed = 0;
33
+ let _current_cpu = {
34
+ user: 0,
35
+ nice: 0,
36
+ system: 0,
37
+ idle: 0,
38
+ irq: 0,
39
+ load: 0,
40
+ tick: 0,
41
+ ms: 0,
42
+ currentLoad: 0,
43
+ currentLoadUser: 0,
44
+ currentLoadSystem: 0,
45
+ currentLoadNice: 0,
46
+ currentLoadIdle: 0,
47
+ currentLoadIrq: 0,
48
+ rawCurrentLoad: 0,
49
+ rawCurrentLoadUser: 0,
50
+ rawCurrentLoadSystem: 0,
51
+ rawCurrentLoadNice: 0,
52
+ rawCurrentLoadIdle: 0,
53
+ rawCurrentLoadIrq: 0
54
+ };
55
+ let _cpus = [];
56
+ let _corecount = 0;
57
+
58
+ const AMDBaseFrequencies = {
59
+ '8346': '1.8',
60
+ '8347': '1.9',
61
+ '8350': '2.0',
62
+ '8354': '2.2',
63
+ '8356|SE': '2.4',
64
+ '8356': '2.3',
65
+ '8360': '2.5',
66
+ '2372': '2.1',
67
+ '2373': '2.1',
68
+ '2374': '2.2',
69
+ '2376': '2.3',
70
+ '2377': '2.3',
71
+ '2378': '2.4',
72
+ '2379': '2.4',
73
+ '2380': '2.5',
74
+ '2381': '2.5',
75
+ '2382': '2.6',
76
+ '2384': '2.7',
77
+ '2386': '2.8',
78
+ '2387': '2.8',
79
+ '2389': '2.9',
80
+ '2393': '3.1',
81
+ '8374': '2.2',
82
+ '8376': '2.3',
83
+ '8378': '2.4',
84
+ '8379': '2.4',
85
+ '8380': '2.5',
86
+ '8381': '2.5',
87
+ '8382': '2.6',
88
+ '8384': '2.7',
89
+ '8386': '2.8',
90
+ '8387': '2.8',
91
+ '8389': '2.9',
92
+ '8393': '3.1',
93
+ '2419EE': '1.8',
94
+ '2423HE': '2.0',
95
+ '2425HE': '2.1',
96
+ '2427': '2.2',
97
+ '2431': '2.4',
98
+ '2435': '2.6',
99
+ '2439SE': '2.8',
100
+ '8425HE': '2.1',
101
+ '8431': '2.4',
102
+ '8435': '2.6',
103
+ '8439SE': '2.8',
104
+ '4122': '2.2',
105
+ '4130': '2.6',
106
+ '4162EE': '1.7',
107
+ '4164EE': '1.8',
108
+ '4170HE': '2.1',
109
+ '4174HE': '2.3',
110
+ '4176HE': '2.4',
111
+ '4180': '2.6',
112
+ '4184': '2.8',
113
+ '6124HE': '1.8',
114
+ '6128HE': '2.0',
115
+ '6132HE': '2.2',
116
+ '6128': '2.0',
117
+ '6134': '2.3',
118
+ '6136': '2.4',
119
+ '6140': '2.6',
120
+ '6164HE': '1.7',
121
+ '6166HE': '1.8',
122
+ '6168': '1.9',
123
+ '6172': '2.1',
124
+ '6174': '2.2',
125
+ '6176': '2.3',
126
+ '6176SE': '2.3',
127
+ '6180SE': '2.5',
128
+ '3250': '2.5',
129
+ '3260': '2.7',
130
+ '3280': '2.4',
131
+ '4226': '2.7',
132
+ '4228': '2.8',
133
+ '4230': '2.9',
134
+ '4234': '3.1',
135
+ '4238': '3.3',
136
+ '4240': '3.4',
137
+ '4256': '1.6',
138
+ '4274': '2.5',
139
+ '4276': '2.6',
140
+ '4280': '2.8',
141
+ '4284': '3.0',
142
+ '6204': '3.3',
143
+ '6212': '2.6',
144
+ '6220': '3.0',
145
+ '6234': '2.4',
146
+ '6238': '2.6',
147
+ '6262HE': '1.6',
148
+ '6272': '2.1',
149
+ '6274': '2.2',
150
+ '6276': '2.3',
151
+ '6278': '2.4',
152
+ '6282SE': '2.6',
153
+ '6284SE': '2.7',
154
+ '6308': '3.5',
155
+ '6320': '2.8',
156
+ '6328': '3.2',
157
+ '6338P': '2.3',
158
+ '6344': '2.6',
159
+ '6348': '2.8',
160
+ '6366': '1.8',
161
+ '6370P': '2.0',
162
+ '6376': '2.3',
163
+ '6378': '2.4',
164
+ '6380': '2.5',
165
+ '6386': '2.8',
166
+ 'FX|4100': '3.6',
167
+ 'FX|4120': '3.9',
168
+ 'FX|4130': '3.8',
169
+ 'FX|4150': '3.8',
170
+ 'FX|4170': '4.2',
171
+ 'FX|6100': '3.3',
172
+ 'FX|6120': '3.6',
173
+ 'FX|6130': '3.6',
174
+ 'FX|6200': '3.8',
175
+ 'FX|8100': '2.8',
176
+ 'FX|8120': '3.1',
177
+ 'FX|8140': '3.2',
178
+ 'FX|8150': '3.6',
179
+ 'FX|8170': '3.9',
180
+ 'FX|4300': '3.8',
181
+ 'FX|4320': '4.0',
182
+ 'FX|4350': '4.2',
183
+ 'FX|6300': '3.5',
184
+ 'FX|6350': '3.9',
185
+ 'FX|8300': '3.3',
186
+ 'FX|8310': '3.4',
187
+ 'FX|8320': '3.5',
188
+ 'FX|8350': '4.0',
189
+ 'FX|8370': '4.0',
190
+ 'FX|9370': '4.4',
191
+ 'FX|9590': '4.7',
192
+ 'FX|8320E': '3.2',
193
+ 'FX|8370E': '3.3',
194
+
195
+ // ZEN Desktop CPUs
196
+ '1200': '3.1',
197
+ 'Pro 1200': '3.1',
198
+ '1300X': '3.5',
199
+ 'Pro 1300': '3.5',
200
+ '1400': '3.2',
201
+ '1500X': '3.5',
202
+ 'Pro 1500': '3.5',
203
+ '1600': '3.2',
204
+ '1600X': '3.6',
205
+ 'Pro 1600': '3.2',
206
+ '1700': '3.0',
207
+ 'Pro 1700': '3.0',
208
+ '1700X': '3.4',
209
+ 'Pro 1700X': '3.4',
210
+ '1800X': '3.6',
211
+ '1900X': '3.8',
212
+ '1920': '3.2',
213
+ '1920X': '3.5',
214
+ '1950X': '3.4',
215
+
216
+ // ZEN Desktop APUs
217
+ '200GE': '3.2',
218
+ 'Pro 200GE': '3.2',
219
+ '220GE': '3.4',
220
+ '240GE': '3.5',
221
+ '3000G': '3.5',
222
+ '300GE': '3.4',
223
+ '3050GE': '3.4',
224
+ '2200G': '3.5',
225
+ 'Pro 2200G': '3.5',
226
+ '2200GE': '3.2',
227
+ 'Pro 2200GE': '3.2',
228
+ '2400G': '3.6',
229
+ 'Pro 2400G': '3.6',
230
+ '2400GE': '3.2',
231
+ 'Pro 2400GE': '3.2',
232
+
233
+ // ZEN Mobile APUs
234
+ 'Pro 200U': '2.3',
235
+ '300U': '2.4',
236
+ '2200U': '2.5',
237
+ '3200U': '2.6',
238
+ '2300U': '2.0',
239
+ 'Pro 2300U': '2.0',
240
+ '2500U': '2.0',
241
+ 'Pro 2500U': '2.2',
242
+ '2600H': '3.2',
243
+ '2700U': '2.0',
244
+ 'Pro 2700U': '2.2',
245
+ '2800H': '3.3',
246
+
247
+ // ZEN Server Processors
248
+ '7351': '2.4',
249
+ '7351P': '2.4',
250
+ '7401': '2.0',
251
+ '7401P': '2.0',
252
+ '7551P': '2.0',
253
+ '7551': '2.0',
254
+ '7251': '2.1',
255
+ '7261': '2.5',
256
+ '7281': '2.1',
257
+ '7301': '2.2',
258
+ '7371': '3.1',
259
+ '7451': '2.3',
260
+ '7501': '2.0',
261
+ '7571': '2.2',
262
+ '7601': '2.2',
263
+
264
+ // ZEN Embedded Processors
265
+ 'V1500B': '2.2',
266
+ 'V1780B': '3.35',
267
+ 'V1202B': '2.3',
268
+ 'V1404I': '2.0',
269
+ 'V1605B': '2.0',
270
+ 'V1756B': '3.25',
271
+ 'V1807B': '3.35',
272
+
273
+ '3101': '2.1',
274
+ '3151': '2.7',
275
+ '3201': '1.5',
276
+ '3251': '2.5',
277
+ '3255': '2.5',
278
+ '3301': '2.0',
279
+ '3351': '1.9',
280
+ '3401': '1.85',
281
+ '3451': '2.15',
282
+
283
+ // ZEN+ Desktop
284
+ '1200|AF': '3.1',
285
+ '2300X': '3.5',
286
+ '2500X': '3.6',
287
+ '2600': '3.4',
288
+ '2600E': '3.1',
289
+ '1600|AF': '3.2',
290
+ '2600X': '3.6',
291
+ '2700': '3.2',
292
+ '2700E': '2.8',
293
+ 'Pro 2700': '3.2',
294
+ '2700X': '3.7',
295
+ 'Pro 2700X': '3.6',
296
+ '2920X': '3.5',
297
+ '2950X': '3.5',
298
+ '2970WX': '3.0',
299
+ '2990WX': '3.0',
300
+
301
+ // ZEN+ Desktop APU
302
+ 'Pro 300GE': '3.4',
303
+ 'Pro 3125GE': '3.4',
304
+ '3150G': '3.5',
305
+ 'Pro 3150G': '3.5',
306
+ '3150GE': '3.3',
307
+ 'Pro 3150GE': '3.3',
308
+ '3200G': '3.6',
309
+ 'Pro 3200G': '3.6',
310
+ '3200GE': '3.3',
311
+ 'Pro 3200GE': '3.3',
312
+ '3350G': '3.6',
313
+ 'Pro 3350G': '3.6',
314
+ '3350GE': '3.3',
315
+ 'Pro 3350GE': '3.3',
316
+ '3400G': '3.7',
317
+ 'Pro 3400G': '3.7',
318
+ '3400GE': '3.3',
319
+ 'Pro 3400GE': '3.3',
320
+
321
+ // ZEN+ Mobile
322
+ '3300U': '2.1',
323
+ 'PRO 3300U': '2.1',
324
+ '3450U': '2.1',
325
+ '3500U': '2.1',
326
+ 'PRO 3500U': '2.1',
327
+ '3500C': '2.1',
328
+ '3550H': '2.1',
329
+ '3580U': '2.1',
330
+ '3700U': '2.3',
331
+ 'PRO 3700U': '2.3',
332
+ '3700C': '2.3',
333
+ '3750H': '2.3',
334
+ '3780U': '2.3',
335
+
336
+ // ZEN2 Desktop CPUS
337
+ '3100': '3.6',
338
+ '3300X': '3.8',
339
+ '3500': '3.6',
340
+ '3500X': '3.6',
341
+ '3600': '3.6',
342
+ 'Pro 3600': '3.6',
343
+ '3600X': '3.8',
344
+ '3600XT': '3.8',
345
+ 'Pro 3700': '3.6',
346
+ '3700X': '3.6',
347
+ '3800X': '3.9',
348
+ '3800XT': '3.9',
349
+ '3900': '3.1',
350
+ 'Pro 3900': '3.1',
351
+ '3900X': '3.8',
352
+ '3900XT': '3.8',
353
+ '3950X': '3.5',
354
+ '3960X': '3.8',
355
+ '3970X': '3.7',
356
+ '3990X': '2.9',
357
+ '3945WX': '4.0',
358
+ '3955WX': '3.9',
359
+ '3975WX': '3.5',
360
+ '3995WX': '2.7',
361
+
362
+ // ZEN2 Desktop APUs
363
+ '4300GE': '3.5',
364
+ 'Pro 4300GE': '3.5',
365
+ '4300G': '3.8',
366
+ 'Pro 4300G': '3.8',
367
+ '4600GE': '3.3',
368
+ 'Pro 4650GE': '3.3',
369
+ '4600G': '3.7',
370
+ 'Pro 4650G': '3.7',
371
+ '4700GE': '3.1',
372
+ 'Pro 4750GE': '3.1',
373
+ '4700G': '3.6',
374
+ 'Pro 4750G': '3.6',
375
+ '4300U': '2.7',
376
+ '4450U': '2.5',
377
+ 'Pro 4450U': '2.5',
378
+ '4500U': '2.3',
379
+ '4600U': '2.1',
380
+ 'PRO 4650U': '2.1',
381
+ '4680U': '2.1',
382
+ '4600HS': '3.0',
383
+ '4600H': '3.0',
384
+ '4700U': '2.0',
385
+ 'PRO 4750U': '1.7',
386
+ '4800U': '1.8',
387
+ '4800HS': '2.9',
388
+ '4800H': '2.9',
389
+ '4900HS': '3.0',
390
+ '4900H': '3.3',
391
+ '5300U': '2.6',
392
+ '5500U': '2.1',
393
+ '5700U': '1.8',
394
+
395
+ // ZEN2 - EPYC
396
+ '7232P': '3.1',
397
+ '7302P': '3.0',
398
+ '7402P': '2.8',
399
+ '7502P': '2.5',
400
+ '7702P': '2.0',
401
+ '7252': '3.1',
402
+ '7262': '3.2',
403
+ '7272': '2.9',
404
+ '7282': '2.8',
405
+ '7302': '3.0',
406
+ '7352': '2.3',
407
+ '7402': '2.8',
408
+ '7452': '2.35',
409
+ '7502': '2.5',
410
+ '7532': '2.4',
411
+ '7542': '2.9',
412
+ '7552': '2.2',
413
+ '7642': '2.3',
414
+ '7662': '2.0',
415
+ '7702': '2.0',
416
+ '7742': '2.25',
417
+ '7H12': '2.6',
418
+ '7F32': '3.7',
419
+ '7F52': '3.5',
420
+ '7F72': '3.2',
421
+
422
+ // Epyc (Milan)
423
+
424
+ '7763': '2.45',
425
+ '7713': '2.0',
426
+ '7713P': '2.0',
427
+ '7663': '2.0',
428
+ '7643': '2.3',
429
+ '75F3': '2.95',
430
+ '7543': '2.8',
431
+ '7543P': '2.8',
432
+ '7513': '2.6',
433
+ '7453': '2.75',
434
+ '74F3': '3.2',
435
+ '7443': '2.85',
436
+ '7443P': '2.85',
437
+ '7413': '2.65',
438
+ '73F3': '3.5',
439
+ '7343': '3.2',
440
+ '7313': '3.0',
441
+ '7313P': '3.0',
442
+ '72F3': '3.7',
443
+
444
+ // ZEN3
445
+ '5600X': '3.7',
446
+ '5800X': '3.8',
447
+ '5900X': '3.7',
448
+ '5950X': '3.4'
449
+ };
450
+
451
+
452
+ const socketTypes = {
453
+ 1: 'Other',
454
+ 2: 'Unknown',
455
+ 3: 'Daughter Board',
456
+ 4: 'ZIF Socket',
457
+ 5: 'Replacement/Piggy Back',
458
+ 6: 'None',
459
+ 7: 'LIF Socket',
460
+ 8: 'Slot 1',
461
+ 9: 'Slot 2',
462
+ 10: '370 Pin Socket',
463
+ 11: 'Slot A',
464
+ 12: 'Slot M',
465
+ 13: '423',
466
+ 14: 'A (Socket 462)',
467
+ 15: '478',
468
+ 16: '754',
469
+ 17: '940',
470
+ 18: '939',
471
+ 19: 'mPGA604',
472
+ 20: 'LGA771',
473
+ 21: 'LGA775',
474
+ 22: 'S1',
475
+ 23: 'AM2',
476
+ 24: 'F (1207)',
477
+ 25: 'LGA1366',
478
+ 26: 'G34',
479
+ 27: 'AM3',
480
+ 28: 'C32',
481
+ 29: 'LGA1156',
482
+ 30: 'LGA1567',
483
+ 31: 'PGA988A',
484
+ 32: 'BGA1288',
485
+ 33: 'rPGA988B',
486
+ 34: 'BGA1023',
487
+ 35: 'BGA1224',
488
+ 36: 'LGA1155',
489
+ 37: 'LGA1356',
490
+ 38: 'LGA2011',
491
+ 39: 'FS1',
492
+ 40: 'FS2',
493
+ 41: 'FM1',
494
+ 42: 'FM2',
495
+ 43: 'LGA2011-3',
496
+ 44: 'LGA1356-3',
497
+ 45: 'LGA1150',
498
+ 46: 'BGA1168',
499
+ 47: 'BGA1234',
500
+ 48: 'BGA1364',
501
+ 49: 'AM4',
502
+ 50: 'LGA1151',
503
+ 51: 'BGA1356',
504
+ 52: 'BGA1440',
505
+ 53: 'BGA1515',
506
+ 54: 'LGA3647-1',
507
+ 55: 'SP3',
508
+ 56: 'SP3r2',
509
+ 57: 'LGA2066',
510
+ 58: 'BGA1392',
511
+ 59: 'BGA1510',
512
+ 60: 'BGA1528',
513
+ 61: 'LGA4189',
514
+ 62: 'LGA1200',
515
+ 63: 'LGA4677',
516
+ };
517
+
518
+ const socketTypesByName = {
519
+ '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',
520
+ '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',
521
+ '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'
522
+ };
523
+
524
+ function getSocketTypesByName(str) {
525
+ let result = '';
526
+ for (const key in socketTypesByName) {
527
+ const names = socketTypesByName[key].split(' ');
528
+ names.forEach(element => {
529
+ if (str.indexOf(element) >= 0) {
530
+ result = key;
531
+ }
532
+ });
533
+ }
534
+ return result;
535
+ }
536
+
537
+ function cpuManufacturer(str) {
538
+ let result = str;
539
+ str = str.toLowerCase();
540
+
541
+ if (str.indexOf('intel') >= 0) { result = 'Intel'; }
542
+ if (str.indexOf('amd') >= 0) { result = 'AMD'; }
543
+ if (str.indexOf('qemu') >= 0) { result = 'QEMU'; }
544
+ if (str.indexOf('hygon') >= 0) { result = 'Hygon'; }
545
+ if (str.indexOf('centaur') >= 0) { result = 'WinChip/Via'; }
546
+ if (str.indexOf('vmware') >= 0) { result = 'VMware'; }
547
+ if (str.indexOf('Xen') >= 0) { result = 'Xen Hypervisor'; }
548
+ if (str.indexOf('tcg') >= 0) { result = 'QEMU'; }
549
+ if (str.indexOf('apple') >= 0) { result = 'Apple'; }
550
+
551
+ return result;
552
+ }
553
+
554
+ function cpuBrandManufacturer(res) {
555
+ res.brand = res.brand.replace(/\(R\)+/g, '®').replace(/\s+/g, ' ').trim();
556
+ res.brand = res.brand.replace(/\(TM\)+/g, '™').replace(/\s+/g, ' ').trim();
557
+ res.brand = res.brand.replace(/\(C\)+/g, '©').replace(/\s+/g, ' ').trim();
558
+ res.brand = res.brand.replace(/CPU+/g, '').replace(/\s+/g, ' ').trim();
559
+ res.manufacturer = cpuManufacturer(res.brand);
560
+
561
+ let parts = res.brand.split(' ');
562
+ parts.shift();
563
+ res.brand = parts.join(' ');
564
+ return res;
565
+ }
566
+
567
+ function getAMDSpeed(brand) {
568
+ let result = '0';
569
+ for (let key in AMDBaseFrequencies) {
570
+ if ({}.hasOwnProperty.call(AMDBaseFrequencies, key)) {
571
+ let parts = key.split('|');
572
+ let found = 0;
573
+ parts.forEach(item => {
574
+ if (brand.indexOf(item) > -1) {
575
+ found++;
576
+ }
577
+ });
578
+ if (found === parts.length) {
579
+ result = AMDBaseFrequencies[key];
580
+ }
581
+ }
582
+ }
583
+ return parseFloat(result);
584
+ }
585
+
586
+ // --------------------------
587
+ // CPU - brand, speed
588
+
589
+ function getCpu() {
590
+
591
+ return new Promise((resolve) => {
592
+ process.nextTick(() => {
593
+ const UNKNOWN = 'unknown';
594
+ let result = {
595
+ manufacturer: UNKNOWN,
596
+ brand: UNKNOWN,
597
+ vendor: '',
598
+ family: '',
599
+ model: '',
600
+ stepping: '',
601
+ revision: '',
602
+ voltage: '',
603
+ speed: 0,
604
+ speedMin: 0,
605
+ speedMax: 0,
606
+ governor: '',
607
+ cores: util.cores(),
608
+ physicalCores: util.cores(),
609
+ performanceCores: util.cores(),
610
+ efficiencyCores: 0,
611
+ processors: 1,
612
+ socket: '',
613
+ flags: '',
614
+ virtualization: false,
615
+ cache: {}
616
+ };
617
+ cpuFlags().then(flags => {
618
+ result.flags = flags;
619
+ result.virtualization = flags.indexOf('vmx') > -1 || flags.indexOf('svm') > -1;
620
+ if (_darwin) {
621
+ exec('sysctl machdep.cpu hw.cpufrequency_max hw.cpufrequency_min hw.packages hw.physicalcpu_max hw.ncpu hw.tbfrequency hw.cpufamily hw.cpusubfamily', function (error, stdout) {
622
+ let lines = stdout.toString().split('\n');
623
+ const modelline = util.getValue(lines, 'machdep.cpu.brand_string');
624
+ const modellineParts = modelline.split('@');
625
+ result.brand = modellineParts[0].trim();
626
+ const speed = modellineParts[1] ? modellineParts[1].trim() : '0';
627
+ result.speed = parseFloat(speed.replace(/GHz+/g, ''));
628
+ let tbFrequency = util.getValue(lines, 'hw.tbfrequency') / 1000000000.0;
629
+ tbFrequency = tbFrequency < 0.1 ? tbFrequency * 100 : tbFrequency;
630
+ result.speed = result.speed === 0 ? tbFrequency : result.speed;
631
+
632
+ _cpu_speed = result.speed;
633
+ result = cpuBrandManufacturer(result);
634
+ result.speedMin = util.getValue(lines, 'hw.cpufrequency_min') ? (util.getValue(lines, 'hw.cpufrequency_min') / 1000000000.0) : result.speed;
635
+ result.speedMax = util.getValue(lines, 'hw.cpufrequency_max') ? (util.getValue(lines, 'hw.cpufrequency_max') / 1000000000.0) : result.speed;
636
+ result.vendor = util.getValue(lines, 'machdep.cpu.vendor') || 'Apple';
637
+ result.family = util.getValue(lines, 'machdep.cpu.family') || util.getValue(lines, 'hw.cpufamily');
638
+ result.model = util.getValue(lines, 'machdep.cpu.model');
639
+ result.stepping = util.getValue(lines, 'machdep.cpu.stepping') || util.getValue(lines, 'hw.cpusubfamily');
640
+ result.virtualization = true;
641
+ const countProcessors = util.getValue(lines, 'hw.packages');
642
+ const countCores = util.getValue(lines, 'hw.physicalcpu_max');
643
+ const countThreads = util.getValue(lines, 'hw.ncpu');
644
+ if (os.arch() === 'arm64') {
645
+ const clusters = execSync('ioreg -c IOPlatformDevice -d 3 -r | grep cluster-type').toString().split('\n');
646
+ const efficiencyCores = clusters.filter(line => line.indexOf('"E"') >= 0).length;
647
+ const performanceCores = clusters.filter(line => line.indexOf('"P"') >= 0).length;
648
+ result.socket = 'SOC';
649
+ result.efficiencyCores = efficiencyCores;
650
+ result.performanceCores = performanceCores;
651
+ }
652
+ if (countProcessors) {
653
+ result.processors = parseInt(countProcessors) || 1;
654
+ }
655
+ if (countCores && countThreads) {
656
+ result.cores = parseInt(countThreads) || util.cores();
657
+ result.physicalCores = parseInt(countCores) || util.cores();
658
+ }
659
+ cpuCache().then((res) => {
660
+ result.cache = res;
661
+ resolve(result);
662
+ });
663
+ });
664
+ }
665
+ if (_linux) {
666
+ let modelline = '';
667
+ let lines = [];
668
+ if (os.cpus()[0] && os.cpus()[0].model) { modelline = os.cpus()[0].model; }
669
+ 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) {
670
+ if (!error) {
671
+ lines = stdout.toString().split('\n');
672
+ }
673
+ modelline = util.getValue(lines, 'model name') || modelline;
674
+ const modellineParts = modelline.split('@');
675
+ result.brand = modellineParts[0].trim();
676
+ result.speed = modellineParts[1] ? parseFloat(modellineParts[1].trim()) : 0;
677
+ if (result.speed === 0 && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) {
678
+ result.speed = getAMDSpeed(result.brand);
679
+ }
680
+ if (result.speed === 0) {
681
+ const current = getCpuCurrentSpeedSync();
682
+ if (current.avg !== 0) { result.speed = current.avg; }
683
+ }
684
+ _cpu_speed = result.speed;
685
+ result.speedMin = Math.round(parseFloat(util.getValue(lines, 'cpu min mhz').replace(/,/g, '.')) / 10.0) / 100;
686
+ result.speedMax = Math.round(parseFloat(util.getValue(lines, 'cpu max mhz').replace(/,/g, '.')) / 10.0) / 100;
687
+
688
+ result = cpuBrandManufacturer(result);
689
+ result.vendor = cpuManufacturer(util.getValue(lines, 'vendor id'));
690
+
691
+ result.family = util.getValue(lines, 'cpu family');
692
+ result.model = util.getValue(lines, 'model:');
693
+ result.stepping = util.getValue(lines, 'stepping');
694
+ result.revision = util.getValue(lines, 'cpu revision');
695
+ result.cache.l1d = util.getValue(lines, 'l1d cache');
696
+ 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)); }
697
+ result.cache.l1i = util.getValue(lines, 'l1i cache');
698
+ 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)); }
699
+ result.cache.l2 = util.getValue(lines, 'l2 cache');
700
+ 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)); }
701
+ result.cache.l3 = util.getValue(lines, 'l3 cache');
702
+ 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)); }
703
+
704
+ const threadsPerCore = util.getValue(lines, 'thread(s) per core') || '1';
705
+ const processors = util.getValue(lines, 'socket(s)') || '1';
706
+ let threadsPerCoreInt = parseInt(threadsPerCore, 10); // threads per code (normally only for performance cores)
707
+ let processorsInt = parseInt(processors, 10) || 1; // number of sockets / processor units in machine (normally 1)
708
+ const coresPerSocket = parseInt(util.getValue(lines, 'core(s) per socket'), 10); // number of cores (e.g. 16 on i12900)
709
+ result.physicalCores = coresPerSocket ? coresPerSocket * processorsInt : result.cores / threadsPerCoreInt;
710
+ result.performanceCores = threadsPerCoreInt > 1 ? result.cores - result.physicalCores : result.cores;
711
+ result.efficiencyCores = threadsPerCoreInt > 1 ? result.cores - (threadsPerCoreInt * result.performanceCores) : 0;
712
+ result.processors = processorsInt;
713
+ result.governor = util.getValue(lines, 'governor') || '';
714
+
715
+ // Test Raspberry
716
+ if (result.vendor === 'ARM') {
717
+ const linesRpi = fs.readFileSync('/proc/cpuinfo').toString().split('\n');
718
+ const rPIRevision = util.decodePiCpuinfo(linesRpi);
719
+ if (rPIRevision.model.toLowerCase().indexOf('raspberry') >= 0) {
720
+ result.family = result.manufacturer;
721
+ result.manufacturer = rPIRevision.manufacturer;
722
+ result.brand = rPIRevision.processor;
723
+ result.revision = rPIRevision.revisionCode;
724
+ result.socket = 'SOC';
725
+ }
726
+ }
727
+
728
+ // socket type
729
+ let lines2 = [];
730
+ exec('export LC_ALL=C; dmidecode –t 4 2>/dev/null | grep "Upgrade: Socket"; unset LC_ALL', function (error2, stdout2) {
731
+ lines2 = stdout2.toString().split('\n');
732
+ if (lines2 && lines2.length) {
733
+ result.socket = util.getValue(lines2, 'Upgrade').replace('Socket', '').trim() || result.socket;
734
+ }
735
+ resolve(result);
736
+ });
737
+ });
738
+ }
739
+ if (_freebsd || _openbsd || _netbsd) {
740
+ let modelline = '';
741
+ let lines = [];
742
+ if (os.cpus()[0] && os.cpus()[0].model) { modelline = os.cpus()[0].model; }
743
+ exec('export LC_ALL=C; dmidecode -t 4; dmidecode -t 7 unset LC_ALL', function (error, stdout) {
744
+ let cache = [];
745
+ if (!error) {
746
+ const data = stdout.toString().split('# dmidecode');
747
+ const processor = data.length > 1 ? data[1] : '';
748
+ cache = data.length > 2 ? data[2].split('Cache Information') : [];
749
+
750
+ lines = processor.split('\n');
751
+ }
752
+ result.brand = modelline.split('@')[0].trim();
753
+ result.speed = modelline.split('@')[1] ? parseFloat(modelline.split('@')[1].trim()) : 0;
754
+ if (result.speed === 0 && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) {
755
+ result.speed = getAMDSpeed(result.brand);
756
+ }
757
+ if (result.speed === 0) {
758
+ const current = getCpuCurrentSpeedSync();
759
+ if (current.avg !== 0) { result.speed = current.avg; }
760
+ }
761
+ _cpu_speed = result.speed;
762
+ result.speedMin = result.speed;
763
+ result.speedMax = Math.round(parseFloat(util.getValue(lines, 'max speed').replace(/Mhz/g, '')) / 10.0) / 100;
764
+
765
+ result = cpuBrandManufacturer(result);
766
+ result.vendor = cpuManufacturer(util.getValue(lines, 'manufacturer'));
767
+ let sig = util.getValue(lines, 'signature');
768
+ sig = sig.split(',');
769
+ for (let i = 0; i < sig.length; i++) {
770
+ sig[i] = sig[i].trim();
771
+ }
772
+ result.family = util.getValue(sig, 'Family', ' ', true);
773
+ result.model = util.getValue(sig, 'Model', ' ', true);
774
+ result.stepping = util.getValue(sig, 'Stepping', ' ', true);
775
+ result.revision = '';
776
+ const voltage = parseFloat(util.getValue(lines, 'voltage'));
777
+ result.voltage = isNaN(voltage) ? '' : voltage.toFixed(2);
778
+ for (let i = 0; i < cache.length; i++) {
779
+ lines = cache[i].split('\n');
780
+ let cacheType = util.getValue(lines, 'Socket Designation').toLowerCase().replace(' ', '-').split('-');
781
+ cacheType = cacheType.length ? cacheType[0] : '';
782
+ const sizeParts = util.getValue(lines, 'Installed Size').split(' ');
783
+ let size = parseInt(sizeParts[0], 10);
784
+ const unit = sizeParts.length > 1 ? sizeParts[1] : 'kb';
785
+ size = size * (unit === 'kb' ? 1024 : (unit === 'mb' ? 1024 * 1024 : (unit === 'gb' ? 1024 * 1024 * 1024 : 1)));
786
+ if (cacheType) {
787
+ if (cacheType === 'l1') {
788
+ result.cache[cacheType + 'd'] = size / 2;
789
+ result.cache[cacheType + 'i'] = size / 2;
790
+ } else {
791
+ result.cache[cacheType] = size;
792
+ }
793
+ }
794
+ }
795
+ // socket type
796
+ result.socket = util.getValue(lines, 'Upgrade').replace('Socket', '').trim();
797
+ // # threads / # cores
798
+ const threadCount = util.getValue(lines, 'thread count').trim();
799
+ const coreCount = util.getValue(lines, 'core count').trim();
800
+ if (coreCount && threadCount) {
801
+ result.cores = parseInt(threadCount, 10);
802
+ result.physicalCores = parseInt(coreCount, 10);
803
+ }
804
+ resolve(result);
805
+ });
806
+ }
807
+ if (_sunos) {
808
+ resolve(result);
809
+ }
810
+ if (_windows) {
811
+ try {
812
+ const workload = [];
813
+ workload.push(util.powerShell('Get-CimInstance Win32_processor | select Name, Revision, L2CacheSize, L3CacheSize, Manufacturer, MaxClockSpeed, Description, UpgradeMethod, Caption, NumberOfLogicalProcessors, NumberOfCores | fl'));
814
+ workload.push(util.powerShell('Get-CimInstance Win32_CacheMemory | select CacheType,InstalledSize,Level | fl'));
815
+ workload.push(util.powerShell('(Get-CimInstance Win32_ComputerSystem).HypervisorPresent'));
816
+
817
+ Promise.all(
818
+ workload
819
+ ).then((data) => {
820
+ let lines = data[0].split('\r\n');
821
+ let name = util.getValue(lines, 'name', ':') || '';
822
+ if (name.indexOf('@') >= 0) {
823
+ result.brand = name.split('@')[0].trim();
824
+ result.speed = name.split('@')[1] ? parseFloat(name.split('@')[1].trim()) : 0;
825
+ _cpu_speed = result.speed;
826
+ } else {
827
+ result.brand = name.trim();
828
+ result.speed = 0;
829
+ }
830
+ result = cpuBrandManufacturer(result);
831
+ result.revision = util.getValue(lines, 'revision', ':');
832
+ result.cache.l1d = 0;
833
+ result.cache.l1i = 0;
834
+ result.cache.l2 = util.getValue(lines, 'l2cachesize', ':');
835
+ result.cache.l3 = util.getValue(lines, 'l3cachesize', ':');
836
+ if (result.cache.l2) { result.cache.l2 = parseInt(result.cache.l2, 10) * 1024; }
837
+ if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3, 10) * 1024; }
838
+ result.vendor = util.getValue(lines, 'manufacturer', ':');
839
+ result.speedMax = Math.round(parseFloat(util.getValue(lines, 'maxclockspeed', ':').replace(/,/g, '.')) / 10.0) / 100;
840
+ if (result.speed === 0 && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) {
841
+ result.speed = getAMDSpeed(result.brand);
842
+ }
843
+ if (result.speed === 0) {
844
+ result.speed = result.speedMax;
845
+ }
846
+ result.speedMin = result.speed;
847
+
848
+ let description = util.getValue(lines, 'description', ':').split(' ');
849
+ for (let i = 0; i < description.length; i++) {
850
+ if (description[i].toLowerCase().startsWith('family') && (i + 1) < description.length && description[i + 1]) {
851
+ result.family = description[i + 1];
852
+ }
853
+ if (description[i].toLowerCase().startsWith('model') && (i + 1) < description.length && description[i + 1]) {
854
+ result.model = description[i + 1];
855
+ }
856
+ if (description[i].toLowerCase().startsWith('stepping') && (i + 1) < description.length && description[i + 1]) {
857
+ result.stepping = description[i + 1];
858
+ }
859
+ }
860
+ // socket type
861
+ const socketId = util.getValue(lines, 'UpgradeMethod', ':');
862
+ if (socketTypes[socketId]) {
863
+ result.socket = socketTypes[socketId];
864
+ }
865
+ const socketByName = getSocketTypesByName(name);
866
+ if (socketByName) {
867
+ result.socket = socketByName;
868
+ }
869
+ // # threads / # cores
870
+ const countProcessors = util.countLines(lines, 'Caption');
871
+ const countThreads = util.getValue(lines, 'NumberOfLogicalProcessors', ':');
872
+ const countCores = util.getValue(lines, 'NumberOfCores', ':');
873
+ if (countProcessors) {
874
+ result.processors = parseInt(countProcessors) || 1;
875
+ }
876
+ if (countCores && countThreads) {
877
+ result.cores = parseInt(countThreads) || util.cores();
878
+ result.physicalCores = parseInt(countCores) || util.cores();
879
+ }
880
+ if (countProcessors > 1) {
881
+ result.cores = result.cores * countProcessors;
882
+ result.physicalCores = result.physicalCores * countProcessors;
883
+ }
884
+ const parts = data[1].split(/\n\s*\n/);
885
+ parts.forEach(function (part) {
886
+ lines = part.split('\r\n');
887
+ const cacheType = util.getValue(lines, 'CacheType');
888
+ const level = util.getValue(lines, 'Level');
889
+ const installedSize = util.getValue(lines, 'InstalledSize');
890
+ // L1 Instructions
891
+ if (level === '3' && cacheType === '3') {
892
+ result.cache.l1i = parseInt(installedSize, 10);
893
+ }
894
+ // L1 Data
895
+ if (level === '3' && cacheType === '4') {
896
+ result.cache.l1d = parseInt(installedSize, 10);
897
+ }
898
+ // L1 all
899
+ if (level === '3' && cacheType === '5' && !result.cache.l1i && !result.cache.l1d) {
900
+ result.cache.l1i = parseInt(installedSize, 10) / 2;
901
+ result.cache.l1d = parseInt(installedSize, 10) / 2;
902
+ }
903
+ });
904
+ const hyperv = data[2] ? data[2].toString().toLowerCase() : '';
905
+ result.virtualization = hyperv.indexOf('true') !== -1;
906
+
907
+ resolve(result);
908
+ });
909
+ } catch (e) {
910
+ resolve(result);
911
+ }
912
+ }
913
+ });
914
+ });
915
+ });
916
+ }
917
+
918
+ // --------------------------
919
+ // CPU - Processor Data
920
+
921
+ function cpu(callback) {
922
+
923
+ return new Promise((resolve) => {
924
+ process.nextTick(() => {
925
+ getCpu().then(result => {
926
+ if (callback) { callback(result); }
927
+ resolve(result);
928
+ });
929
+ });
930
+ });
931
+ }
932
+
933
+ exports.cpu = cpu;
934
+
935
+ // --------------------------
936
+ // CPU - current speed - in GHz
937
+
938
+ function getCpuCurrentSpeedSync() {
939
+
940
+ let cpus = os.cpus();
941
+ let minFreq = 999999999;
942
+ let maxFreq = 0;
943
+ let avgFreq = 0;
944
+ let cores = [];
945
+
946
+ if (cpus && cpus.length) {
947
+ for (let i in cpus) {
948
+ if ({}.hasOwnProperty.call(cpus, i)) {
949
+ let freq = cpus[i].speed > 100 ? (cpus[i].speed + 1) / 1000 : cpus[i].speed / 10;
950
+ avgFreq = avgFreq + freq;
951
+ if (freq > maxFreq) { maxFreq = freq; }
952
+ if (freq < minFreq) { minFreq = freq; }
953
+ cores.push(parseFloat(freq.toFixed(2)));
954
+ }
955
+ }
956
+ avgFreq = avgFreq / cpus.length;
957
+ return {
958
+ min: parseFloat(minFreq.toFixed(2)),
959
+ max: parseFloat(maxFreq.toFixed(2)),
960
+ avg: parseFloat((avgFreq).toFixed(2)),
961
+ cores: cores
962
+ };
963
+ } else {
964
+ return {
965
+ min: 0,
966
+ max: 0,
967
+ avg: 0,
968
+ cores: cores
969
+ };
970
+ }
971
+ }
972
+
973
+ function cpuCurrentSpeed(callback) {
974
+
975
+ return new Promise((resolve) => {
976
+ process.nextTick(() => {
977
+ let result = getCpuCurrentSpeedSync();
978
+ if (result.avg === 0 && _cpu_speed !== 0) {
979
+ const currCpuSpeed = parseFloat(_cpu_speed);
980
+ result = {
981
+ min: currCpuSpeed,
982
+ max: currCpuSpeed,
983
+ avg: currCpuSpeed,
984
+ cores: []
985
+ };
986
+ }
987
+ if (callback) { callback(result); }
988
+ resolve(result);
989
+ });
990
+ });
991
+ }
992
+
993
+ exports.cpuCurrentSpeed = cpuCurrentSpeed;
994
+
995
+ // --------------------------
996
+ // CPU - temperature
997
+ // if sensors are installed
998
+
999
+ function cpuTemperature(callback) {
1000
+
1001
+ return new Promise((resolve) => {
1002
+ process.nextTick(() => {
1003
+ let result = {
1004
+ main: null,
1005
+ cores: [],
1006
+ max: null,
1007
+ socket: [],
1008
+ chipset: null
1009
+ };
1010
+ if (_linux) {
1011
+ // CPU Chipset, Socket
1012
+ try {
1013
+ const cmd = 'cat /sys/class/thermal/thermal_zone*/type 2>/dev/null; echo "-----"; cat /sys/class/thermal/thermal_zone*/temp 2>/dev/null;';
1014
+ const parts = execSync(cmd).toString().split('-----\n');
1015
+ if (parts.length === 2) {
1016
+ const lines = parts[0].split('\n');
1017
+ const lines2 = parts[1].split('\n');
1018
+ for (let i = 0; i < lines.length; i++) {
1019
+ const line = lines[i].trim();
1020
+ if (line.startsWith('acpi') && lines2[i]) {
1021
+ result.socket.push(Math.round(parseInt(lines2[i], 10) / 100) / 10);
1022
+ }
1023
+ if (line.startsWith('pch') && lines2[i]) {
1024
+ result.chipset = Math.round(parseInt(lines2[i], 10) / 100) / 10;
1025
+ }
1026
+ }
1027
+ }
1028
+ } catch (e) {
1029
+ util.noop();
1030
+ }
1031
+
1032
+ 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;';
1033
+ try {
1034
+ exec(cmd, function (error, stdout) {
1035
+ stdout = stdout.toString();
1036
+ const tdiePos = stdout.toLowerCase().indexOf('tdie');
1037
+ if (tdiePos !== -1) {
1038
+ stdout = stdout.substring(tdiePos);
1039
+ }
1040
+ let lines = stdout.split('\n');
1041
+ lines.forEach(line => {
1042
+ const parts = line.split('___');
1043
+ const label = parts[0];
1044
+ const value = parts.length > 1 && parts[1] ? parts[1] : '0';
1045
+ if (value && (label === undefined || (label && label.toLowerCase().startsWith('core')))) {
1046
+ result.cores.push(Math.round(parseInt(value, 10) / 100) / 10);
1047
+ } else if (value && label && result.main === null && (label.toLowerCase().indexOf('package') >= 0 || label.toLowerCase().indexOf('physical') >= 0)) {
1048
+ result.main = Math.round(parseInt(value, 10) / 100) / 10;
1049
+ }
1050
+ });
1051
+
1052
+ if (result.cores.length > 0) {
1053
+ if (result.main === null) {
1054
+ result.main = Math.round(result.cores.reduce((a, b) => a + b, 0) / result.cores.length);
1055
+ }
1056
+ let maxtmp = Math.max.apply(Math, result.cores);
1057
+ result.max = (maxtmp > result.main) ? maxtmp : result.main;
1058
+ }
1059
+ if (result.main !== null) {
1060
+ if (result.max === null) {
1061
+ result.max = result.main;
1062
+ }
1063
+ if (callback) { callback(result); }
1064
+ resolve(result);
1065
+ return;
1066
+ }
1067
+ exec('sensors', function (error, stdout) {
1068
+ if (!error) {
1069
+ let lines = stdout.toString().split('\n');
1070
+ let tdieTemp = null;
1071
+ let newSectionStarts = true;
1072
+ let section = '';
1073
+ lines.forEach(function (line) {
1074
+ // determine section
1075
+ if (line.trim() === '') {
1076
+ newSectionStarts = true;
1077
+ } else if (newSectionStarts) {
1078
+ if (line.trim().toLowerCase().startsWith('acpi')) { section = 'acpi'; }
1079
+ if (line.trim().toLowerCase().startsWith('pch')) { section = 'pch'; }
1080
+ if (line.trim().toLowerCase().startsWith('core')) { section = 'core'; }
1081
+ newSectionStarts = false;
1082
+ }
1083
+ let regex = /[+-]([^°]*)/g;
1084
+ let temps = line.match(regex);
1085
+ let firstPart = line.split(':')[0].toUpperCase();
1086
+ if (section === 'acpi') {
1087
+ // socket temp
1088
+ if (firstPart.indexOf('TEMP') !== -1) {
1089
+ result.socket.push(parseFloat(temps));
1090
+ }
1091
+ } else if (section === 'pch') {
1092
+ // chipset temp
1093
+ if (firstPart.indexOf('TEMP') !== -1 && !result.chipset) {
1094
+ result.chipset = parseFloat(temps);
1095
+ }
1096
+ }
1097
+ // cpu temp
1098
+ if (firstPart.indexOf('PHYSICAL') !== -1 || firstPart.indexOf('PACKAGE') !== -1) {
1099
+ result.main = parseFloat(temps);
1100
+ }
1101
+ if (firstPart.indexOf('CORE ') !== -1) {
1102
+ result.cores.push(parseFloat(temps));
1103
+ }
1104
+ if (firstPart.indexOf('TDIE') !== -1 && tdieTemp === null) {
1105
+ tdieTemp = parseFloat(temps);
1106
+ }
1107
+ });
1108
+ if (result.cores.length > 0) {
1109
+ result.main = Math.round(result.cores.reduce((a, b) => a + b, 0) / result.cores.length);
1110
+ let maxtmp = Math.max.apply(Math, result.cores);
1111
+ result.max = (maxtmp > result.main) ? maxtmp : result.main;
1112
+ } else {
1113
+ if (result.main === null && tdieTemp !== null) {
1114
+ result.main = tdieTemp;
1115
+ result.max = tdieTemp;
1116
+ }
1117
+ }
1118
+ if (result.main !== null || result.max !== null) {
1119
+ if (callback) { callback(result); }
1120
+ resolve(result);
1121
+ return;
1122
+ }
1123
+ }
1124
+ fs.stat('/sys/class/thermal/thermal_zone0/temp', function (err) {
1125
+ if (err === null) {
1126
+ fs.readFile('/sys/class/thermal/thermal_zone0/temp', function (error, stdout) {
1127
+ if (!error) {
1128
+ let lines = stdout.toString().split('\n');
1129
+ if (lines.length > 0) {
1130
+ result.main = parseFloat(lines[0]) / 1000.0;
1131
+ result.max = result.main;
1132
+ }
1133
+ }
1134
+ if (callback) { callback(result); }
1135
+ resolve(result);
1136
+ });
1137
+ } else {
1138
+ exec('/opt/vc/bin/vcgencmd measure_temp', function (error, stdout) {
1139
+ if (!error) {
1140
+ let lines = stdout.toString().split('\n');
1141
+ if (lines.length > 0 && lines[0].indexOf('=')) {
1142
+ result.main = parseFloat(lines[0].split('=')[1]);
1143
+ result.max = result.main;
1144
+ }
1145
+ }
1146
+ if (callback) { callback(result); }
1147
+ resolve(result);
1148
+ });
1149
+ }
1150
+ });
1151
+ });
1152
+ });
1153
+ } catch (er) {
1154
+ if (callback) { callback(result); }
1155
+ resolve(result);
1156
+ }
1157
+ }
1158
+ if (_freebsd || _openbsd || _netbsd) {
1159
+ exec('sysctl dev.cpu | grep temp', function (error, stdout) {
1160
+ if (!error) {
1161
+ let lines = stdout.toString().split('\n');
1162
+ let sum = 0;
1163
+ lines.forEach(function (line) {
1164
+ const parts = line.split(':');
1165
+ if (parts.length > 1) {
1166
+ const temp = parseFloat(parts[1].replace(',', '.'));
1167
+ if (temp > result.max) { result.max = temp; }
1168
+ sum = sum + temp;
1169
+ result.cores.push(temp);
1170
+ }
1171
+ });
1172
+ if (result.cores.length) {
1173
+ result.main = Math.round(sum / result.cores.length * 100) / 100;
1174
+ }
1175
+ }
1176
+ if (callback) { callback(result); }
1177
+ resolve(result);
1178
+ });
1179
+ }
1180
+ if (_darwin) {
1181
+ let osxTemp = null;
1182
+ try {
1183
+ osxTemp = require('osx-temperature-sensor');
1184
+ } catch (er) {
1185
+ osxTemp = null;
1186
+ }
1187
+ if (osxTemp) {
1188
+ result = osxTemp.cpuTemperature();
1189
+ // round to 2 digits
1190
+ if (result.main) {
1191
+ result.main = Math.round(result.main * 100) / 100;
1192
+ }
1193
+ if (result.max) {
1194
+ result.max = Math.round(result.max * 100) / 100;
1195
+ }
1196
+ if (result.cores && result.cores.length) {
1197
+ for (let i = 0; i < result.cores.length; i++) {
1198
+ result.cores[i] = Math.round(result.cores[i] * 100) / 100;
1199
+ }
1200
+ }
1201
+ }
1202
+
1203
+ if (callback) { callback(result); }
1204
+ resolve(result);
1205
+ }
1206
+ if (_sunos) {
1207
+ if (callback) { callback(result); }
1208
+ resolve(result);
1209
+ }
1210
+ if (_windows) {
1211
+ try {
1212
+ util.powerShell('Get-CimInstance MSAcpi_ThermalZoneTemperature -Namespace "root/wmi" | Select CurrentTemperature').then((stdout, error) => {
1213
+ if (!error) {
1214
+ let sum = 0;
1215
+ let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
1216
+ lines.forEach(function (line) {
1217
+ let value = (parseInt(line, 10) - 2732) / 10;
1218
+ if (!isNaN(value)) {
1219
+ sum = sum + value;
1220
+ if (value > result.max) { result.max = value; }
1221
+ result.cores.push(value);
1222
+ }
1223
+ });
1224
+ if (result.cores.length) {
1225
+ result.main = sum / result.cores.length;
1226
+ }
1227
+ }
1228
+ if (callback) { callback(result); }
1229
+ resolve(result);
1230
+ });
1231
+ } catch (e) {
1232
+ if (callback) { callback(result); }
1233
+ resolve(result);
1234
+ }
1235
+ }
1236
+ });
1237
+ });
1238
+ }
1239
+
1240
+ exports.cpuTemperature = cpuTemperature;
1241
+
1242
+ // --------------------------
1243
+ // CPU Flags
1244
+
1245
+ function cpuFlags(callback) {
1246
+
1247
+ return new Promise((resolve) => {
1248
+ process.nextTick(() => {
1249
+ let result = '';
1250
+ if (_windows) {
1251
+ try {
1252
+ exec('reg query "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0" /v FeatureSet', util.execOptsWin, function (error, stdout) {
1253
+ if (!error) {
1254
+ let flag_hex = stdout.split('0x').pop().trim();
1255
+ let flag_bin_unpadded = parseInt(flag_hex, 16).toString(2);
1256
+ let flag_bin = '0'.repeat(32 - flag_bin_unpadded.length) + flag_bin_unpadded;
1257
+ // empty flags are the reserved fields in the CPUID feature bit list
1258
+ // as found on wikipedia:
1259
+ // https://en.wikipedia.org/wiki/CPUID
1260
+ let all_flags = [
1261
+ 'fpu', 'vme', 'de', 'pse', 'tsc', 'msr', 'pae', 'mce', 'cx8', 'apic',
1262
+ '', 'sep', 'mtrr', 'pge', 'mca', 'cmov', 'pat', 'pse-36', 'psn', 'clfsh',
1263
+ '', 'ds', 'acpi', 'mmx', 'fxsr', 'sse', 'sse2', 'ss', 'htt', 'tm', 'ia64', 'pbe'
1264
+ ];
1265
+ for (let f = 0; f < all_flags.length; f++) {
1266
+ if (flag_bin[f] === '1' && all_flags[f] !== '') {
1267
+ result += ' ' + all_flags[f];
1268
+ }
1269
+ }
1270
+ result = result.trim().toLowerCase();
1271
+ }
1272
+ if (callback) { callback(result); }
1273
+ resolve(result);
1274
+ });
1275
+ } catch (e) {
1276
+ if (callback) { callback(result); }
1277
+ resolve(result);
1278
+ }
1279
+ }
1280
+ if (_linux) {
1281
+ try {
1282
+
1283
+ exec('export LC_ALL=C; lscpu; unset LC_ALL', function (error, stdout) {
1284
+ if (!error) {
1285
+ let lines = stdout.toString().split('\n');
1286
+ lines.forEach(function (line) {
1287
+ if (line.split(':')[0].toUpperCase().indexOf('FLAGS') !== -1) {
1288
+ result = line.split(':')[1].trim().toLowerCase();
1289
+ }
1290
+ });
1291
+ }
1292
+ if (!result) {
1293
+ fs.readFile('/proc/cpuinfo', function (error, stdout) {
1294
+ if (!error) {
1295
+ let lines = stdout.toString().split('\n');
1296
+ result = util.getValue(lines, 'features', ':', true).toLowerCase();
1297
+ }
1298
+ if (callback) { callback(result); }
1299
+ resolve(result);
1300
+ });
1301
+ } else {
1302
+ if (callback) { callback(result); }
1303
+ resolve(result);
1304
+ }
1305
+ });
1306
+ } catch (e) {
1307
+ if (callback) { callback(result); }
1308
+ resolve(result);
1309
+ }
1310
+ }
1311
+ if (_freebsd || _openbsd || _netbsd) {
1312
+ exec('export LC_ALL=C; dmidecode -t 4 2>/dev/null; unset LC_ALL', function (error, stdout) {
1313
+ let flags = [];
1314
+ if (!error) {
1315
+ let parts = stdout.toString().split('\tFlags:');
1316
+ const lines = parts.length > 1 ? parts[1].split('\tVersion:')[0].split('\n') : [];
1317
+ lines.forEach(function (line) {
1318
+ let flag = (line.indexOf('(') ? line.split('(')[0].toLowerCase() : '').trim().replace(/\t/g, '');
1319
+ if (flag) {
1320
+ flags.push(flag);
1321
+ }
1322
+ });
1323
+ }
1324
+ result = flags.join(' ').trim().toLowerCase();
1325
+ if (callback) { callback(result); }
1326
+ resolve(result);
1327
+ });
1328
+ }
1329
+ if (_darwin) {
1330
+ exec('sysctl machdep.cpu.features', function (error, stdout) {
1331
+ if (!error) {
1332
+ let lines = stdout.toString().split('\n');
1333
+ if (lines.length > 0 && lines[0].indexOf('machdep.cpu.features:') !== -1) {
1334
+ result = lines[0].split(':')[1].trim().toLowerCase();
1335
+ }
1336
+ }
1337
+ if (callback) { callback(result); }
1338
+ resolve(result);
1339
+ });
1340
+ }
1341
+ if (_sunos) {
1342
+ if (callback) { callback(result); }
1343
+ resolve(result);
1344
+ }
1345
+ });
1346
+ });
1347
+ }
1348
+
1349
+ exports.cpuFlags = cpuFlags;
1350
+
1351
+ // --------------------------
1352
+ // CPU Cache
1353
+
1354
+ function cpuCache(callback) {
1355
+
1356
+ return new Promise((resolve) => {
1357
+ process.nextTick(() => {
1358
+
1359
+ let result = {
1360
+ l1d: null,
1361
+ l1i: null,
1362
+ l2: null,
1363
+ l3: null,
1364
+ };
1365
+ if (_linux) {
1366
+ try {
1367
+ exec('export LC_ALL=C; lscpu; unset LC_ALL', function (error, stdout) {
1368
+ if (!error) {
1369
+ let lines = stdout.toString().split('\n');
1370
+ lines.forEach(function (line) {
1371
+ let parts = line.split(':');
1372
+ if (parts[0].toUpperCase().indexOf('L1D CACHE') !== -1) {
1373
+ result.l1d = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : (parts[1].indexOf('K') !== -1 ? 1024 : 1));
1374
+ }
1375
+ if (parts[0].toUpperCase().indexOf('L1I CACHE') !== -1) {
1376
+ result.l1i = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : (parts[1].indexOf('K') !== -1 ? 1024 : 1));
1377
+ }
1378
+ if (parts[0].toUpperCase().indexOf('L2 CACHE') !== -1) {
1379
+ result.l2 = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : (parts[1].indexOf('K') !== -1 ? 1024 : 1));
1380
+ }
1381
+ if (parts[0].toUpperCase().indexOf('L3 CACHE') !== -1) {
1382
+ result.l3 = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : (parts[1].indexOf('K') !== -1 ? 1024 : 1));
1383
+ }
1384
+ });
1385
+ }
1386
+ if (callback) { callback(result); }
1387
+ resolve(result);
1388
+ });
1389
+ } catch (e) {
1390
+ if (callback) { callback(result); }
1391
+ resolve(result);
1392
+ }
1393
+ }
1394
+ if (_freebsd || _openbsd || _netbsd) {
1395
+ exec('export LC_ALL=C; dmidecode -t 7 2>/dev/null; unset LC_ALL', function (error, stdout) {
1396
+ let cache = [];
1397
+ if (!error) {
1398
+ const data = stdout.toString();
1399
+ cache = data.split('Cache Information');
1400
+ cache.shift();
1401
+ }
1402
+ for (let i = 0; i < cache.length; i++) {
1403
+ const lines = cache[i].split('\n');
1404
+ let cacheType = util.getValue(lines, 'Socket Designation').toLowerCase().replace(' ', '-').split('-');
1405
+ cacheType = cacheType.length ? cacheType[0] : '';
1406
+ const sizeParts = util.getValue(lines, 'Installed Size').split(' ');
1407
+ let size = parseInt(sizeParts[0], 10);
1408
+ const unit = sizeParts.length > 1 ? sizeParts[1] : 'kb';
1409
+ size = size * (unit === 'kb' ? 1024 : (unit === 'mb' ? 1024 * 1024 : (unit === 'gb' ? 1024 * 1024 * 1024 : 1)));
1410
+ if (cacheType) {
1411
+ if (cacheType === 'l1') {
1412
+ result.cache[cacheType + 'd'] = size / 2;
1413
+ result.cache[cacheType + 'i'] = size / 2;
1414
+ } else {
1415
+ result.cache[cacheType] = size;
1416
+ }
1417
+ }
1418
+ }
1419
+ if (callback) { callback(result); }
1420
+ resolve(result);
1421
+ });
1422
+ }
1423
+ if (_darwin) {
1424
+ exec('sysctl hw.l1icachesize hw.l1dcachesize hw.l2cachesize hw.l3cachesize', function (error, stdout) {
1425
+ if (!error) {
1426
+ let lines = stdout.toString().split('\n');
1427
+ lines.forEach(function (line) {
1428
+ let parts = line.split(':');
1429
+ if (parts[0].toLowerCase().indexOf('hw.l1icachesize') !== -1) {
1430
+ result.l1d = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
1431
+ }
1432
+ if (parts[0].toLowerCase().indexOf('hw.l1dcachesize') !== -1) {
1433
+ result.l1i = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
1434
+ }
1435
+ if (parts[0].toLowerCase().indexOf('hw.l2cachesize') !== -1) {
1436
+ result.l2 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
1437
+ }
1438
+ if (parts[0].toLowerCase().indexOf('hw.l3cachesize') !== -1) {
1439
+ result.l3 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
1440
+ }
1441
+ });
1442
+ }
1443
+ if (callback) { callback(result); }
1444
+ resolve(result);
1445
+ });
1446
+ }
1447
+ if (_sunos) {
1448
+ if (callback) { callback(result); }
1449
+ resolve(result);
1450
+ }
1451
+ if (_windows) {
1452
+ try {
1453
+ util.powerShell('Get-CimInstance Win32_processor | select L2CacheSize, L3CacheSize | fl').then((stdout, error) => {
1454
+ if (!error) {
1455
+ let lines = stdout.split('\r\n');
1456
+ result.l1d = 0;
1457
+ result.l1i = 0;
1458
+ result.l2 = util.getValue(lines, 'l2cachesize', ':');
1459
+ result.l3 = util.getValue(lines, 'l3cachesize', ':');
1460
+ if (result.l2) { result.l2 = parseInt(result.l2, 10) * 1024; }
1461
+ if (result.l3) { result.l3 = parseInt(result.l3, 10) * 1024; }
1462
+ }
1463
+ util.powerShell('Get-CimInstance Win32_CacheMemory | select CacheType,InstalledSize,Level | fl').then((stdout, error) => {
1464
+ if (!error) {
1465
+ const parts = stdout.split(/\n\s*\n/);
1466
+ parts.forEach(function (part) {
1467
+ const lines = part.split('\r\n');
1468
+ const cacheType = util.getValue(lines, 'CacheType');
1469
+ const level = util.getValue(lines, 'Level');
1470
+ const installedSize = util.getValue(lines, 'InstalledSize');
1471
+ // L1 Instructions
1472
+ if (level === '3' && cacheType === '3') {
1473
+ result.l1i = parseInt(installedSize, 10);
1474
+ }
1475
+ // L1 Data
1476
+ if (level === '3' && cacheType === '4') {
1477
+ result.l1d = parseInt(installedSize, 10);
1478
+ }
1479
+ // L1 all
1480
+ if (level === '3' && cacheType === '5' && !result.l1i && !result.l1d) {
1481
+ result.l1i = parseInt(installedSize, 10) / 2;
1482
+ result.l1d = parseInt(installedSize, 10) / 2;
1483
+ }
1484
+ });
1485
+ }
1486
+ if (callback) { callback(result); }
1487
+ resolve(result);
1488
+ });
1489
+ });
1490
+ } catch (e) {
1491
+ if (callback) { callback(result); }
1492
+ resolve(result);
1493
+ }
1494
+ }
1495
+ });
1496
+ });
1497
+ }
1498
+
1499
+ exports.cpuCache = cpuCache;
1500
+
1501
+ // --------------------------
1502
+ // CPU - current load - in %
1503
+
1504
+ function getLoad() {
1505
+
1506
+ return new Promise((resolve) => {
1507
+ process.nextTick(() => {
1508
+ let loads = os.loadavg().map(function (x) { return x / util.cores(); });
1509
+ let avgLoad = parseFloat((Math.max.apply(Math, loads)).toFixed(2));
1510
+ let result = {};
1511
+
1512
+ let now = Date.now() - _current_cpu.ms;
1513
+ if (now >= 200) {
1514
+ _current_cpu.ms = Date.now();
1515
+ const cpus = os.cpus();
1516
+ let totalUser = 0;
1517
+ let totalSystem = 0;
1518
+ let totalNice = 0;
1519
+ let totalIrq = 0;
1520
+ let totalIdle = 0;
1521
+ let cores = [];
1522
+ _corecount = (cpus && cpus.length) ? cpus.length : 0;
1523
+
1524
+ for (let i = 0; i < _corecount; i++) {
1525
+ const cpu = cpus[i].times;
1526
+ totalUser += cpu.user;
1527
+ totalSystem += cpu.sys;
1528
+ totalNice += cpu.nice;
1529
+ totalIdle += cpu.idle;
1530
+ totalIrq += cpu.irq;
1531
+ let tmpTick = (_cpus && _cpus[i] && _cpus[i].totalTick ? _cpus[i].totalTick : 0);
1532
+ let tmpLoad = (_cpus && _cpus[i] && _cpus[i].totalLoad ? _cpus[i].totalLoad : 0);
1533
+ let tmpUser = (_cpus && _cpus[i] && _cpus[i].user ? _cpus[i].user : 0);
1534
+ let tmpSystem = (_cpus && _cpus[i] && _cpus[i].sys ? _cpus[i].sys : 0);
1535
+ let tmpNice = (_cpus && _cpus[i] && _cpus[i].nice ? _cpus[i].nice : 0);
1536
+ let tmpIdle = (_cpus && _cpus[i] && _cpus[i].idle ? _cpus[i].idle : 0);
1537
+ let tmpIrq = (_cpus && _cpus[i] && _cpus[i].irq ? _cpus[i].irq : 0);
1538
+ _cpus[i] = cpu;
1539
+ _cpus[i].totalTick = _cpus[i].user + _cpus[i].sys + _cpus[i].nice + _cpus[i].irq + _cpus[i].idle;
1540
+ _cpus[i].totalLoad = _cpus[i].user + _cpus[i].sys + _cpus[i].nice + _cpus[i].irq;
1541
+ _cpus[i].currentTick = _cpus[i].totalTick - tmpTick;
1542
+ _cpus[i].load = (_cpus[i].totalLoad - tmpLoad);
1543
+ _cpus[i].loadUser = (_cpus[i].user - tmpUser);
1544
+ _cpus[i].loadSystem = (_cpus[i].sys - tmpSystem);
1545
+ _cpus[i].loadNice = (_cpus[i].nice - tmpNice);
1546
+ _cpus[i].loadIdle = (_cpus[i].idle - tmpIdle);
1547
+ _cpus[i].loadIrq = (_cpus[i].irq - tmpIrq);
1548
+ cores[i] = {};
1549
+ cores[i].load = _cpus[i].load / _cpus[i].currentTick * 100;
1550
+ cores[i].loadUser = _cpus[i].loadUser / _cpus[i].currentTick * 100;
1551
+ cores[i].loadSystem = _cpus[i].loadSystem / _cpus[i].currentTick * 100;
1552
+ cores[i].loadNice = _cpus[i].loadNice / _cpus[i].currentTick * 100;
1553
+ cores[i].loadIdle = _cpus[i].loadIdle / _cpus[i].currentTick * 100;
1554
+ cores[i].loadIrq = _cpus[i].loadIrq / _cpus[i].currentTick * 100;
1555
+ cores[i].rawLoad = _cpus[i].load;
1556
+ cores[i].rawLoadUser = _cpus[i].loadUser;
1557
+ cores[i].rawLoadSystem = _cpus[i].loadSystem;
1558
+ cores[i].rawLoadNice = _cpus[i].loadNice;
1559
+ cores[i].rawLoadIdle = _cpus[i].loadIdle;
1560
+ cores[i].rawLoadIrq = _cpus[i].loadIrq;
1561
+ }
1562
+ let totalTick = totalUser + totalSystem + totalNice + totalIrq + totalIdle;
1563
+ let totalLoad = totalUser + totalSystem + totalNice + totalIrq;
1564
+ let currentTick = totalTick - _current_cpu.tick;
1565
+ result = {
1566
+ avgLoad: avgLoad,
1567
+ currentLoad: (totalLoad - _current_cpu.load) / currentTick * 100,
1568
+ currentLoadUser: (totalUser - _current_cpu.user) / currentTick * 100,
1569
+ currentLoadSystem: (totalSystem - _current_cpu.system) / currentTick * 100,
1570
+ currentLoadNice: (totalNice - _current_cpu.nice) / currentTick * 100,
1571
+ currentLoadIdle: (totalIdle - _current_cpu.idle) / currentTick * 100,
1572
+ currentLoadIrq: (totalIrq - _current_cpu.irq) / currentTick * 100,
1573
+ rawCurrentLoad: (totalLoad - _current_cpu.load),
1574
+ rawCurrentLoadUser: (totalUser - _current_cpu.user),
1575
+ rawCurrentLoadSystem: (totalSystem - _current_cpu.system),
1576
+ rawCurrentLoadNice: (totalNice - _current_cpu.nice),
1577
+ rawCurrentLoadIdle: (totalIdle - _current_cpu.idle),
1578
+ rawCurrentLoadIrq: (totalIrq - _current_cpu.irq),
1579
+ cpus: cores
1580
+ };
1581
+ _current_cpu = {
1582
+ user: totalUser,
1583
+ nice: totalNice,
1584
+ system: totalSystem,
1585
+ idle: totalIdle,
1586
+ irq: totalIrq,
1587
+ tick: totalTick,
1588
+ load: totalLoad,
1589
+ ms: _current_cpu.ms,
1590
+ currentLoad: result.currentLoad,
1591
+ currentLoadUser: result.currentLoadUser,
1592
+ currentLoadSystem: result.currentLoadSystem,
1593
+ currentLoadNice: result.currentLoadNice,
1594
+ currentLoadIdle: result.currentLoadIdle,
1595
+ currentLoadIrq: result.currentLoadIrq,
1596
+ rawCurrentLoad: result.rawCurrentLoad,
1597
+ rawCurrentLoadUser: result.rawCurrentLoadUser,
1598
+ rawCurrentLoadSystem: result.rawCurrentLoadSystem,
1599
+ rawCurrentLoadNice: result.rawCurrentLoadNice,
1600
+ rawCurrentLoadIdle: result.rawCurrentLoadIdle,
1601
+ rawCurrentLoadIrq: result.rawCurrentLoadIrq,
1602
+ };
1603
+ } else {
1604
+ let cores = [];
1605
+ for (let i = 0; i < _corecount; i++) {
1606
+ cores[i] = {};
1607
+ cores[i].load = _cpus[i].load / _cpus[i].currentTick * 100;
1608
+ cores[i].loadUser = _cpus[i].loadUser / _cpus[i].currentTick * 100;
1609
+ cores[i].loadSystem = _cpus[i].loadSystem / _cpus[i].currentTick * 100;
1610
+ cores[i].loadNice = _cpus[i].loadNice / _cpus[i].currentTick * 100;
1611
+ cores[i].loadIdle = _cpus[i].loadIdle / _cpus[i].currentTick * 100;
1612
+ cores[i].loadIrq = _cpus[i].loadIrq / _cpus[i].currentTick * 100;
1613
+ cores[i].rawLoad = _cpus[i].load;
1614
+ cores[i].rawLoadUser = _cpus[i].loadUser;
1615
+ cores[i].rawLoadSystem = _cpus[i].loadSystem;
1616
+ cores[i].rawLoadNice = _cpus[i].loadNice;
1617
+ cores[i].rawLoadIdle = _cpus[i].loadIdle;
1618
+ cores[i].rawLoadIrq = _cpus[i].loadIrq;
1619
+ }
1620
+ result = {
1621
+ avgLoad: avgLoad,
1622
+ currentLoad: _current_cpu.currentLoad,
1623
+ currentLoadUser: _current_cpu.currentLoadUser,
1624
+ currentLoadSystem: _current_cpu.currentLoadSystem,
1625
+ currentLoadNice: _current_cpu.currentLoadNice,
1626
+ currentLoadIdle: _current_cpu.currentLoadIdle,
1627
+ currentLoadIrq: _current_cpu.currentLoadIrq,
1628
+ rawCurrentLoad: _current_cpu.rawCurrentLoad,
1629
+ rawCurrentLoadUser: _current_cpu.rawCurrentLoadUser,
1630
+ rawCurrentLoadSystem: _current_cpu.rawCurrentLoadSystem,
1631
+ rawCurrentLoadNice: _current_cpu.rawCurrentLoadNice,
1632
+ rawCurrentLoadIdle: _current_cpu.rawCurrentLoadIdle,
1633
+ rawCurrentLoadIrq: _current_cpu.rawCurrentLoadIrq,
1634
+ cpus: cores
1635
+ };
1636
+ }
1637
+ resolve(result);
1638
+ });
1639
+ });
1640
+ }
1641
+
1642
+ function currentLoad(callback) {
1643
+
1644
+ return new Promise((resolve) => {
1645
+ process.nextTick(() => {
1646
+ getLoad().then(result => {
1647
+ if (callback) { callback(result); }
1648
+ resolve(result);
1649
+ });
1650
+ });
1651
+ });
1652
+ }
1653
+
1654
+ exports.currentLoad = currentLoad;
1655
+
1656
+ // --------------------------
1657
+ // PS - full load
1658
+ // since bootup
1659
+
1660
+ function getFullLoad() {
1661
+
1662
+ return new Promise((resolve) => {
1663
+ process.nextTick(() => {
1664
+
1665
+ const cpus = os.cpus();
1666
+ let totalUser = 0;
1667
+ let totalSystem = 0;
1668
+ let totalNice = 0;
1669
+ let totalIrq = 0;
1670
+ let totalIdle = 0;
1671
+
1672
+ let result = 0;
1673
+
1674
+ if (cpus && cpus.length) {
1675
+ for (let i = 0, len = cpus.length; i < len; i++) {
1676
+ const cpu = cpus[i].times;
1677
+ totalUser += cpu.user;
1678
+ totalSystem += cpu.sys;
1679
+ totalNice += cpu.nice;
1680
+ totalIrq += cpu.irq;
1681
+ totalIdle += cpu.idle;
1682
+ }
1683
+ let totalTicks = totalIdle + totalIrq + totalNice + totalSystem + totalUser;
1684
+ result = (totalTicks - totalIdle) / totalTicks * 100.0;
1685
+
1686
+ }
1687
+ resolve(result);
1688
+ });
1689
+ });
1690
+ }
1691
+
1692
+ function fullLoad(callback) {
1693
+
1694
+ return new Promise((resolve) => {
1695
+ process.nextTick(() => {
1696
+ getFullLoad().then(result => {
1697
+ if (callback) { callback(result); }
1698
+ resolve(result);
1699
+ });
1700
+ });
1701
+ });
1702
+ }
1703
+
1704
+ exports.fullLoad = fullLoad;