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