systeminformation 5.11.21 → 5.11.22

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.
Files changed (2) hide show
  1. package/lib/processes.js +62 -28
  2. package/package.json +1 -1
package/lib/processes.js CHANGED
@@ -88,6 +88,25 @@ function parseTimeUnix(time) {
88
88
  return result;
89
89
  }
90
90
 
91
+ function parseElapsedTime(etime) {
92
+ let current = new Date();
93
+ current = new Date(current.getTime() - current.getTimezoneOffset() * 60000);
94
+
95
+ const elapsed = etime.split('-');
96
+
97
+ const timeIndex = elapsed.length - 1;
98
+ const days = timeIndex > 0 ? parseInt(elapsed[timeIndex - 1]) : 0;
99
+
100
+ const timeStr = elapsed[timeIndex].split(':');
101
+ const hours = timeStr.length === 3 ? parseInt(timeStr[0] || 0) : 0;
102
+ const mins = parseInt(timeStr[timeStr.length === 3 ? 1 : 0] || 0);
103
+ const secs = parseInt(timeStr[timeStr.length === 3 ? 2 : 1] || 0);
104
+ const ms = (((((days * 24 + hours) * 60) + mins) * 60 + secs) * 1000);
105
+
106
+ const res = new Date(current.getTime() - ms);
107
+ return res.toISOString().substring(0, 10) + ' ' + res.toISOString().substring(11, 19);
108
+ }
109
+
91
110
  // --------------------------
92
111
  // PS - services
93
112
  // pass a comma separated string with services to check (mysql, apache, postgresql, ...)
@@ -550,7 +569,7 @@ function processes(callback) {
550
569
  checkColumn(7);
551
570
  const nice = parseInt(line.substring(parsedhead[7].from + offset, parsedhead[7].to + offset2)) || 0;
552
571
  checkColumn(8);
553
- const started = parseTimeUnix(line.substring(parsedhead[8].from + offset, parsedhead[8].to + offset2).trim());
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());
554
573
  checkColumn(9);
555
574
  let state = line.substring(parsedhead[9].from + offset, parsedhead[9].to + offset2).trim();
556
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')))))));
@@ -567,33 +586,48 @@ function processes(callback) {
567
586
  if (fullcommand.substr(fullcommand.length - 1) === ']') { fullcommand = fullcommand.slice(0, -1); }
568
587
  if (fullcommand.substr(0, 1) === '[') { command = fullcommand.substring(1); }
569
588
  else {
570
- // try to figure out where parameter starts
571
- let firstParamPos = fullcommand.indexOf(' -');
572
- let firstParamPathPos = fullcommand.indexOf(' /');
573
- firstParamPos = (firstParamPos >= 0 ? firstParamPos : 10000);
574
- firstParamPathPos = (firstParamPathPos >= 0 ? firstParamPathPos : 10000);
575
- const firstPos = Math.min(firstParamPos, firstParamPathPos);
576
- let tmpCommand = fullcommand.substr(0, firstPos);
577
- const tmpParams = fullcommand.substr(firstPos);
578
- const lastSlashPos = tmpCommand.lastIndexOf('/');
579
- if (lastSlashPos >= 0) {
580
- cmdPath = tmpCommand.substr(0, lastSlashPos);
581
- tmpCommand = tmpCommand.substr(lastSlashPos + 1);
582
- }
583
-
584
- if (firstPos === 10000 && tmpCommand.indexOf(' ') > -1) {
585
- const parts = tmpCommand.split(' ');
586
- if (fs.existsSync(path.join(cmdPath, parts[0]))) {
587
- command = parts.shift();
588
- params = (parts.join(' ') + ' ' + tmpParams).trim();
589
+ const p1 = fullcommand.indexOf('(');
590
+ const p2 = fullcommand.indexOf(')');
591
+ const p3 = fullcommand.indexOf('/');
592
+ const p4 = fullcommand.indexOf(':');
593
+ if (p1 < p2 && p1 < p3 && p3 < p2) {
594
+ command = fullcommand.split(' ')[0];
595
+ command = command.replace(/:/g, '');
596
+ } else {
597
+ if (p4 > 0 && (p3 === -1 || p3 > 3)) {
598
+ command = fullcommand.split(' ')[0];
599
+ command = command.replace(/:/g, '');
589
600
  } else {
590
- command = tmpCommand.trim();
591
- params = tmpParams.trim();
601
+ // try to figure out where parameter starts
602
+ let firstParamPos = fullcommand.indexOf(' -');
603
+ let firstParamPathPos = fullcommand.indexOf(' /');
604
+ firstParamPos = (firstParamPos >= 0 ? firstParamPos : 10000);
605
+ firstParamPathPos = (firstParamPathPos >= 0 ? firstParamPathPos : 10000);
606
+ const firstPos = Math.min(firstParamPos, firstParamPathPos);
607
+ let tmpCommand = fullcommand.substr(0, firstPos);
608
+ const tmpParams = fullcommand.substr(firstPos);
609
+ const lastSlashPos = tmpCommand.lastIndexOf('/');
610
+ if (lastSlashPos >= 0) {
611
+ cmdPath = tmpCommand.substr(0, lastSlashPos);
612
+ tmpCommand = tmpCommand.substr(lastSlashPos + 1);
613
+ }
614
+
615
+ if (firstPos === 10000 && tmpCommand.indexOf(' ') > -1) {
616
+ const parts = tmpCommand.split(' ');
617
+ if (fs.existsSync(path.join(cmdPath, parts[0]))) {
618
+ command = parts.shift();
619
+ params = (parts.join(' ') + ' ' + tmpParams).trim();
620
+ } else {
621
+ command = tmpCommand.trim();
622
+ params = tmpParams.trim();
623
+ }
624
+ } else {
625
+ command = tmpCommand.trim();
626
+ params = tmpParams.trim();
627
+ }
592
628
  }
593
- } else {
594
- command = tmpCommand.trim();
595
- params = tmpParams.trim();
596
629
  }
630
+
597
631
  }
598
632
 
599
633
  return ({
@@ -693,9 +727,9 @@ function processes(callback) {
693
727
 
694
728
  if ((_processes_cpu.ms && Date.now() - _processes_cpu.ms >= 500) || _processes_cpu.ms === 0) {
695
729
  if (_linux || _freebsd || _openbsd || _netbsd || _darwin || _sunos) {
696
- 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,lstart:30,state:5,tty:15,user:20,command; unset LC_ALL'; }
697
- if (_freebsd || _openbsd || _netbsd) { cmd = 'export LC_ALL=C; ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,ni,lstart,state,tty,user,command; unset LC_ALL'; }
698
- if (_darwin) { cmd = 'ps -axo pid,ppid,pcpu,pmem,pri,vsz=xxx_fake_title,rss=fake_title2,nice,lstart,state,tty,user,command -r'; }
730
+ 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'; }
731
+ 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'; }
732
+ 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'; }
699
733
  if (_sunos) { cmd = 'ps -Ao pid,ppid,pcpu,pmem,pri,vsz,rss,nice,stime,s,tty,user,comm'; }
700
734
  exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) {
701
735
  if (!error && stdout.toString().trim()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "5.11.21",
3
+ "version": "5.11.22",
4
4
  "description": "Advanced, lightweight system and OS information library",
5
5
  "license": "MIT",
6
6
  "author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",