From 06da4917bbdec3fd497020676cae6eaa69de02fe Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Sat, 6 Feb 2021 11:26:51 +0100 Subject: [PATCH] getDynamicData() fixed windows WSL issue --- CHANGELOG.md | 1 + docs/history.html | 5 +++++ docs/index.html | 2 +- lib/filesystem.js | 21 +++++++++++++++++---- lib/processes.js | 10 ++++++---- lib/system.js | 10 ++++++++++ lib/wifi.js | 5 +++++ test/si.js | 8 ++++---- 8 files changed, 49 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a252b64..90c4cd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 5.0.10 | 2020-02-06 | `getDynamicData()` fixed windows WSL issue | | 5.0.9 | 2020-02-02 | `fsSize()` fixed parsing edge case issue mac OS | | 5.0.8 | 2020-01-30 | typescript typings fix cpuCurrentSpeed | | 5.0.7 | 2020-01-29 | `fsSize()` available fixed windows and typescript typings | diff --git a/docs/history.html b/docs/history.html index d016bf5..eceddd8 100644 --- a/docs/history.html +++ b/docs/history.html @@ -56,6 +56,11 @@ + + 5.0.10 + 2020-02-06 + getDynamicData() windows WSL fix + 5.0.9 2020-02-02 diff --git a/docs/index.html b/docs/index.html index 3c236fb..4406986 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
 
-
New Version: 5.0.9
+
New Version: 5.0.10
diff --git a/lib/filesystem.js b/lib/filesystem.js index 676dc81..291918c 100755 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -196,11 +196,24 @@ function fsOpenFiles(callback) { if (!result.available) { result.available = result.max - result.allocated; } } } + if (callback) { + callback(result); + } + resolve(result); + } else { + fs.readFile('/proc/sys/fs/file-max', function (error, stdout) { + if (!error) { + let lines = stdout.toString().split('\n'); + if (lines[0]) { + result.max = parseInt(lines[0], 10); + } + } + if (callback) { + callback(result); + } + resolve(result); + }); } - if (callback) { - callback(result); - } - resolve(result); }); } if (_sunos) { diff --git a/lib/processes.js b/lib/processes.js index 1defb3e..35fe94b 100644 --- a/lib/processes.js +++ b/lib/processes.js @@ -186,7 +186,7 @@ function services(srv, callback) { } result.push({ name: srv, -// running: (allSrv.length && singleSrv.length && singleSrv[0].running !== null ? singleSrv[0].running : ps.length > 0), + // running: (allSrv.length && singleSrv.length && singleSrv[0].running !== null ? singleSrv[0].running : ps.length > 0), running: ps.length > 0, startmode: '', pids: pids, @@ -305,10 +305,11 @@ function services(srv, callback) { if (serviceSections[i].trim() !== '') { let lines = serviceSections[i].trim().split('\r\n'); let srvName = util.getValue(lines, 'Name', '=', true).toLowerCase(); + let srvCaption = util.getValue(lines, 'Caption', '=', true).toLowerCase(); let started = util.getValue(lines, 'Started', '=', true); let startMode = util.getValue(lines, 'StartMode', '=', true); let pid = util.getValue(lines, 'ProcessId', '=', true); - if (srvString === '*' || srvs.indexOf(srvName) >= 0) { + if (srvString === '*' || srvs.indexOf(srvName) >= 0 || srvs.indexOf(srvCaption) >= 0) { result.push({ name: srvName, running: (started === 'TRUE'), @@ -318,6 +319,7 @@ function services(srv, callback) { mem: 0 }); dataSrv.push(srvName); + dataSrv.push(srvCaption); } } } @@ -358,8 +360,8 @@ function services(srv, callback) { } } } else { - if (callback) { callback({}); } - resolve({}); + if (callback) { callback([]); } + resolve([]); } }); }); diff --git a/lib/system.js b/lib/system.js index 8d1db6a..ab10641 100644 --- a/lib/system.js +++ b/lib/system.js @@ -16,6 +16,7 @@ const exec = require('child_process').exec; const execSync = require('child_process').execSync; const fs = require('fs'); +const os = require('os'); const util = require('./util'); let _platform = process.platform; @@ -120,6 +121,15 @@ function system(callback) { util.noop(); } } + if (!result.virtual && os.version().toLowerCase().indexOf('microsoft') >= 0) { + let versionStr = os.version().toLowerCase(); + versionStr = versionStr.split('-')[0].replace('#', ''); + const version = parseInt(versionStr, 10) || null; + result.virtual = true; + result.manufacturer = 'Microsoft'; + result.model = 'WSL'; + result.version = version; + } if ((_freebsd || _openbsd || _netbsd) && !result.virtualHost) { try { const procInfo = execSync('dmidecode -t 4'); diff --git a/lib/wifi.js b/lib/wifi.js index b76d3ad..bec0888 100644 --- a/lib/wifi.js +++ b/lib/wifi.js @@ -251,6 +251,11 @@ function wifiNetworks(callback) { } resolve(result); } + } else { + if (callback) { + callback(result); + } + resolve(result); } } catch (e) { if (callback) { diff --git a/test/si.js b/test/si.js index 6972961..0151d62 100644 --- a/test/si.js +++ b/test/si.js @@ -27,9 +27,9 @@ function test(f) { else if (f === 'M') { si.memLayout().then(data => { if (data !== null) { resolve({ data, title: 'Memory Layout' }); } else { resolve('not_supported'); } }); } else if (f === 'o') { si.osInfo().then(data => { if (data !== null) { resolve({ data, title: 'OS Info' }); } else { resolve('not_supported'); } }); } else if (f === 'p') { si.processes().then(data => { if (data !== null) { resolve({ data, title: 'Processes' }); } else { resolve('not_supported'); } }); } - else if (f === 'P') { si.processLoad('postgres, login, apache, mysql, nginx, git').then(data => { if (data !== null) { resolve({ data, title: 'Process Load' }); } else { resolve('not_supported'); } }); } + else if (f === 'P') { si.processLoad('postgres, login, apache, mysql, nginx, git, node').then(data => { if (data !== null) { resolve({ data, title: 'Process Load' }); } else { resolve('not_supported'); } }); } else if (f === 'r') { si.printer().then(data => { if (data !== null) { resolve({ data, title: 'Printer' }); } else { resolve('not_supported'); } }); } - else if (f === 's') { si.services('apache2, postgres').then(data => { if (data !== null) { resolve({ data, title: 'Services' }); } else { resolve('not_supported'); } }); } + else if (f === 's') { si.services('apache2, postgres, wsearch').then(data => { if (data !== null) { resolve({ data, title: 'Services' }); } else { resolve('not_supported'); } }); } else if (f === 'S') { si.shell().then(data => { if (data !== null) { resolve({ data, title: 'Shell' }); } else { resolve('not_supported'); } }); } else if (f === 't') { resolve({ data: si.time(), title: 'Time' }); } else if (f === 'T') { si.cpuTemperature().then(data => { if (data !== null) { resolve({ data, title: 'CPU Temperature' }); } else { resolve('not_supported'); } }); } @@ -52,8 +52,8 @@ function test(f) { else if (f === '9') { si.dockerContainerProcesses('1').then(data => { if (data !== null) { resolve({ data, title: 'Docker Cont Processes' }); } else { resolve('not_supported'); } }); } else if (f === '0') { si.dockerAll().then(data => { if (data !== null) { resolve({ data, title: 'Docker All' }); } else { resolve('not_supported'); } }); } else if (f === ',') { si.getStaticData().then(data => { if (data !== null) { resolve({ data, title: 'All Static Data' }); } else { resolve('not_supported'); } }); } - else if (f === '.') { si.getDynamicData('apache2, postgres').then(data => { if (data !== null) { resolve({ data, title: 'All Dynamic Data' }); } else { resolve('not_supported'); } }); } - else if (f === '/') { si.getAllData('apache2, postgres').then(data => { if (data !== null) { resolve({ data, title: 'All Data' }); } else { resolve('not_supported'); } }); } + else if (f === '.') { si.getDynamicData('apache2, postgres, wsearch').then(data => { if (data !== null) { resolve({ data, title: 'All Dynamic Data' }); } else { resolve('not_supported'); } }); } + else if (f === '/') { si.getAllData('apache2, postgres, wsearch').then(data => { if (data !== null) { resolve({ data, title: 'All Data' }); } else { resolve('not_supported'); } }); } else if (f === '?') { const valueObject = { cpu: '*',