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.

Files changed (33) hide show
  1. package/index.js +74 -0
  2. package/package.json +21 -0
  3. package/te/node_modules/.package-lock.json +44 -0
  4. package/te/node_modules/code-poltergeist-system-monitor/index.js +74 -0
  5. package/te/node_modules/code-poltergeist-system-monitor/package.json +21 -0
  6. package/te/node_modules/systeminformation/LICENSE +20 -0
  7. package/te/node_modules/systeminformation/README.md +1116 -0
  8. package/te/node_modules/systeminformation/lib/audio.js +222 -0
  9. package/te/node_modules/systeminformation/lib/battery.js +311 -0
  10. package/te/node_modules/systeminformation/lib/bluetooth.js +231 -0
  11. package/te/node_modules/systeminformation/lib/cli.js +91 -0
  12. package/te/node_modules/systeminformation/lib/cpu.js +1834 -0
  13. package/te/node_modules/systeminformation/lib/docker.js +758 -0
  14. package/te/node_modules/systeminformation/lib/dockerSocket.js +327 -0
  15. package/te/node_modules/systeminformation/lib/filesystem.js +1510 -0
  16. package/te/node_modules/systeminformation/lib/graphics.js +1125 -0
  17. package/te/node_modules/systeminformation/lib/index.d.ts +1041 -0
  18. package/te/node_modules/systeminformation/lib/index.js +504 -0
  19. package/te/node_modules/systeminformation/lib/internet.js +237 -0
  20. package/te/node_modules/systeminformation/lib/memory.js +575 -0
  21. package/te/node_modules/systeminformation/lib/network.js +1783 -0
  22. package/te/node_modules/systeminformation/lib/osinfo.js +1179 -0
  23. package/te/node_modules/systeminformation/lib/printer.js +210 -0
  24. package/te/node_modules/systeminformation/lib/processes.js +1296 -0
  25. package/te/node_modules/systeminformation/lib/system.js +742 -0
  26. package/te/node_modules/systeminformation/lib/usb.js +279 -0
  27. package/te/node_modules/systeminformation/lib/users.js +363 -0
  28. package/te/node_modules/systeminformation/lib/util.js +1373 -0
  29. package/te/node_modules/systeminformation/lib/virtualbox.js +107 -0
  30. package/te/node_modules/systeminformation/lib/wifi.js +834 -0
  31. package/te/node_modules/systeminformation/package.json +99 -0
  32. package/te/package-lock.json +52 -0
  33. package/te/package.json +15 -0
@@ -0,0 +1,575 @@
1
+ 'use strict';
2
+ // @ts-check
3
+ // ==================================================================================
4
+ // memory.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
+ // 5. Memory
14
+ // ----------------------------------------------------------------------------------
15
+
16
+ const os = require('os');
17
+ const exec = require('child_process').exec;
18
+ const execSync = require('child_process').execSync;
19
+ const util = require('./util');
20
+ const fs = require('fs');
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
+ const OSX_RAM_manufacturers = {
33
+ '0x014F': 'Transcend Information',
34
+ '0x2C00': 'Micron Technology Inc.',
35
+ '0x802C': 'Micron Technology Inc.',
36
+ '0x80AD': 'Hynix Semiconductor Inc.',
37
+ '0x80CE': 'Samsung Electronics Inc.',
38
+ '0xAD00': 'Hynix Semiconductor Inc.',
39
+ '0xCE00': 'Samsung Electronics Inc.',
40
+ '0x02FE': 'Elpida',
41
+ '0x5105': 'Qimonda AG i. In.',
42
+ '0x8551': 'Qimonda AG i. In.',
43
+ '0x859B': 'Crucial',
44
+ '0x04CD': 'G-Skill'
45
+ };
46
+
47
+ const LINUX_RAM_manufacturers = {
48
+ '017A': 'Apacer',
49
+ '0198': 'HyperX',
50
+ '029E': 'Corsair',
51
+ '04CB': 'A-DATA',
52
+ '04CD': 'G-Skill',
53
+ '059B': 'Crucial',
54
+ '00CE': 'Samsung',
55
+ '1315': 'Crucial',
56
+ '014F': 'Transcend Information',
57
+ '2C00': 'Micron Technology Inc.',
58
+ '802C': 'Micron Technology Inc.',
59
+ '80AD': 'Hynix Semiconductor Inc.',
60
+ '80CE': 'Samsung Electronics Inc.',
61
+ 'AD00': 'Hynix Semiconductor Inc.',
62
+ 'CE00': 'Samsung Electronics Inc.',
63
+ '02FE': 'Elpida',
64
+ '5105': 'Qimonda AG i. In.',
65
+ '8551': 'Qimonda AG i. In.',
66
+ '859B': 'Crucial'
67
+ };
68
+
69
+ // _______________________________________________________________________________________
70
+ // | R A M | H D |
71
+ // |______________________|_________________________| | |
72
+ // | active buffers/cache | | |
73
+ // |________________________________________________|___________|_________|______________|
74
+ // | used free | used free |
75
+ // |____________________________________________________________|________________________|
76
+ // | total | swap |
77
+ // |____________________________________________________________|________________________|
78
+
79
+ // free (older versions)
80
+ // ----------------------------------
81
+ // # free
82
+ // total used free shared buffers cached
83
+ // Mem: 16038 (1) 15653 (2) 384 (3) 0 (4) 236 (5) 14788 (6)
84
+ // -/+ buffers/cache: 628 (7) 15409 (8)
85
+ // Swap: 16371 83 16288
86
+ //
87
+ // |------------------------------------------------------------|
88
+ // | R A M |
89
+ // |______________________|_____________________________________|
90
+ // | active (2-(5+6) = 7) | available (3+5+6 = 8) |
91
+ // |______________________|_________________________|___________|
92
+ // | active | buffers/cache (5+6) | |
93
+ // |________________________________________________|___________|
94
+ // | used (2) | free (3) |
95
+ // |____________________________________________________________|
96
+ // | total (1) |
97
+ // |____________________________________________________________|
98
+
99
+ //
100
+ // free (since free von procps-ng 3.3.10)
101
+ // ----------------------------------
102
+ // # free
103
+ // total used free shared buffers/cache available
104
+ // Mem: 16038 (1) 628 (2) 386 (3) 0 (4) 15024 (5) 14788 (6)
105
+ // Swap: 16371 83 16288
106
+ //
107
+ // |------------------------------------------------------------|
108
+ // | R A M |
109
+ // |______________________|_____________________________________|
110
+ // | | available (6) estimated |
111
+ // |______________________|_________________________|___________|
112
+ // | active (2) | buffers/cache (5) | free (3) |
113
+ // |________________________________________________|___________|
114
+ // | total (1) |
115
+ // |____________________________________________________________|
116
+ //
117
+ // Reference: http://www.software-architect.net/blog/article/date/2015/06/12/-826c6e5052.html
118
+
119
+ // /procs/meminfo - sample (all in kB)
120
+ //
121
+ // MemTotal: 32806380 kB
122
+ // MemFree: 17977744 kB
123
+ // MemAvailable: 19768972 kB
124
+ // Buffers: 517028 kB
125
+ // Cached: 2161876 kB
126
+ // SwapCached: 456 kB
127
+ // Active: 12081176 kB
128
+ // Inactive: 2164616 kB
129
+ // Active(anon): 10832884 kB
130
+ // Inactive(anon): 1477272 kB
131
+ // Active(file): 1248292 kB
132
+ // Inactive(file): 687344 kB
133
+ // Unevictable: 0 kB
134
+ // Mlocked: 0 kB
135
+ // SwapTotal: 16768892 kB
136
+ // SwapFree: 16768304 kB
137
+ // Dirty: 268 kB
138
+ // Writeback: 0 kB
139
+ // AnonPages: 11568832 kB
140
+ // Mapped: 719992 kB
141
+ // Shmem: 743272 kB
142
+ // Slab: 335716 kB
143
+ // SReclaimable: 256364 kB
144
+ // SUnreclaim: 79352 kB
145
+
146
+ function mem(callback) {
147
+
148
+ return new Promise((resolve) => {
149
+ process.nextTick(() => {
150
+
151
+ let result = {
152
+ total: os.totalmem(),
153
+ free: os.freemem(),
154
+ used: os.totalmem() - os.freemem(),
155
+
156
+ active: os.totalmem() - os.freemem(), // temporarily (fallback)
157
+ available: os.freemem(), // temporarily (fallback)
158
+ buffers: 0,
159
+ cached: 0,
160
+ slab: 0,
161
+ buffcache: 0,
162
+
163
+ swaptotal: 0,
164
+ swapused: 0,
165
+ swapfree: 0,
166
+ writeback: null,
167
+ dirty: null
168
+ };
169
+
170
+ if (_linux) {
171
+ try {
172
+ fs.readFile('/proc/meminfo', function (error, stdout) {
173
+ if (!error) {
174
+ const lines = stdout.toString().split('\n');
175
+ result.total = parseInt(util.getValue(lines, 'memtotal'), 10);
176
+ result.total = result.total ? result.total * 1024 : os.totalmem();
177
+ result.free = parseInt(util.getValue(lines, 'memfree'), 10);
178
+ result.free = result.free ? result.free * 1024 : os.freemem();
179
+ result.used = result.total - result.free;
180
+
181
+ result.buffers = parseInt(util.getValue(lines, 'buffers'), 10);
182
+ result.buffers = result.buffers ? result.buffers * 1024 : 0;
183
+ result.cached = parseInt(util.getValue(lines, 'cached'), 10);
184
+ result.cached = result.cached ? result.cached * 1024 : 0;
185
+ result.slab = parseInt(util.getValue(lines, 'slab'), 10);
186
+ result.slab = result.slab ? result.slab * 1024 : 0;
187
+ result.buffcache = result.buffers + result.cached + result.slab;
188
+
189
+ let available = parseInt(util.getValue(lines, 'memavailable'), 10);
190
+ result.available = available ? available * 1024 : result.free + result.buffcache;
191
+ result.active = result.total - result.available;
192
+
193
+ result.swaptotal = parseInt(util.getValue(lines, 'swaptotal'), 10);
194
+ result.swaptotal = result.swaptotal ? result.swaptotal * 1024 : 0;
195
+ result.swapfree = parseInt(util.getValue(lines, 'swapfree'), 10);
196
+ result.swapfree = result.swapfree ? result.swapfree * 1024 : 0;
197
+ result.swapused = result.swaptotal - result.swapfree;
198
+ result.writeback = parseInt(util.getValue(lines, 'writeback'), 10);
199
+ result.writeback = result.writeback ? result.writeback * 1024 : 0;
200
+ result.dirty = parseInt(util.getValue(lines, 'dirty'), 10);
201
+ result.dirty = result.dirty ? result.dirty * 1024 : 0;
202
+ }
203
+ if (callback) { callback(result); }
204
+ resolve(result);
205
+ });
206
+ } catch (e) {
207
+ if (callback) { callback(result); }
208
+ resolve(result);
209
+ }
210
+ }
211
+ if (_freebsd || _openbsd || _netbsd) {
212
+ try {
213
+ exec('/sbin/sysctl hw.realmem hw.physmem vm.stats.vm.v_page_count vm.stats.vm.v_wire_count vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count vm.stats.vm.v_page_size', function (error, stdout) {
214
+ if (!error) {
215
+ let lines = stdout.toString().split('\n');
216
+ const pagesize = parseInt(util.getValue(lines, 'vm.stats.vm.v_page_size'), 10);
217
+ const inactive = parseInt(util.getValue(lines, 'vm.stats.vm.v_inactive_count'), 10) * pagesize;
218
+ const cache = parseInt(util.getValue(lines, 'vm.stats.vm.v_cache_count'), 10) * pagesize;
219
+
220
+ result.total = parseInt(util.getValue(lines, 'hw.realmem'), 10);
221
+ if (isNaN(result.total)) { result.total = parseInt(util.getValue(lines, 'hw.physmem'), 10); }
222
+ result.free = parseInt(util.getValue(lines, 'vm.stats.vm.v_free_count'), 10) * pagesize;
223
+ result.buffcache = inactive + cache;
224
+ result.available = result.buffcache + result.free;
225
+ result.active = result.total - result.free - result.buffcache;
226
+
227
+ result.swaptotal = 0;
228
+ result.swapfree = 0;
229
+ result.swapused = 0;
230
+
231
+ }
232
+ if (callback) { callback(result); }
233
+ resolve(result);
234
+ });
235
+ } catch (e) {
236
+ if (callback) { callback(result); }
237
+ resolve(result);
238
+ }
239
+ }
240
+ if (_sunos) {
241
+ if (callback) { callback(result); }
242
+ resolve(result);
243
+ }
244
+ if (_darwin) {
245
+ let pageSize = 4096;
246
+ try {
247
+ let sysPpageSize = util.toInt(execSync('sysctl -n vm.pagesize').toString());
248
+ pageSize = sysPpageSize || pageSize;
249
+ } catch (e) {
250
+ util.noop();
251
+ }
252
+ try {
253
+ exec('vm_stat 2>/dev/null | grep "Pages active"', function (error, stdout) {
254
+ if (!error) {
255
+ let lines = stdout.toString().split('\n');
256
+
257
+ result.active = parseInt(lines[0].split(':')[1], 10) * pageSize;
258
+ result.buffcache = result.used - result.active;
259
+ result.available = result.free + result.buffcache;
260
+ }
261
+ exec('sysctl -n vm.swapusage 2>/dev/null', function (error, stdout) {
262
+ if (!error) {
263
+ let lines = stdout.toString().split('\n');
264
+ if (lines.length > 0) {
265
+ let firstline = lines[0].replace(/,/g, '.').replace(/M/g, '');
266
+ let lineArray = firstline.trim().split(' ');
267
+ lineArray.forEach(line => {
268
+ if (line.toLowerCase().indexOf('total') !== -1) { result.swaptotal = parseFloat(line.split('=')[1].trim()) * 1024 * 1024; }
269
+ if (line.toLowerCase().indexOf('used') !== -1) { result.swapused = parseFloat(line.split('=')[1].trim()) * 1024 * 1024; }
270
+ if (line.toLowerCase().indexOf('free') !== -1) { result.swapfree = parseFloat(line.split('=')[1].trim()) * 1024 * 1024; }
271
+ });
272
+ }
273
+ }
274
+ if (callback) { callback(result); }
275
+ resolve(result);
276
+ });
277
+ });
278
+ } catch (e) {
279
+ if (callback) { callback(result); }
280
+ resolve(result);
281
+ }
282
+ }
283
+ if (_windows) {
284
+ let swaptotal = 0;
285
+ let swapused = 0;
286
+ try {
287
+ util.powerShell('Get-CimInstance Win32_PageFileUsage | Select AllocatedBaseSize, CurrentUsage').then((stdout, error) => {
288
+ if (!error) {
289
+ let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
290
+ lines.forEach(function (line) {
291
+ if (line !== '') {
292
+ line = line.trim().split(/\s\s+/);
293
+ swaptotal = swaptotal + (parseInt(line[0], 10) || 0);
294
+ swapused = swapused + (parseInt(line[1], 10) || 0);
295
+ }
296
+ });
297
+ }
298
+ result.swaptotal = swaptotal * 1024 * 1024;
299
+ result.swapused = swapused * 1024 * 1024;
300
+ result.swapfree = result.swaptotal - result.swapused;
301
+
302
+ if (callback) { callback(result); }
303
+ resolve(result);
304
+ });
305
+ } catch (e) {
306
+ if (callback) { callback(result); }
307
+ resolve(result);
308
+ }
309
+ }
310
+ });
311
+ });
312
+ }
313
+
314
+ exports.mem = mem;
315
+
316
+ function memLayout(callback) {
317
+
318
+ function getManufacturerDarwin(manId) {
319
+ if ({}.hasOwnProperty.call(OSX_RAM_manufacturers, manId)) {
320
+ return (OSX_RAM_manufacturers[manId]);
321
+ }
322
+ return manId;
323
+ }
324
+
325
+ function getManufacturerLinux(manId) {
326
+ const manIdSearch = manId.replace('0x', '').toUpperCase();
327
+ if (manIdSearch.length === 4 && {}.hasOwnProperty.call(LINUX_RAM_manufacturers, manIdSearch)) {
328
+ return (LINUX_RAM_manufacturers[manIdSearch]);
329
+ }
330
+ return manId;
331
+ }
332
+
333
+ return new Promise((resolve) => {
334
+ process.nextTick(() => {
335
+
336
+ let result = [];
337
+
338
+ if (_linux || _freebsd || _openbsd || _netbsd) {
339
+ exec('export LC_ALL=C; dmidecode -t memory 2>/dev/null | grep -iE "Size:|Type|Speed|Manufacturer|Form Factor|Locator|Memory Device|Serial Number|Voltage|Part Number"; unset LC_ALL', function (error, stdout) {
340
+ if (!error) {
341
+ let devices = stdout.toString().split('Memory Device');
342
+ devices.shift();
343
+ devices.forEach(function (device) {
344
+ let lines = device.split('\n');
345
+ const sizeString = util.getValue(lines, 'Size');
346
+ const size = sizeString.indexOf('GB') >= 0 ? parseInt(sizeString, 10) * 1024 * 1024 * 1024 : parseInt(sizeString, 10) * 1024 * 1024;
347
+ let bank = util.getValue(lines, 'Bank Locator');
348
+ if (bank.toLowerCase().indexOf('bad') >= 0) {
349
+ bank = '';
350
+ }
351
+ if (parseInt(util.getValue(lines, 'Size'), 10) > 0) {
352
+ const totalWidth = util.toInt(util.getValue(lines, 'Total Width'));
353
+ const dataWidth = util.toInt(util.getValue(lines, 'Data Width'));
354
+ result.push({
355
+ size,
356
+ bank,
357
+ type: util.getValue(lines, 'Type:'),
358
+ ecc: dataWidth && totalWidth ? totalWidth > dataWidth : false,
359
+ clockSpeed: (util.getValue(lines, 'Configured Clock Speed:') ? parseInt(util.getValue(lines, 'Configured Clock Speed:'), 10) : (util.getValue(lines, 'Speed:') ? parseInt(util.getValue(lines, 'Speed:'), 10) : null)),
360
+ formFactor: util.getValue(lines, 'Form Factor:'),
361
+ manufacturer: getManufacturerLinux(util.getValue(lines, 'Manufacturer:')),
362
+ partNum: util.getValue(lines, 'Part Number:'),
363
+ serialNum: util.getValue(lines, 'Serial Number:'),
364
+ voltageConfigured: parseFloat(util.getValue(lines, 'Configured Voltage:')) || null,
365
+ voltageMin: parseFloat(util.getValue(lines, 'Minimum Voltage:')) || null,
366
+ voltageMax: parseFloat(util.getValue(lines, 'Maximum Voltage:')) || null,
367
+ });
368
+ } else {
369
+ result.push({
370
+ size: 0,
371
+ bank,
372
+ type: 'Empty',
373
+ ecc: null,
374
+ clockSpeed: 0,
375
+ formFactor: util.getValue(lines, 'Form Factor:'),
376
+ partNum: '',
377
+ serialNum: '',
378
+ voltageConfigured: null,
379
+ voltageMin: null,
380
+ voltageMax: null,
381
+ });
382
+ }
383
+ });
384
+ }
385
+ if (!result.length) {
386
+ result.push({
387
+ size: os.totalmem(),
388
+ bank: '',
389
+ type: '',
390
+ ecc: null,
391
+ clockSpeed: 0,
392
+ formFactor: '',
393
+ partNum: '',
394
+ serialNum: '',
395
+ voltageConfigured: null,
396
+ voltageMin: null,
397
+ voltageMax: null,
398
+ });
399
+
400
+ // Try Raspberry PI
401
+ try {
402
+ let stdout = execSync('cat /proc/cpuinfo 2>/dev/null', util.execOptsLinux);
403
+ let lines = stdout.toString().split('\n');
404
+ let model = util.getValue(lines, 'hardware', ':', true).toUpperCase();
405
+ let version = util.getValue(lines, 'revision', ':', true).toLowerCase();
406
+
407
+ if (model === 'BCM2835' || model === 'BCM2708' || model === 'BCM2709' || model === 'BCM2835' || model === 'BCM2837') {
408
+
409
+ const clockSpeed = {
410
+ '0': 400,
411
+ '1': 450,
412
+ '2': 450,
413
+ '3': 3200
414
+ };
415
+ result[0].type = 'LPDDR2';
416
+ result[0].type = version && version[2] && version[2] === '3' ? 'LPDDR4' : result[0].type;
417
+ result[0].ecc = false;
418
+ result[0].clockSpeed = version && version[2] && clockSpeed[version[2]] || 400;
419
+ result[0].clockSpeed = version && version[4] && version[4] === 'd' ? 500 : result[0].clockSpeed;
420
+ result[0].formFactor = 'SoC';
421
+
422
+ stdout = execSync('vcgencmd get_config sdram_freq 2>/dev/null', util.execOptsLinux);
423
+ lines = stdout.toString().split('\n');
424
+ let freq = parseInt(util.getValue(lines, 'sdram_freq', '=', true), 10) || 0;
425
+ if (freq) {
426
+ result[0].clockSpeed = freq;
427
+ }
428
+
429
+ stdout = execSync('vcgencmd measure_volts sdram_p 2>/dev/null', util.execOptsLinux);
430
+ lines = stdout.toString().split('\n');
431
+ let voltage = parseFloat(util.getValue(lines, 'volt', '=', true)) || 0;
432
+ if (voltage) {
433
+ result[0].voltageConfigured = voltage;
434
+ result[0].voltageMin = voltage;
435
+ result[0].voltageMax = voltage;
436
+ }
437
+ }
438
+ } catch (e) {
439
+ util.noop();
440
+ }
441
+
442
+ }
443
+ if (callback) { callback(result); }
444
+ resolve(result);
445
+ });
446
+ }
447
+
448
+ if (_darwin) {
449
+ exec('system_profiler SPMemoryDataType', function (error, stdout) {
450
+ if (!error) {
451
+ const allLines = stdout.toString().split('\n');
452
+ const eccStatus = util.getValue(allLines, 'ecc', ':', true).toLowerCase();
453
+ let devices = stdout.toString().split(' BANK ');
454
+ let hasBank = true;
455
+ if (devices.length === 1) {
456
+ devices = stdout.toString().split(' DIMM');
457
+ hasBank = false;
458
+ }
459
+ devices.shift();
460
+ devices.forEach(function (device) {
461
+ let lines = device.split('\n');
462
+ const bank = (hasBank ? 'BANK ' : 'DIMM') + lines[0].trim().split('/')[0];
463
+ const size = parseInt(util.getValue(lines, ' Size'));
464
+ if (size) {
465
+ result.push({
466
+ size: size * 1024 * 1024 * 1024,
467
+ bank: bank,
468
+ type: util.getValue(lines, ' Type:'),
469
+ ecc: eccStatus ? eccStatus === 'enabled' : null,
470
+ clockSpeed: parseInt(util.getValue(lines, ' Speed:'), 10),
471
+ formFactor: '',
472
+ manufacturer: getManufacturerDarwin(util.getValue(lines, ' Manufacturer:')),
473
+ partNum: util.getValue(lines, ' Part Number:'),
474
+ serialNum: util.getValue(lines, ' Serial Number:'),
475
+ voltageConfigured: null,
476
+ voltageMin: null,
477
+ voltageMax: null,
478
+ });
479
+ } else {
480
+ result.push({
481
+ size: 0,
482
+ bank: bank,
483
+ type: 'Empty',
484
+ ecc: null,
485
+ clockSpeed: 0,
486
+ formFactor: '',
487
+ manufacturer: '',
488
+ partNum: '',
489
+ serialNum: '',
490
+ voltageConfigured: null,
491
+ voltageMin: null,
492
+ voltageMax: null,
493
+ });
494
+ }
495
+ });
496
+ }
497
+ if (!result.length) {
498
+ const lines = stdout.toString().split('\n');
499
+ const size = parseInt(util.getValue(lines, ' Memory:'));
500
+ const type = util.getValue(lines, ' Type:');
501
+ if (size && type) {
502
+ result.push({
503
+ size: size * 1024 * 1024 * 1024,
504
+ bank: '0',
505
+ type,
506
+ ecc: false,
507
+ clockSpeed: 0,
508
+ formFactor: '',
509
+ manufacturer: 'Apple',
510
+ partNum: '',
511
+ serialNum: '',
512
+ voltageConfigured: null,
513
+ voltageMin: null,
514
+ voltageMax: null,
515
+ });
516
+
517
+ }
518
+ }
519
+ if (callback) { callback(result); }
520
+ resolve(result);
521
+ });
522
+ }
523
+ if (_sunos) {
524
+ if (callback) { callback(result); }
525
+ resolve(result);
526
+ }
527
+ if (_windows) {
528
+ // https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.4.0a.pdf
529
+ const memoryTypes = 'Unknown|Other|DRAM|Synchronous DRAM|Cache DRAM|EDO|EDRAM|VRAM|SRAM|RAM|ROM|FLASH|EEPROM|FEPROM|EPROM|CDRAM|3DRAM|SDRAM|SGRAM|RDRAM|DDR|DDR2|DDR2 FB-DIMM|Reserved|DDR3|FBD2|DDR4|LPDDR|LPDDR2|LPDDR3|LPDDR4|Logical non-volatile device|HBM|HBM2|DDR5|LPDDR5'.split('|');
530
+ const FormFactors = 'Unknown|Other|SIP|DIP|ZIP|SOJ|Proprietary|SIMM|DIMM|TSOP|PGA|RIMM|SODIMM|SRIMM|SMD|SSMP|QFP|TQFP|SOIC|LCC|PLCC|BGA|FPBGA|LGA'.split('|');
531
+
532
+ try {
533
+ util.powerShell('Get-CimInstance Win32_PhysicalMemory | select DataWidth,TotalWidth,Capacity,BankLabel,MemoryType,SMBIOSMemoryType,ConfiguredClockSpeed,FormFactor,Manufacturer,PartNumber,SerialNumber,ConfiguredVoltage,MinVoltage,MaxVoltage,Tag | fl').then((stdout, error) => {
534
+ if (!error) {
535
+ let devices = stdout.toString().split(/\n\s*\n/);
536
+ devices.shift();
537
+ devices.forEach(function (device) {
538
+ let lines = device.split('\r\n');
539
+ const dataWidth = util.toInt(util.getValue(lines, 'DataWidth', ':'));
540
+ const totalWidth = util.toInt(util.getValue(lines, 'TotalWidth', ':'));
541
+ const size = parseInt(util.getValue(lines, 'Capacity', ':'), 10) || 0;
542
+ const tag = util.getValue(lines, 'Tag', ':');
543
+ const tagInt = util.splitByNumber(tag);
544
+ if (size) {
545
+ result.push({
546
+ size,
547
+ bank: util.getValue(lines, 'BankLabel', ':') + (tagInt[1] ? '/' + tagInt[1] : ''), // BankLabel
548
+ type: memoryTypes[parseInt(util.getValue(lines, 'MemoryType', ':'), 10) || parseInt(util.getValue(lines, 'SMBIOSMemoryType', ':'), 10)],
549
+ ecc: dataWidth && totalWidth ? totalWidth > dataWidth : false,
550
+ clockSpeed: parseInt(util.getValue(lines, 'ConfiguredClockSpeed', ':'), 10) || parseInt(util.getValue(lines, 'Speed', ':'), 10) || 0,
551
+ formFactor: FormFactors[parseInt(util.getValue(lines, 'FormFactor', ':'), 10) || 0],
552
+ manufacturer: util.getValue(lines, 'Manufacturer', ':'),
553
+ partNum: util.getValue(lines, 'PartNumber', ':'),
554
+ serialNum: util.getValue(lines, 'SerialNumber', ':'),
555
+ voltageConfigured: (parseInt(util.getValue(lines, 'ConfiguredVoltage', ':'), 10) || 0) / 1000.0,
556
+ voltageMin: (parseInt(util.getValue(lines, 'MinVoltage', ':'), 10) || 0) / 1000.0,
557
+ voltageMax: (parseInt(util.getValue(lines, 'MaxVoltage', ':'), 10) || 0) / 1000.0,
558
+ });
559
+ }
560
+ });
561
+ }
562
+ if (callback) { callback(result); }
563
+ resolve(result);
564
+ });
565
+ } catch (e) {
566
+ if (callback) { callback(result); }
567
+ resolve(result);
568
+ }
569
+ }
570
+ });
571
+ });
572
+ }
573
+
574
+ exports.memLayout = memLayout;
575
+