systeminformation 5.11.19 → 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.
package/lib/filesystem.js CHANGED
@@ -49,12 +49,17 @@ function fsSize(callback) {
49
49
  return 'HFS';
50
50
  }
51
51
 
52
+ function isLinuxTmpFs(fs) {
53
+ const linuxTmpFileSystems = ['rootfs', 'unionfs', 'squashfs', 'cramfs', 'initrd', 'initramfs', 'devtmpfs', 'tmpfs', 'udev', 'devfs', 'specfs', 'type'];
54
+ return (linuxTmpFileSystems.includes(fs.toLowerCase()));
55
+ }
56
+
52
57
  function parseDf(lines) {
53
58
  let data = [];
54
59
  lines.forEach(function (line) {
55
60
  if (line !== '') {
56
61
  line = line.replace(/ +/g, ' ').split(' ');
57
- if (line && ((line[0].startsWith('/')) || (line[6] && line[6] === '/') || (line[0].indexOf('/') > 0) || (line[0].indexOf(':') === 1))) {
62
+ if (line && ((line[0].startsWith('/')) || (line[6] && line[6] === '/') || (line[0].indexOf('/') > 0) || (line[0].indexOf(':') === 1) || !_darwin && !isLinuxTmpFs(line[1]))) {
58
63
  const fs = line[0];
59
64
  const fsType = ((_linux || _freebsd || _openbsd || _netbsd) ? line[1] : getmacOsFsType(line[0]));
60
65
  const size = parseInt(((_linux || _freebsd || _openbsd || _netbsd) ? line[2] : line[1])) * 1024;
@@ -96,11 +101,12 @@ function fsSize(callback) {
96
101
  macOsDisks = [];
97
102
  }
98
103
  }
99
- if (_linux) { cmd = 'df -lkPTx squashfs | grep -E "^/|^.\\:"'; }
104
+ if (_linux) { cmd = 'df -lkPTx squashfs'; } // cmd = 'df -lkPTx squashfs | grep -E "^/|^.\\:"';
100
105
  if (_freebsd || _openbsd || _netbsd) { cmd = 'df -lkPT'; }
101
106
  exec(cmd, { maxBuffer: 1024 * 1024 }, function (error, stdout) {
102
107
  if (!error) {
103
108
  let lines = stdout.toString().split('\n');
109
+ if (lines && lines[0] && lines[0].toLowerCase().startsWith('filesystem')) { lines.shift(); }
104
110
  data = parseDf(lines);
105
111
  if (callback) {
106
112
  callback(data);
@@ -110,6 +116,7 @@ function fsSize(callback) {
110
116
  exec('df -kPT', { maxBuffer: 1024 * 1024 }, function (error, stdout) {
111
117
  if (!error) {
112
118
  let lines = stdout.toString().split('\n');
119
+ if (lines && lines[0] && lines[0].toLowerCase().startsWith('filesystem')) { lines.shift(); }
113
120
  data = parseDf(lines);
114
121
  }
115
122
  if (callback) {
@@ -852,7 +859,7 @@ function diskLayout(callback) {
852
859
  try {
853
860
  const outJSON = JSON.parse(out);
854
861
  if (outJSON && {}.hasOwnProperty.call(outJSON, 'blockdevices')) {
855
- devices = outJSON.blockdevices.filter(item => { return (item.type === 'disk') && item.size > 0 && (item.model !== null || (item.mountpoint === null && item.label === null && item.fsType === null && item.parttype === null && item.path && item.path.indexOf('/ram') !== 0 && item.path.indexOf('/loop') !== 0 && item['disc-max'] && item['disc-max'] !== 0)); });
862
+ devices = outJSON.blockdevices.filter(item => { return (item.type === 'disk') && item.size > 0 && (item.model !== null || (item.mountpoint === null && item.label === null && item.fstype === null && item.parttype === null && item.path && item.path.indexOf('/ram') !== 0 && item.path.indexOf('/loop') !== 0 && item['disc-max'] && item['disc-max'] !== 0)); });
856
863
  }
857
864
  } catch (e) {
858
865
  // fallback to older version of lsblk
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.19",
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)",