systeminformation 5.28.0 → 5.28.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/processes.js CHANGED
@@ -23,13 +23,13 @@ const util = require('./util');
23
23
 
24
24
  let _platform = process.platform;
25
25
 
26
- const _linux = (_platform === 'linux' || _platform === 'android');
27
- const _darwin = (_platform === 'darwin');
28
- const _windows = (_platform === 'win32');
29
- const _freebsd = (_platform === 'freebsd');
30
- const _openbsd = (_platform === 'openbsd');
31
- const _netbsd = (_platform === 'netbsd');
32
- const _sunos = (_platform === 'sunos');
26
+ const _linux = _platform === 'linux' || _platform === 'android';
27
+ const _darwin = _platform === 'darwin';
28
+ const _windows = _platform === 'win32';
29
+ const _freebsd = _platform === 'freebsd';
30
+ const _openbsd = _platform === 'openbsd';
31
+ const _netbsd = _platform === 'netbsd';
32
+ const _sunos = _platform === 'sunos';
33
33
 
34
34
  const _processes_cpu = {
35
35
  all: 0,
@@ -57,16 +57,16 @@ const _process_cpu = {
57
57
  };
58
58
 
59
59
  const _winStatusValues = {
60
- '0': 'unknown',
61
- '1': 'other',
62
- '2': 'ready',
63
- '3': 'running',
64
- '4': 'blocked',
65
- '5': 'suspended blocked',
66
- '6': 'suspended ready',
67
- '7': 'terminated',
68
- '8': 'stopped',
69
- '9': 'growing',
60
+ 0: 'unknown',
61
+ 1: 'other',
62
+ 2: 'ready',
63
+ 3: 'running',
64
+ 4: 'blocked',
65
+ 5: 'suspended blocked',
66
+ 6: 'suspended ready',
67
+ 7: 'terminated',
68
+ 8: 'stopped',
69
+ 9: 'growing'
70
70
  };
71
71
 
72
72
  function parseTimeUnix(time) {
@@ -91,7 +91,7 @@ function parseElapsedTime(etime) {
91
91
  const hours = timeStr.length === 3 ? parseInt(timeStr[0] || 0) : 0;
92
92
  const mins = parseInt(timeStr[timeStr.length === 3 ? 1 : 0] || 0);
93
93
  const secs = parseInt(timeStr[timeStr.length === 3 ? 2 : 1] || 0);
94
- const ms = (((((days * 24 + hours) * 60) + mins) * 60 + secs) * 1000);
94
+ const ms = (((days * 24 + hours) * 60 + mins) * 60 + secs) * 1000;
95
95
 
96
96
  let res = new Date(current.getTime());
97
97
  let result = res.toISOString().substring(0, 10) + ' ' + res.toISOString().substring(11, 19);
@@ -110,7 +110,6 @@ function parseElapsedTime(etime) {
110
110
  // this function gives an array back, if the services are running.
111
111
 
112
112
  function services(srv, callback) {
113
-
114
113
  // fallback - if only callback is given
115
114
  if (util.isFunction(srv) && !callback) {
116
115
  callback = srv;
@@ -120,7 +119,9 @@ function services(srv, callback) {
120
119
  return new Promise((resolve) => {
121
120
  process.nextTick(() => {
122
121
  if (typeof srv !== 'string') {
123
- if (callback) { callback([]); }
122
+ if (callback) {
123
+ callback([]);
124
+ }
124
125
  return resolve([]);
125
126
  }
126
127
 
@@ -201,11 +202,14 @@ function services(srv, callback) {
201
202
  }
202
203
  }
203
204
  }
204
- if ((_darwin) && srvString === '*') { // service enumeration not yet suported on mac OS
205
- if (callback) { callback(result); }
205
+ if (_darwin && srvString === '*') {
206
+ // service enumeration not yet suported on mac OS
207
+ if (callback) {
208
+ callback(result);
209
+ }
206
210
  resolve(result);
207
211
  }
208
- let args = (_darwin) ? ['-caxo', 'pcpu,pmem,pid,command'] : ['-axo', 'pcpu,pmem,pid,command'];
212
+ let args = _darwin ? ['-caxo', 'pcpu,pmem,pid,command'] : ['-axo', 'pcpu,pmem,pid,command'];
209
213
  if (srvString !== '' && srvs.length > 0) {
210
214
  util.execSafe('ps', args).then((stdout) => {
211
215
  if (stdout) {
@@ -214,12 +218,17 @@ function services(srv, callback) {
214
218
  let ps;
215
219
  if (_darwin) {
216
220
  ps = lines.filter(function (e) {
217
- return (e.toLowerCase().indexOf(srv) !== -1);
221
+ return e.toLowerCase().indexOf(srv) !== -1;
218
222
  });
219
-
220
223
  } else {
221
224
  ps = lines.filter(function (e) {
222
- return (e.toLowerCase().indexOf(' ' + srv.toLowerCase() + ':') !== -1) || (e.toLowerCase().indexOf('(' + srv.toLowerCase() + ' ') !== -1) || (e.toLowerCase().indexOf('(' + srv.toLowerCase() + ')') !== -1) || (e.toLowerCase().indexOf(' ' + srv.toLowerCase().replace(/[0-9.]/g, '') + ':') !== -1) || (e.toLowerCase().indexOf('/' + srv.toLowerCase()) !== -1);
225
+ return (
226
+ e.toLowerCase().indexOf(' ' + srv.toLowerCase() + ':') !== -1 ||
227
+ e.toLowerCase().indexOf('(' + srv.toLowerCase() + ' ') !== -1 ||
228
+ e.toLowerCase().indexOf('(' + srv.toLowerCase() + ')') !== -1 ||
229
+ e.toLowerCase().indexOf(' ' + srv.toLowerCase().replace(/[0-9.]/g, '') + ':') !== -1 ||
230
+ e.toLowerCase().indexOf('/' + srv.toLowerCase()) !== -1
231
+ );
223
232
  });
224
233
  }
225
234
  const pids = [];
@@ -234,12 +243,20 @@ function services(srv, callback) {
234
243
  running: ps.length > 0,
235
244
  startmode: '',
236
245
  pids: pids,
237
- cpu: parseFloat((ps.reduce(function (pv, cv) {
238
- return pv + parseFloat(cv.trim().split(' ')[0]);
239
- }, 0)).toFixed(2)),
240
- mem: parseFloat((ps.reduce(function (pv, cv) {
241
- return pv + parseFloat(cv.trim().split(' ')[1]);
242
- }, 0)).toFixed(2))
246
+ cpu: parseFloat(
247
+ ps
248
+ .reduce(function (pv, cv) {
249
+ return pv + parseFloat(cv.trim().split(' ')[0]);
250
+ }, 0)
251
+ .toFixed(2)
252
+ ),
253
+ mem: parseFloat(
254
+ ps
255
+ .reduce(function (pv, cv) {
256
+ return pv + parseFloat(cv.trim().split(' ')[1]);
257
+ }, 0)
258
+ .toFixed(2)
259
+ )
243
260
  });
244
261
  });
245
262
  if (_linux) {
@@ -247,10 +264,10 @@ function services(srv, callback) {
247
264
  let cmd = 'cat /proc/stat | grep "cpu "';
248
265
  for (let i in result) {
249
266
  for (let j in result[i].pids) {
250
- cmd += (';cat /proc/' + result[i].pids[j] + '/stat');
267
+ cmd += ';cat /proc/' + result[i].pids[j] + '/stat';
251
268
  }
252
269
  }
253
- exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) {
270
+ exec(cmd, { maxBuffer: 1024 * 102400 }, function (error, stdout) {
254
271
  let curr_processes = stdout.toString().split('\n');
255
272
 
256
273
  // first line (all - /proc/stat)
@@ -292,11 +309,15 @@ function services(srv, callback) {
292
309
  _services_cpu.list = Object.assign({}, list_new);
293
310
  _services_cpu.ms = Date.now() - _services_cpu.ms;
294
311
  _services_cpu.result = Object.assign({}, result);
295
- if (callback) { callback(result); }
312
+ if (callback) {
313
+ callback(result);
314
+ }
296
315
  resolve(result);
297
316
  });
298
317
  } else {
299
- if (callback) { callback(result); }
318
+ if (callback) {
319
+ callback(result);
320
+ }
300
321
  resolve(result);
301
322
  }
302
323
  } else {
@@ -316,7 +337,9 @@ function services(srv, callback) {
316
337
  mem: 0
317
338
  });
318
339
  });
319
- if (callback) { callback(result); }
340
+ if (callback) {
341
+ callback(result);
342
+ }
320
343
  resolve(result);
321
344
  } else {
322
345
  srvs.forEach(function (srv) {
@@ -328,14 +351,18 @@ function services(srv, callback) {
328
351
  mem: 0
329
352
  });
330
353
  });
331
- if (callback) { callback(result); }
354
+ if (callback) {
355
+ callback(result);
356
+ }
332
357
  resolve(result);
333
358
  }
334
359
  });
335
360
  }
336
361
  });
337
362
  } else {
338
- if (callback) { callback(result); }
363
+ if (callback) {
364
+ callback(result);
365
+ }
339
366
  resolve(result);
340
367
  }
341
368
  }
@@ -364,7 +391,7 @@ function services(srv, callback) {
364
391
  if (srvString === '*' || srvs.indexOf(srvName) >= 0 || srvs.indexOf(srvCaption) >= 0) {
365
392
  result.push({
366
393
  name: srvName,
367
- running: (started.toLowerCase() === 'true'),
394
+ running: started.toLowerCase() === 'true',
368
395
  startmode: startMode,
369
396
  pids: [pid],
370
397
  cpu: 0,
@@ -374,14 +401,11 @@ function services(srv, callback) {
374
401
  dataSrv.push(srvCaption);
375
402
  }
376
403
  }
377
-
378
404
  });
379
405
 
380
406
  if (srvString !== '*') {
381
- let srvsMissing = srvs.filter(function (e) {
382
- return dataSrv.indexOf(e) === -1;
383
- });
384
- srvsMissing.forEach(function (srvName) {
407
+ const srvsMissing = srvs.filter((e) => dataSrv.indexOf(e) === -1);
408
+ srvsMissing.forEach((srvName) => {
385
409
  result.push({
386
410
  name: srvName,
387
411
  running: false,
@@ -392,10 +416,12 @@ function services(srv, callback) {
392
416
  });
393
417
  });
394
418
  }
395
- if (callback) { callback(result); }
419
+ if (callback) {
420
+ callback(result);
421
+ }
396
422
  resolve(result);
397
423
  } else {
398
- srvs.forEach(function (srvName) {
424
+ srvs.forEach((srvName) => {
399
425
  result.push({
400
426
  name: srvName,
401
427
  running: false,
@@ -404,17 +430,23 @@ function services(srv, callback) {
404
430
  mem: 0
405
431
  });
406
432
  });
407
- if (callback) { callback(result); }
433
+ if (callback) {
434
+ callback(result);
435
+ }
408
436
  resolve(result);
409
437
  }
410
438
  });
411
- } catch (e) {
412
- if (callback) { callback(result); }
439
+ } catch {
440
+ if (callback) {
441
+ callback(result);
442
+ }
413
443
  resolve(result);
414
444
  }
415
445
  }
416
446
  } else {
417
- if (callback) { callback([]); }
447
+ if (callback) {
448
+ callback([]);
449
+ }
418
450
  resolve([]);
419
451
  }
420
452
  });
@@ -424,17 +456,17 @@ function services(srv, callback) {
424
456
  exports.services = services;
425
457
 
426
458
  function parseProcStat(line) {
427
- let parts = line.replace(/ +/g, ' ').split(' ');
428
- let user = (parts.length >= 2 ? parseInt(parts[1]) : 0);
429
- let nice = (parts.length >= 3 ? parseInt(parts[2]) : 0);
430
- let system = (parts.length >= 4 ? parseInt(parts[3]) : 0);
431
- let idle = (parts.length >= 5 ? parseInt(parts[4]) : 0);
432
- let iowait = (parts.length >= 6 ? parseInt(parts[5]) : 0);
433
- let irq = (parts.length >= 7 ? parseInt(parts[6]) : 0);
434
- let softirq = (parts.length >= 8 ? parseInt(parts[7]) : 0);
435
- let steal = (parts.length >= 9 ? parseInt(parts[8]) : 0);
436
- let guest = (parts.length >= 10 ? parseInt(parts[9]) : 0);
437
- let guest_nice = (parts.length >= 11 ? parseInt(parts[10]) : 0);
459
+ const parts = line.replace(/ +/g, ' ').split(' ');
460
+ const user = parts.length >= 2 ? parseInt(parts[1]) : 0;
461
+ const nice = parts.length >= 3 ? parseInt(parts[2]) : 0;
462
+ const system = parts.length >= 4 ? parseInt(parts[3]) : 0;
463
+ const idle = parts.length >= 5 ? parseInt(parts[4]) : 0;
464
+ const iowait = parts.length >= 6 ? parseInt(parts[5]) : 0;
465
+ const irq = parts.length >= 7 ? parseInt(parts[6]) : 0;
466
+ const softirq = parts.length >= 8 ? parseInt(parts[7]) : 0;
467
+ const steal = parts.length >= 9 ? parseInt(parts[8]) : 0;
468
+ const guest = parts.length >= 10 ? parseInt(parts[9]) : 0;
469
+ const guest_nice = parts.length >= 11 ? parseInt(parts[10]) : 0;
438
470
  return user + nice + system + idle + iowait + irq + softirq + steal + guest + guest_nice;
439
471
  }
440
472
 
@@ -453,11 +485,11 @@ function calcProcStatLinux(line, all, _cpu_old) {
453
485
  let cpuu = 0;
454
486
  let cpus = 0;
455
487
  if (_cpu_old.all > 0 && _cpu_old.list[pid]) {
456
- cpuu = (utime + cutime - _cpu_old.list[pid].utime - _cpu_old.list[pid].cutime) / (all - _cpu_old.all) * 100; // user
457
- cpus = (stime + cstime - _cpu_old.list[pid].stime - _cpu_old.list[pid].cstime) / (all - _cpu_old.all) * 100; // system
488
+ cpuu = ((utime + cutime - _cpu_old.list[pid].utime - _cpu_old.list[pid].cutime) / (all - _cpu_old.all)) * 100; // user
489
+ cpus = ((stime + cstime - _cpu_old.list[pid].stime - _cpu_old.list[pid].cstime) / (all - _cpu_old.all)) * 100; // system
458
490
  } else {
459
- cpuu = (utime + cutime) / (all) * 100; // user
460
- cpus = (stime + cstime) / (all) * 100; // system
491
+ cpuu = ((utime + cutime) / all) * 100; // user
492
+ cpus = ((stime + cstime) / all) * 100; // system
461
493
  }
462
494
  return {
463
495
  pid: pid,
@@ -497,11 +529,11 @@ function calcProcStatWin(procStat, all, _cpu_old) {
497
529
  let cpuu = 0;
498
530
  let cpus = 0;
499
531
  if (_cpu_old.all > 0 && _cpu_old.list[procStat.pid]) {
500
- cpuu = (procStat.utime - _cpu_old.list[procStat.pid].utime) / (all - _cpu_old.all) * 100; // user
501
- cpus = (procStat.stime - _cpu_old.list[procStat.pid].stime) / (all - _cpu_old.all) * 100; // system
532
+ cpuu = ((procStat.utime - _cpu_old.list[procStat.pid].utime) / (all - _cpu_old.all)) * 100; // user
533
+ cpus = ((procStat.stime - _cpu_old.list[procStat.pid].stime) / (all - _cpu_old.all)) * 100; // system
502
534
  } else {
503
- cpuu = (procStat.utime) / (all) * 100; // user
504
- cpus = (procStat.stime) / (all) * 100; // system
535
+ cpuu = (procStat.utime / all) * 100; // user
536
+ cpus = (procStat.stime / all) * 100; // system
505
537
  }
506
538
  return {
507
539
  pid: procStat.pid,
@@ -512,13 +544,10 @@ function calcProcStatWin(procStat, all, _cpu_old) {
512
544
  };
513
545
  }
514
546
 
515
-
516
-
517
547
  // --------------------------
518
548
  // running processes
519
549
 
520
550
  function processes(callback) {
521
-
522
551
  let parsedhead = [];
523
552
 
524
553
  function getName(command) {
@@ -539,7 +568,6 @@ function processes(callback) {
539
568
  }
540
569
 
541
570
  function parseLine(line) {
542
-
543
571
  let offset = 0;
544
572
  let offset2 = 0;
545
573
 
@@ -569,13 +597,32 @@ function processes(callback) {
569
597
  checkColumn(7);
570
598
  const nice = parseInt(line.substring(parsedhead[7].from + offset, parsedhead[7].to + offset2)) || 0;
571
599
  checkColumn(8);
572
- const started = !_sunos ? parseElapsedTime(line.substring(parsedhead[8].from + offset, parsedhead[8].to + offset2).trim()) : parseTimeUnix(line.substring(parsedhead[8].from + offset, parsedhead[8].to + offset2).trim());
600
+ const started = !_sunos
601
+ ? parseElapsedTime(line.substring(parsedhead[8].from + offset, parsedhead[8].to + offset2).trim())
602
+ : parseTimeUnix(line.substring(parsedhead[8].from + offset, parsedhead[8].to + offset2).trim());
573
603
  checkColumn(9);
574
604
  let state = line.substring(parsedhead[9].from + offset, parsedhead[9].to + offset2).trim();
575
- state = (state[0] === 'R' ? 'running' : (state[0] === 'S' ? 'sleeping' : (state[0] === 'T' ? 'stopped' : (state[0] === 'W' ? 'paging' : (state[0] === 'X' ? 'dead' : (state[0] === 'Z' ? 'zombie' : ((state[0] === 'D' || state[0] === 'U') ? 'blocked' : 'unknown')))))));
605
+ state =
606
+ state[0] === 'R'
607
+ ? 'running'
608
+ : state[0] === 'S'
609
+ ? 'sleeping'
610
+ : state[0] === 'T'
611
+ ? 'stopped'
612
+ : state[0] === 'W'
613
+ ? 'paging'
614
+ : state[0] === 'X'
615
+ ? 'dead'
616
+ : state[0] === 'Z'
617
+ ? 'zombie'
618
+ : state[0] === 'D' || state[0] === 'U'
619
+ ? 'blocked'
620
+ : 'unknown';
576
621
  checkColumn(10);
577
622
  let tty = line.substring(parsedhead[10].from + offset, parsedhead[10].to + offset2).trim();
578
- if (tty === '?' || tty === '??') { tty = ''; }
623
+ if (tty === '?' || tty === '??') {
624
+ tty = '';
625
+ }
579
626
  checkColumn(11);
580
627
  const user = line.substring(parsedhead[11].from + offset, parsedhead[11].to + offset2).trim();
581
628
  checkColumn(12);
@@ -583,9 +630,12 @@ function processes(callback) {
583
630
  let command = '';
584
631
  let params = '';
585
632
  let fullcommand = line.substring(parsedhead[12].from + offset, parsedhead[12].to + offset2).trim();
586
- if (fullcommand.substr(fullcommand.length - 1) === ']') { fullcommand = fullcommand.slice(0, -1); }
587
- if (fullcommand.substr(0, 1) === '[') { command = fullcommand.substring(1); }
588
- else {
633
+ if (fullcommand.substr(fullcommand.length - 1) === ']') {
634
+ fullcommand = fullcommand.slice(0, -1);
635
+ }
636
+ if (fullcommand.substr(0, 1) === '[') {
637
+ command = fullcommand.substring(1);
638
+ } else {
589
639
  const p1 = fullcommand.indexOf('(');
590
640
  const p2 = fullcommand.indexOf(')');
591
641
  const p3 = fullcommand.indexOf('/');
@@ -601,8 +651,8 @@ function processes(callback) {
601
651
  // try to figure out where parameter starts
602
652
  let firstParamPos = fullcommand.indexOf(' -');
603
653
  let firstParamPathPos = fullcommand.indexOf(' /');
604
- firstParamPos = (firstParamPos >= 0 ? firstParamPos : 10000);
605
- firstParamPathPos = (firstParamPathPos >= 0 ? firstParamPathPos : 10000);
654
+ firstParamPos = firstParamPos >= 0 ? firstParamPos : 10000;
655
+ firstParamPathPos = firstParamPathPos >= 0 ? firstParamPathPos : 10000;
606
656
  const firstPos = Math.min(firstParamPos, firstParamPathPos);
607
657
  let tmpCommand = fullcommand.substr(0, firstPos);
608
658
  const tmpParams = fullcommand.substr(firstPos);
@@ -627,10 +677,9 @@ function processes(callback) {
627
677
  }
628
678
  }
629
679
  }
630
-
631
680
  }
632
681
 
633
- return ({
682
+ return {
634
683
  pid: pid,
635
684
  parentPid: ppid,
636
685
  name: _linux ? getName(command) : command,
@@ -649,7 +698,7 @@ function processes(callback) {
649
698
  command: command,
650
699
  params: params,
651
700
  path: cmdPath
652
- });
701
+ };
653
702
  }
654
703
 
655
704
  function parseProcesses(lines) {
@@ -658,7 +707,7 @@ function processes(callback) {
658
707
  let head = lines[0];
659
708
  parsedhead = util.parseHead(head, 8);
660
709
  lines.shift();
661
- lines.forEach(function (line) {
710
+ lines.forEach((line) => {
662
711
  if (line.trim() !== '') {
663
712
  result.push(parseLine(line));
664
713
  }
@@ -667,7 +716,6 @@ function processes(callback) {
667
716
  return result;
668
717
  }
669
718
  function parseProcesses2(lines) {
670
-
671
719
  function formatDateTime(time) {
672
720
  const month = ('0' + (time.getMonth() + 1).toString()).slice(-2);
673
721
  const year = time.getFullYear().toString();
@@ -676,7 +724,7 @@ function processes(callback) {
676
724
  const mins = ('0' + time.getMinutes().toString()).slice(-2);
677
725
  const secs = ('0' + time.getSeconds().toString()).slice(-2);
678
726
 
679
- return (year + '-' + month + '-' + day + ' ' + hours + ':' + mins + ':' + secs);
727
+ return year + '-' + month + '-' + day + ' ' + hours + ':' + mins + ':' + secs;
680
728
  }
681
729
 
682
730
  function parseElapsed(etime) {
@@ -695,12 +743,12 @@ function processes(callback) {
695
743
  }
696
744
 
697
745
  let result = [];
698
- lines.forEach(function (line) {
746
+ lines.forEach((line) => {
699
747
  if (line.trim() !== '') {
700
748
  line = line.trim().replace(/ +/g, ' ').replace(/,+/g, '.');
701
749
  const parts = line.split(' ');
702
750
  const command = parts.slice(9).join(' ');
703
- const pmem = parseFloat((1.0 * parseInt(parts[3]) * 1024 / os.totalmem()).toFixed(1));
751
+ const pmem = parseFloat(((1.0 * parseInt(parts[3]) * 1024) / os.totalmem()).toFixed(1));
704
752
  const started = parseElapsed(parts[5]);
705
753
 
706
754
  result.push({
@@ -716,7 +764,22 @@ function processes(callback) {
716
764
  memRss: parseInt(parts[3]),
717
765
  nice: parseInt(parts[4]),
718
766
  started: started,
719
- state: (parts[6] === 'R' ? 'running' : (parts[6] === 'S' ? 'sleeping' : (parts[6] === 'T' ? 'stopped' : (parts[6] === 'W' ? 'paging' : (parts[6] === 'X' ? 'dead' : (parts[6] === 'Z' ? 'zombie' : ((parts[6] === 'D' || parts[6] === 'U') ? 'blocked' : 'unknown'))))))),
767
+ state:
768
+ parts[6] === 'R'
769
+ ? 'running'
770
+ : parts[6] === 'S'
771
+ ? 'sleeping'
772
+ : parts[6] === 'T'
773
+ ? 'stopped'
774
+ : parts[6] === 'W'
775
+ ? 'paging'
776
+ : parts[6] === 'X'
777
+ ? 'dead'
778
+ : parts[6] === 'Z'
779
+ ? 'zombie'
780
+ : parts[6] === 'D' || parts[6] === 'U'
781
+ ? 'blocked'
782
+ : 'unknown',
720
783
  tty: parts[7],
721
784
  user: parts[8],
722
785
  command: command
@@ -741,223 +804,265 @@ function processes(callback) {
741
804
 
742
805
  if ((_processes_cpu.ms && Date.now() - _processes_cpu.ms >= 500) || _processes_cpu.ms === 0) {
743
806
  if (_linux || _freebsd || _openbsd || _netbsd || _darwin || _sunos) {
744
- if (_linux) { cmd = 'export LC_ALL=C; ps -axo pid:11,ppid:11,pcpu:6,pmem:6,pri:5,vsz:11,rss:11,ni:5,etime:30,state:5,tty:15,user:20,command; unset LC_ALL'; }
745
- if (_freebsd || _openbsd || _netbsd) { cmd = 'export LC_ALL=C; ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,ni,etime,state,tty,user,command; unset LC_ALL'; }
746
- if (_darwin) { cmd = 'ps -axo pid,ppid,pcpu,pmem,pri,vsz=temp_title_1,rss=temp_title_2,nice,etime=temp_title_3,state,tty,user,command -r'; }
747
- if (_sunos) { cmd = 'ps -Ao pid,ppid,pcpu,pmem,pri,vsz,rss,nice,stime,s,tty,user,comm'; }
748
- exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) {
749
- if (!error && stdout.toString().trim()) {
750
- result.list = (parseProcesses(stdout.toString().split('\n'))).slice();
751
- result.all = result.list.length;
752
- result.running = result.list.filter(function (e) {
753
- return e.state === 'running';
754
- }).length;
755
- result.blocked = result.list.filter(function (e) {
756
- return e.state === 'blocked';
757
- }).length;
758
- result.sleeping = result.list.filter(function (e) {
759
- return e.state === 'sleeping';
760
- }).length;
807
+ if (_linux) {
808
+ cmd = 'export LC_ALL=C; ps -axo pid:11,ppid:11,pcpu:6,pmem:6,pri:5,vsz:11,rss:11,ni:5,etime:30,state:5,tty:15,user:20,command; unset LC_ALL';
809
+ }
810
+ if (_freebsd || _openbsd || _netbsd) {
811
+ cmd = 'export LC_ALL=C; ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,ni,etime,state,tty,user,command; unset LC_ALL';
812
+ }
813
+ if (_darwin) {
814
+ cmd = 'ps -axo pid,ppid,pcpu,pmem,pri,vsz=temp_title_1,rss=temp_title_2,nice,etime=temp_title_3,state,tty,user,command -r';
815
+ }
816
+ if (_sunos) {
817
+ cmd = 'ps -Ao pid,ppid,pcpu,pmem,pri,vsz,rss,nice,stime,s,tty,user,comm';
818
+ }
819
+ try {
820
+ exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
821
+ if (!error && stdout.toString().trim()) {
822
+ result.list = parseProcesses(stdout.toString().split('\n')).slice();
823
+ result.all = result.list.length;
824
+ result.running = result.list.filter((e) => {
825
+ return e.state === 'running';
826
+ }).length;
827
+ result.blocked = result.list.filter((e) => {
828
+ return e.state === 'blocked';
829
+ }).length;
830
+ result.sleeping = result.list.filter((e) => {
831
+ return e.state === 'sleeping';
832
+ }).length;
761
833
 
762
- if (_linux) {
763
- // calc process_cpu - ps is not accurate in linux!
764
- cmd = 'cat /proc/stat | grep "cpu "';
765
- result.list.forEach((element) => {
766
- cmd += (';cat /proc/' + element.pid + '/stat');
767
- });
768
- exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) {
769
- let curr_processes = stdout.toString().split('\n');
834
+ if (_linux) {
835
+ // calc process_cpu - ps is not accurate in linux!
836
+ cmd = 'cat /proc/stat | grep "cpu "';
837
+ result.list.forEach((element) => {
838
+ cmd += ';cat /proc/' + element.pid + '/stat';
839
+ });
840
+ exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
841
+ let curr_processes = stdout.toString().split('\n');
770
842
 
771
- // first line (all - /proc/stat)
772
- let all = parseProcStat(curr_processes.shift());
843
+ // first line (all - /proc/stat)
844
+ let all = parseProcStat(curr_processes.shift());
773
845
 
774
- // process
775
- let list_new = {};
776
- let resultProcess = {};
777
- curr_processes.forEach((element) => {
778
- resultProcess = calcProcStatLinux(element, all, _processes_cpu);
846
+ // process
847
+ let list_new = {};
848
+ let resultProcess = {};
849
+ curr_processes.forEach((element) => {
850
+ resultProcess = calcProcStatLinux(element, all, _processes_cpu);
779
851
 
780
- if (resultProcess.pid) {
852
+ if (resultProcess.pid) {
853
+ // store pcpu in outer array
854
+ let listPos = result.list
855
+ .map((e) => {
856
+ return e.pid;
857
+ })
858
+ .indexOf(resultProcess.pid);
859
+ if (listPos >= 0) {
860
+ result.list[listPos].cpu = resultProcess.cpuu + resultProcess.cpus;
861
+ result.list[listPos].cpuu = resultProcess.cpuu;
862
+ result.list[listPos].cpus = resultProcess.cpus;
863
+ }
781
864
 
782
- // store pcpu in outer array
783
- let listPos = result.list.map(function (e) { return e.pid; }).indexOf(resultProcess.pid);
784
- if (listPos >= 0) {
785
- result.list[listPos].cpu = resultProcess.cpuu + resultProcess.cpus;
786
- result.list[listPos].cpuu = resultProcess.cpuu;
787
- result.list[listPos].cpus = resultProcess.cpus;
865
+ // save new values
866
+ list_new[resultProcess.pid] = {
867
+ cpuu: resultProcess.cpuu,
868
+ cpus: resultProcess.cpus,
869
+ utime: resultProcess.utime,
870
+ stime: resultProcess.stime,
871
+ cutime: resultProcess.cutime,
872
+ cstime: resultProcess.cstime
873
+ };
788
874
  }
875
+ });
789
876
 
790
- // save new values
791
- list_new[resultProcess.pid] = {
792
- cpuu: resultProcess.cpuu,
793
- cpus: resultProcess.cpus,
794
- utime: resultProcess.utime,
795
- stime: resultProcess.stime,
796
- cutime: resultProcess.cutime,
797
- cstime: resultProcess.cstime
798
- };
877
+ // store old values
878
+ _processes_cpu.all = all;
879
+ _processes_cpu.list = Object.assign({}, list_new);
880
+ _processes_cpu.ms = Date.now() - _processes_cpu.ms;
881
+ _processes_cpu.result = Object.assign({}, result);
882
+ if (callback) {
883
+ callback(result);
799
884
  }
885
+ resolve(result);
800
886
  });
801
-
802
- // store old values
803
- _processes_cpu.all = all;
804
- _processes_cpu.list = Object.assign({}, list_new);
805
- _processes_cpu.ms = Date.now() - _processes_cpu.ms;
806
- _processes_cpu.result = Object.assign({}, result);
807
- if (callback) { callback(result); }
808
- resolve(result);
809
- });
810
- } else {
811
- if (callback) { callback(result); }
812
- resolve(result);
813
- }
814
- } else {
815
- cmd = 'ps -o pid,ppid,vsz,rss,nice,etime,stat,tty,user,comm';
816
- if (_sunos) {
817
- cmd = 'ps -o pid,ppid,vsz,rss,nice,etime,s,tty,user,comm';
818
- }
819
- exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) {
820
- if (!error) {
821
- let lines = stdout.toString().split('\n');
822
- lines.shift();
823
-
824
- result.list = parseProcesses2(lines).slice();
825
- result.all = result.list.length;
826
- result.running = result.list.filter(function (e) {
827
- return e.state === 'running';
828
- }).length;
829
- result.blocked = result.list.filter(function (e) {
830
- return e.state === 'blocked';
831
- }).length;
832
- result.sleeping = result.list.filter(function (e) {
833
- return e.state === 'sleeping';
834
- }).length;
835
- if (callback) { callback(result); }
836
- resolve(result);
837
887
  } else {
838
- if (callback) { callback(result); }
888
+ if (callback) {
889
+ callback(result);
890
+ }
839
891
  resolve(result);
840
892
  }
841
- });
893
+ } else {
894
+ cmd = 'ps -o pid,ppid,vsz,rss,nice,etime,stat,tty,user,comm';
895
+ if (_sunos) {
896
+ cmd = 'ps -o pid,ppid,vsz,rss,nice,etime,s,tty,user,comm';
897
+ }
898
+ exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
899
+ if (!error) {
900
+ let lines = stdout.toString().split('\n');
901
+ lines.shift();
902
+
903
+ result.list = parseProcesses2(lines).slice();
904
+ result.all = result.list.length;
905
+ result.running = result.list.filter((e) => {
906
+ return e.state === 'running';
907
+ }).length;
908
+ result.blocked = result.list.filter((e) => {
909
+ return e.state === 'blocked';
910
+ }).length;
911
+ result.sleeping = result.list.filter((e) => {
912
+ return e.state === 'sleeping';
913
+ }).length;
914
+ if (callback) {
915
+ callback(result);
916
+ }
917
+ resolve(result);
918
+ } else {
919
+ if (callback) {
920
+ callback(result);
921
+ }
922
+ resolve(result);
923
+ }
924
+ });
925
+ }
926
+ });
927
+ } catch {
928
+ if (callback) {
929
+ callback(result);
842
930
  }
843
- });
931
+ resolve(result);
932
+ }
844
933
  } else if (_windows) {
845
934
  try {
846
- util.powerShell('Get-CimInstance Win32_Process | select-Object ProcessId,ParentProcessId,ExecutionState,Caption,CommandLine,ExecutablePath,UserModeTime,KernelModeTime,WorkingSetSize,Priority,PageFileUsage, @{n="CreationDate";e={$_.CreationDate.ToString("yyyy-MM-dd HH:mm:ss")}} | fl').then((stdout, error) => {
847
- if (!error) {
848
- let processSections = stdout.split(/\n\s*\n/);
849
- let procs = [];
850
- let procStats = [];
851
- let list_new = {};
852
- let allcpuu = 0;
853
- let allcpus = 0;
854
- processSections.forEach((element) => {
855
- if (element.trim() !== '') {
856
- let lines = element.trim().split('\r\n');
857
- let pid = parseInt(util.getValue(lines, 'ProcessId', ':', true), 10);
858
- let parentPid = parseInt(util.getValue(lines, 'ParentProcessId', ':', true), 10);
859
- let statusValue = util.getValue(lines, 'ExecutionState', ':');
860
- let name = util.getValue(lines, 'Caption', ':', true);
861
- let commandLine = util.getValue(lines, 'CommandLine', ':', true);
862
- // get additional command line data
863
- let additionalCommand = false;
864
- lines.forEach((line) => {
865
- if (additionalCommand && line.toLowerCase().startsWith(' ')) {
866
- commandLine += ' ' + line.trim();
867
- } else {
868
- additionalCommand = false;
935
+ util
936
+ .powerShell(
937
+ 'Get-CimInstance Win32_Process | select-Object ProcessId,ParentProcessId,ExecutionState,Caption,CommandLine,ExecutablePath,UserModeTime,KernelModeTime,WorkingSetSize,Priority,PageFileUsage, @{n="CreationDate";e={$_.CreationDate.ToString("yyyy-MM-dd HH:mm:ss")}} | fl'
938
+ )
939
+ .then((stdout, error) => {
940
+ if (!error) {
941
+ let processSections = stdout.split(/\n\s*\n/);
942
+ let procs = [];
943
+ let procStats = [];
944
+ let list_new = {};
945
+ let allcpuu = 0;
946
+ let allcpus = 0;
947
+ processSections.forEach((element) => {
948
+ if (element.trim() !== '') {
949
+ let lines = element.trim().split('\r\n');
950
+ let pid = parseInt(util.getValue(lines, 'ProcessId', ':', true), 10);
951
+ let parentPid = parseInt(util.getValue(lines, 'ParentProcessId', ':', true), 10);
952
+ let statusValue = util.getValue(lines, 'ExecutionState', ':');
953
+ let name = util.getValue(lines, 'Caption', ':', true);
954
+ let commandLine = util.getValue(lines, 'CommandLine', ':', true);
955
+ // get additional command line data
956
+ let additionalCommand = false;
957
+ lines.forEach((line) => {
958
+ if (additionalCommand && line.toLowerCase().startsWith(' ')) {
959
+ commandLine += ' ' + line.trim();
960
+ } else {
961
+ additionalCommand = false;
962
+ }
963
+ if (line.toLowerCase().startsWith('commandline')) {
964
+ additionalCommand = true;
965
+ }
966
+ });
967
+ let commandPath = util.getValue(lines, 'ExecutablePath', ':', true);
968
+ let utime = parseInt(util.getValue(lines, 'UserModeTime', ':', true), 10);
969
+ let stime = parseInt(util.getValue(lines, 'KernelModeTime', ':', true), 10);
970
+ let memw = parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10);
971
+ allcpuu = allcpuu + utime;
972
+ allcpus = allcpus + stime;
973
+ result.all++;
974
+ if (!statusValue) {
975
+ result.unknown++;
869
976
  }
870
- if (line.toLowerCase().startsWith('commandline')) {
871
- additionalCommand = true;
977
+ if (statusValue === '3') {
978
+ result.running++;
979
+ }
980
+ if (statusValue === '4' || statusValue === '5') {
981
+ result.blocked++;
872
982
  }
873
- });
874
- let commandPath = util.getValue(lines, 'ExecutablePath', ':', true);
875
- let utime = parseInt(util.getValue(lines, 'UserModeTime', ':', true), 10);
876
- let stime = parseInt(util.getValue(lines, 'KernelModeTime', ':', true), 10);
877
- let memw = parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10);
878
- allcpuu = allcpuu + utime;
879
- allcpus = allcpus + stime;
880
- result.all++;
881
- if (!statusValue) { result.unknown++; }
882
- if (statusValue === '3') { result.running++; }
883
- if (statusValue === '4' || statusValue === '5') { result.blocked++; }
884
-
885
- procStats.push({
886
- pid: pid,
887
- utime: utime,
888
- stime: stime,
889
- cpu: 0,
890
- cpuu: 0,
891
- cpus: 0,
892
- });
893
- procs.push({
894
- pid: pid,
895
- parentPid: parentPid,
896
- name: name,
897
- cpu: 0,
898
- cpuu: 0,
899
- cpus: 0,
900
- mem: memw / os.totalmem() * 100,
901
- priority: parseInt(util.getValue(lines, 'Priority', ':', true), 10),
902
- memVsz: parseInt(util.getValue(lines, 'PageFileUsage', ':', true), 10),
903
- memRss: Math.floor(parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10) / 1024),
904
- nice: 0,
905
- started: util.getValue(lines, 'CreationDate', ':', true),
906
- state: (!statusValue ? _winStatusValues[0] : _winStatusValues[statusValue]),
907
- tty: '',
908
- user: '',
909
- command: commandLine || name,
910
- path: commandPath,
911
- params: ''
912
- });
913
- }
914
- });
915
983
 
916
- result.sleeping = result.all - result.running - result.blocked - result.unknown;
917
- result.list = procs;
918
- procStats.forEach((element) => {
919
- let resultProcess = calcProcStatWin(element, allcpuu + allcpus, _processes_cpu);
984
+ procStats.push({
985
+ pid: pid,
986
+ utime: utime,
987
+ stime: stime,
988
+ cpu: 0,
989
+ cpuu: 0,
990
+ cpus: 0
991
+ });
992
+ procs.push({
993
+ pid: pid,
994
+ parentPid: parentPid,
995
+ name: name,
996
+ cpu: 0,
997
+ cpuu: 0,
998
+ cpus: 0,
999
+ mem: (memw / os.totalmem()) * 100,
1000
+ priority: parseInt(util.getValue(lines, 'Priority', ':', true), 10),
1001
+ memVsz: parseInt(util.getValue(lines, 'PageFileUsage', ':', true), 10),
1002
+ memRss: Math.floor(parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10) / 1024),
1003
+ nice: 0,
1004
+ started: util.getValue(lines, 'CreationDate', ':', true),
1005
+ state: !statusValue ? _winStatusValues[0] : _winStatusValues[statusValue],
1006
+ tty: '',
1007
+ user: '',
1008
+ command: commandLine || name,
1009
+ path: commandPath,
1010
+ params: ''
1011
+ });
1012
+ }
1013
+ });
920
1014
 
921
- // store pcpu in outer array
922
- let listPos = result.list.map(function (e) { return e.pid; }).indexOf(resultProcess.pid);
923
- if (listPos >= 0) {
924
- result.list[listPos].cpu = resultProcess.cpuu + resultProcess.cpus;
925
- result.list[listPos].cpuu = resultProcess.cpuu;
926
- result.list[listPos].cpus = resultProcess.cpus;
927
- }
1015
+ result.sleeping = result.all - result.running - result.blocked - result.unknown;
1016
+ result.list = procs;
1017
+ procStats.forEach((element) => {
1018
+ let resultProcess = calcProcStatWin(element, allcpuu + allcpus, _processes_cpu);
1019
+
1020
+ // store pcpu in outer array
1021
+ let listPos = result.list.map((e) => e.pid).indexOf(resultProcess.pid);
1022
+ if (listPos >= 0) {
1023
+ result.list[listPos].cpu = resultProcess.cpuu + resultProcess.cpus;
1024
+ result.list[listPos].cpuu = resultProcess.cpuu;
1025
+ result.list[listPos].cpus = resultProcess.cpus;
1026
+ }
928
1027
 
929
- // save new values
930
- list_new[resultProcess.pid] = {
931
- cpuu: resultProcess.cpuu,
932
- cpus: resultProcess.cpus,
933
- utime: resultProcess.utime,
934
- stime: resultProcess.stime
935
- };
936
- });
1028
+ // save new values
1029
+ list_new[resultProcess.pid] = {
1030
+ cpuu: resultProcess.cpuu,
1031
+ cpus: resultProcess.cpus,
1032
+ utime: resultProcess.utime,
1033
+ stime: resultProcess.stime
1034
+ };
1035
+ });
937
1036
 
938
- // store old values
939
- _processes_cpu.all = allcpuu + allcpus;
940
- _processes_cpu.all_utime = allcpuu;
941
- _processes_cpu.all_stime = allcpus;
942
- _processes_cpu.list = Object.assign({}, list_new);
943
- _processes_cpu.ms = Date.now() - _processes_cpu.ms;
944
- _processes_cpu.result = Object.assign({}, result);
945
- }
946
- if (callback) {
947
- callback(result);
948
- }
949
- resolve(result);
950
- });
951
- } catch (e) {
952
- if (callback) { callback(result); }
1037
+ // store old values
1038
+ _processes_cpu.all = allcpuu + allcpus;
1039
+ _processes_cpu.all_utime = allcpuu;
1040
+ _processes_cpu.all_stime = allcpus;
1041
+ _processes_cpu.list = Object.assign({}, list_new);
1042
+ _processes_cpu.ms = Date.now() - _processes_cpu.ms;
1043
+ _processes_cpu.result = Object.assign({}, result);
1044
+ }
1045
+ if (callback) {
1046
+ callback(result);
1047
+ }
1048
+ resolve(result);
1049
+ });
1050
+ } catch {
1051
+ if (callback) {
1052
+ callback(result);
1053
+ }
953
1054
  resolve(result);
954
1055
  }
955
1056
  } else {
956
- if (callback) { callback(result); }
1057
+ if (callback) {
1058
+ callback(result);
1059
+ }
957
1060
  resolve(result);
958
1061
  }
959
1062
  } else {
960
- if (callback) { callback(_processes_cpu.result); }
1063
+ if (callback) {
1064
+ callback(_processes_cpu.result);
1065
+ }
961
1066
  resolve(_processes_cpu.result);
962
1067
  }
963
1068
  });
@@ -972,7 +1077,6 @@ exports.processes = processes;
972
1077
  // (PID, CPU-Usage %, Mem-Usage %)
973
1078
 
974
1079
  function processLoad(proc, callback) {
975
-
976
1080
  // fallback - if only callback is given
977
1081
  if (util.isFunction(proc) && !callback) {
978
1082
  callback = proc;
@@ -981,11 +1085,12 @@ function processLoad(proc, callback) {
981
1085
 
982
1086
  return new Promise((resolve) => {
983
1087
  process.nextTick(() => {
984
-
985
1088
  proc = proc || '';
986
1089
 
987
1090
  if (typeof proc !== 'string') {
988
- if (callback) { callback([]); }
1091
+ if (callback) {
1092
+ callback([]);
1093
+ }
989
1094
  return resolve([]);
990
1095
  }
991
1096
 
@@ -998,8 +1103,7 @@ function processLoad(proc, callback) {
998
1103
  processesString.__proto__.substring = util.stringSubstring;
999
1104
  processesString.__proto__.trim = util.stringTrim;
1000
1105
  processesString.__proto__.startsWith = util.stringStartWith;
1001
-
1002
- } catch (e) {
1106
+ } catch {
1003
1107
  Object.setPrototypeOf(processesString, util.stringObj);
1004
1108
  }
1005
1109
 
@@ -1022,7 +1126,7 @@ function processLoad(proc, callback) {
1022
1126
  let processes = processesString.split('|');
1023
1127
  let result = [];
1024
1128
 
1025
- const procSanitized = util.isPrototypePolluted() ? '' : (util.sanitizeShellString(proc) || '*');
1129
+ const procSanitized = util.isPrototypePolluted() ? '' : util.sanitizeShellString(proc) || '*';
1026
1130
 
1027
1131
  // from here new
1028
1132
  // let result = {
@@ -1066,7 +1170,7 @@ function processLoad(proc, callback) {
1066
1170
  });
1067
1171
  let pname = '';
1068
1172
  let inList = false;
1069
- processes.forEach(function (proc) {
1173
+ processes.forEach((proc) => {
1070
1174
  if (name.toLowerCase().indexOf(proc.toLowerCase()) >= 0 && !inList) {
1071
1175
  inList = true;
1072
1176
  pname = proc;
@@ -1075,10 +1179,10 @@ function processLoad(proc, callback) {
1075
1179
 
1076
1180
  if (processesString === '*' || inList) {
1077
1181
  let processFound = false;
1078
- result.forEach(function (item) {
1182
+ result.forEach((item) => {
1079
1183
  if (item.proc.toLowerCase() === pname.toLowerCase()) {
1080
1184
  item.pids.push(pid);
1081
- item.mem += mem / os.totalmem() * 100;
1185
+ item.mem += (mem / os.totalmem()) * 100;
1082
1186
  processFound = true;
1083
1187
  }
1084
1188
  });
@@ -1088,7 +1192,7 @@ function processLoad(proc, callback) {
1088
1192
  pid: pid,
1089
1193
  pids: [pid],
1090
1194
  cpu: 0,
1091
- mem: mem / os.totalmem() * 100
1195
+ mem: (mem / os.totalmem()) * 100
1092
1196
  });
1093
1197
  }
1094
1198
  }
@@ -1097,11 +1201,8 @@ function processLoad(proc, callback) {
1097
1201
 
1098
1202
  // add missing processes
1099
1203
  if (processesString !== '*') {
1100
- let processesMissing = processes.filter(function (name) {
1101
- return procStats.filter(function (item) { return item.name.toLowerCase().indexOf(name) >= 0; }).length === 0;
1102
-
1103
- });
1104
- processesMissing.forEach(function (procName) {
1204
+ let processesMissing = processes.filter((name) => procStats.filter((item) => item.name.toLowerCase().indexOf(name) >= 0).length === 0);
1205
+ processesMissing.forEach((procName) => {
1105
1206
  result.push({
1106
1207
  proc: procName,
1107
1208
  pid: null,
@@ -1118,7 +1219,9 @@ function processLoad(proc, callback) {
1118
1219
 
1119
1220
  let listPos = -1;
1120
1221
  for (let j = 0; j < result.length; j++) {
1121
- if (result[j].pid === resultProcess.pid || result[j].pids.indexOf(resultProcess.pid) >= 0) { listPos = j; }
1222
+ if (result[j].pid === resultProcess.pid || result[j].pids.indexOf(resultProcess.pid) >= 0) {
1223
+ listPos = j;
1224
+ }
1122
1225
  }
1123
1226
  if (listPos >= 0) {
1124
1227
  result[listPos].cpu += resultProcess.cpuu + resultProcess.cpus;
@@ -1147,7 +1250,9 @@ function processLoad(proc, callback) {
1147
1250
  }
1148
1251
  });
1149
1252
  } catch (e) {
1150
- if (callback) { callback(result); }
1253
+ if (callback) {
1254
+ callback(result);
1255
+ }
1151
1256
  resolve(result);
1152
1257
  }
1153
1258
  }
@@ -1156,22 +1261,29 @@ function processLoad(proc, callback) {
1156
1261
  const params = ['-axo', 'pid,ppid,pcpu,pmem,comm'];
1157
1262
  util.execSafe('ps', params).then((stdout) => {
1158
1263
  if (stdout) {
1159
- let procStats = [];
1160
- let lines = stdout.toString().split('\n').filter(function (line) {
1161
- if (processesString === '*') { return true; }
1162
- if (line.toLowerCase().indexOf('grep') !== -1) { return false; } // remove this??
1163
- let found = false;
1164
- processes.forEach(function (item) {
1165
- found = found || (line.toLowerCase().indexOf(item.toLowerCase()) >= 0);
1264
+ const procStats = [];
1265
+ const lines = stdout
1266
+ .toString()
1267
+ .split('\n')
1268
+ .filter((line) => {
1269
+ if (processesString === '*') {
1270
+ return true;
1271
+ }
1272
+ if (line.toLowerCase().indexOf('grep') !== -1) {
1273
+ return false;
1274
+ } // remove this??
1275
+ let found = false;
1276
+ processes.forEach((item) => {
1277
+ found = found || line.toLowerCase().indexOf(item.toLowerCase()) >= 0;
1278
+ });
1279
+ return found;
1166
1280
  });
1167
- return found;
1168
- });
1169
1281
  lines.shift();
1170
- lines.forEach(function (line) {
1171
- let data = line.trim().replace(/ +/g, ' ').split(' ');
1282
+ lines.forEach((line) => {
1283
+ const data = line.trim().replace(/ +/g, ' ').split(' ');
1172
1284
  if (data.length > 4) {
1173
1285
  const linuxName = data[4].indexOf('/') >= 0 ? data[4].substring(0, data[4].indexOf('/')) : data[4];
1174
- const name = _linux ? (linuxName) : data[4].substring(data[4].lastIndexOf('/') + 1);
1286
+ const name = _linux ? linuxName : data[4].substring(data[4].lastIndexOf('/') + 1);
1175
1287
  procStats.push({
1176
1288
  name,
1177
1289
  pid: parseInt(data[0]) || 0,
@@ -1182,7 +1294,7 @@ function processLoad(proc, callback) {
1182
1294
  }
1183
1295
  });
1184
1296
 
1185
- procStats.forEach(function (item) {
1297
+ procStats.forEach((item) => {
1186
1298
  let listPos = -1;
1187
1299
  let inList = false;
1188
1300
  let name = item.name;
@@ -1191,14 +1303,13 @@ function processLoad(proc, callback) {
1191
1303
  listPos = j;
1192
1304
  }
1193
1305
  }
1194
- processes.forEach(function (proc) {
1195
-
1306
+ processes.forEach((proc) => {
1196
1307
  if (item.name.toLowerCase().indexOf(proc.toLowerCase()) >= 0 && !inList) {
1197
1308
  inList = true;
1198
1309
  name = proc;
1199
1310
  }
1200
1311
  });
1201
- if ((processesString === '*') || inList) {
1312
+ if (processesString === '*' || inList) {
1202
1313
  if (listPos < 0) {
1203
1314
  if (name) {
1204
1315
  result.push({
@@ -1222,10 +1333,14 @@ function processLoad(proc, callback) {
1222
1333
 
1223
1334
  if (processesString !== '*') {
1224
1335
  // add missing processes
1225
- let processesMissing = processes.filter(function (name) {
1226
- return procStats.filter(function (item) { return item.name.toLowerCase().indexOf(name) >= 0; }).length === 0;
1336
+ let processesMissing = processes.filter((name) => {
1337
+ return (
1338
+ procStats.filter((item) => {
1339
+ return item.name.toLowerCase().indexOf(name) >= 0;
1340
+ }).length === 0
1341
+ );
1227
1342
  });
1228
- processesMissing.forEach(function (procName) {
1343
+ processesMissing.forEach((procName) => {
1229
1344
  result.push({
1230
1345
  proc: procName,
1231
1346
  pid: null,
@@ -1237,16 +1352,16 @@ function processLoad(proc, callback) {
1237
1352
  }
1238
1353
  if (_linux) {
1239
1354
  // calc process_cpu - ps is not accurate in linux!
1240
- result.forEach(function (item) {
1355
+ result.forEach((item) => {
1241
1356
  item.cpu = 0;
1242
1357
  });
1243
1358
  let cmd = 'cat /proc/stat | grep "cpu "';
1244
1359
  for (let i in result) {
1245
1360
  for (let j in result[i].pids) {
1246
- cmd += (';cat /proc/' + result[i].pids[j] + '/stat');
1361
+ cmd += ';cat /proc/' + result[i].pids[j] + '/stat';
1247
1362
  }
1248
1363
  }
1249
- exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) {
1364
+ exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
1250
1365
  let curr_processes = stdout.toString().split('\n');
1251
1366
 
1252
1367
  // first line (all - /proc/stat)
@@ -1259,7 +1374,6 @@ function processLoad(proc, callback) {
1259
1374
  resultProcess = calcProcStatLinux(element, all, _process_cpu);
1260
1375
 
1261
1376
  if (resultProcess.pid) {
1262
-
1263
1377
  // find result item
1264
1378
  let resultItemId = -1;
1265
1379
  for (let i in result) {
@@ -1284,7 +1398,7 @@ function processLoad(proc, callback) {
1284
1398
  }
1285
1399
  });
1286
1400
 
1287
- result.forEach(function (item) {
1401
+ result.forEach((item) => {
1288
1402
  item.cpu = Math.round(item.cpu * 100) / 100;
1289
1403
  });
1290
1404
 
@@ -1292,15 +1406,21 @@ function processLoad(proc, callback) {
1292
1406
  _process_cpu.list = Object.assign({}, list_new);
1293
1407
  _process_cpu.ms = Date.now() - _process_cpu.ms;
1294
1408
  _process_cpu.result = Object.assign({}, result);
1295
- if (callback) { callback(result); }
1409
+ if (callback) {
1410
+ callback(result);
1411
+ }
1296
1412
  resolve(result);
1297
1413
  });
1298
1414
  } else {
1299
- if (callback) { callback(result); }
1415
+ if (callback) {
1416
+ callback(result);
1417
+ }
1300
1418
  resolve(result);
1301
1419
  }
1302
1420
  } else {
1303
- if (callback) { callback(result); }
1421
+ if (callback) {
1422
+ callback(result);
1423
+ }
1304
1424
  resolve(result);
1305
1425
  }
1306
1426
  });