diff --git a/lib/cpu.js b/lib/cpu.js index ec346c1..4b3014f 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -597,7 +597,7 @@ function getCpu() { if (_linux) { let modelline = ''; let lines = []; - if (os.cpus()[0] && os.cpus()[0].model) modelline = os.cpus()[0].model; + if (os.cpus()[0] && os.cpus()[0].model) { modelline = os.cpus()[0].model; } exec('export LC_ALL=C; lscpu; echo -n "Governor: "; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 2>/dev/null; echo; unset LC_ALL', function (error, stdout) { if (!error) { lines = stdout.toString().split('\n'); @@ -611,7 +611,7 @@ function getCpu() { } if (result.speed === 0) { const current = getCpuCurrentSpeedSync(); - if (current.avg !== 0) result.speed = current.avg; + if (current.avg !== 0) { result.speed = current.avg; } } _cpu_speed = result.speed; result.speedMin = Math.round(parseFloat(util.getValue(lines, 'cpu min mhz').replace(/,/g, '.')) / 10.0) / 100; @@ -672,7 +672,7 @@ function getCpu() { if (_freebsd || _openbsd || _netbsd) { let modelline = ''; let lines = []; - if (os.cpus()[0] && os.cpus()[0].model) modelline = os.cpus()[0].model; + if (os.cpus()[0] && os.cpus()[0].model) { modelline = os.cpus()[0].model; } exec('export LC_ALL=C; dmidecode -t 4; dmidecode -t 7 unset LC_ALL', function (error, stdout) { let cache = []; if (!error) { @@ -689,7 +689,7 @@ function getCpu() { } if (result.speed === 0) { const current = getCpuCurrentSpeedSync(); - if (current.avg !== 0) result.speed = current.avg; + if (current.avg !== 0) { result.speed = current.avg; } } _cpu_speed = result.speed; result.speedMin = result.speed; @@ -829,7 +829,7 @@ function getCpu() { resolve(result); } } - }) + }); }); }); } @@ -867,8 +867,8 @@ function getCpuCurrentSpeedSync() { if ({}.hasOwnProperty.call(cpus, i)) { let freq = cpus[i].speed > 100 ? (cpus[i].speed + 1) / 1000 : cpus[i].speed / 10; avgFreq = avgFreq + freq; - if (freq > maxFreq) maxFreq = freq; - if (freq < minFreq) minFreq = freq; + if (freq > maxFreq) { maxFreq = freq; } + if (freq < minFreq) { minFreq = freq; } cores.push(parseFloat(freq.toFixed(2))); } } @@ -1035,7 +1035,7 @@ function cpuTemperature(callback) { const parts = line.split(':'); if (parts.length > 1) { const temp = parseFloat(parts[1].replace(',', '.')); - if (temp > result.max) result.max = temp; + if (temp > result.max) { result.max = temp; } sum = sum + temp; result.cores.push(temp); } @@ -1075,7 +1075,7 @@ function cpuTemperature(callback) { lines.forEach(function (line) { let value = (parseInt(line, 10) - 2732) / 10; sum = sum + value; - if (value > result.max) result.max = value; + if (value > result.max) { result.max = value; } result.cores.push(value); }); if (result.cores.length) { diff --git a/lib/docker.js b/lib/docker.js index 758156b..24b56b2 100644 --- a/lib/docker.js +++ b/lib/docker.js @@ -127,7 +127,7 @@ function dockerContainers(all, callback) { // GC in _docker_container_stats for (let key in _docker_container_stats) { if ({}.hasOwnProperty.call(_docker_container_stats, key)) { - if (!inContainers(docker_containers, key)) delete _docker_container_stats[key]; + if (!inContainers(docker_containers, key)) { delete _docker_container_stats[key]; } } } @@ -170,7 +170,7 @@ function dockerContainers(all, callback) { // GC in _docker_container_stats for (let key in _docker_container_stats) { if ({}.hasOwnProperty.call(_docker_container_stats, key)) { - if (!inContainers(docker_containers, key)) delete _docker_container_stats[key]; + if (!inContainers(docker_containers, key)) { delete _docker_container_stats[key]; } } } if (callback) { callback(result); } @@ -276,7 +276,7 @@ function docker_calcNetworkIO(networks) { let wx; for (let key in networks) { // skip loop if the property is from prototype - if (!{}.hasOwnProperty.call(networks, key)) continue; + if (!{}.hasOwnProperty.call(networks, key)) { continue; } /** * @namespace @@ -414,8 +414,8 @@ function dockerContainerStatsSingle(containerID) { result.cpuPercent = (stats.cpu_stats && stats.precpu_stats ? docker_calcCPUPercent(stats.cpu_stats, stats.precpu_stats) : 0); result.pids = (stats.pids_stats && stats.pids_stats.current ? stats.pids_stats.current : 0); result.restartCount = (dataInspect.RestartCount ? dataInspect.RestartCount : 0); - if (stats.networks) result.netIO = docker_calcNetworkIO(stats.networks); - if (stats.blkio_stats) result.blockIO = docker_calcBlockIO(stats.blkio_stats); + if (stats.networks) { result.netIO = docker_calcNetworkIO(stats.networks); } + if (stats.blkio_stats) { result.blockIO = docker_calcBlockIO(stats.blkio_stats); } result.cpuStats = (stats.cpu_stats ? stats.cpu_stats : {}); result.precpuStats = (stats.precpu_stats ? stats.precpu_stats : {}); result.memoryStats = (stats.memory_stats ? stats.memory_stats : {}); diff --git a/lib/filesystem.js b/lib/filesystem.js index c4051cb..5ef6ec3 100755 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -42,8 +42,8 @@ function fsSize(callback) { if (!fs.startsWith('/')) { return 'NFS'; } const parts = fs.split('/'); const fsShort = parts[parts.length - 1]; - const macOsDisksSingle = macOsDisks.filter(item => item.indexOf(fsShort) >= 0) - if (macOsDisksSingle.length === 1 && macOsDisksSingle[0].indexOf('APFS') >= 0) { return 'APFS' } + const macOsDisksSingle = macOsDisks.filter(item => item.indexOf(fsShort) >= 0); + if (macOsDisksSingle.length === 1 && macOsDisksSingle[0].indexOf('APFS') >= 0) { return 'APFS'; } return 'HFS'; } @@ -86,14 +86,14 @@ function fsSize(callback) { cmd = 'df -kP'; try { macOsDisks = execSync('diskutil list').toString().split('\n').filter(line => { - return !line.startsWith('/') && line.indexOf(':') > 0 + return !line.startsWith('/') && line.indexOf(':') > 0; }); } catch (e) { macOsDisks = []; } } - if (_linux) cmd = 'df -lkPTx squashfs | grep ^/'; - if (_freebsd || _openbsd || _netbsd) cmd = 'df -lkPT'; + if (_linux) { cmd = 'df -lkPTx squashfs | grep ^/'; } + if (_freebsd || _openbsd || _netbsd) { cmd = 'df -lkPT'; } exec(cmd, function (error, stdout) { if (!error) { let lines = stdout.toString().split('\n'); @@ -231,39 +231,41 @@ function parseDevices(lines) { } else { let parts = line.split(':'); if (parts.length > 1) { - if (!devices[i]) devices[i] = { - name: '', - identifier: '', - type: 'disk', - fsType: '', - mount: '', - size: 0, - physical: 'HDD', - uuid: '', - label: '', - model: '', - serial: '', - removable: false, - protocol: '' - }; + if (!devices[i]) { + devices[i] = { + name: '', + identifier: '', + type: 'disk', + fsType: '', + mount: '', + size: 0, + physical: 'HDD', + uuid: '', + label: '', + model: '', + serial: '', + removable: false, + protocol: '' + }; + } parts[0] = parts[0].trim().toUpperCase().replace(/ +/g, ''); parts[1] = parts[1].trim(); - if ('DEVICEIDENTIFIER' === parts[0]) devices[i].identifier = parts[1]; - if ('DEVICENODE' === parts[0]) devices[i].name = parts[1]; + if ('DEVICEIDENTIFIER' === parts[0]) { devices[i].identifier = parts[1]; } + if ('DEVICENODE' === parts[0]) { devices[i].name = parts[1]; } if ('VOLUMENAME' === parts[0]) { - if (parts[1].indexOf('Not applicable') === -1) devices[i].label = parts[1]; + if (parts[1].indexOf('Not applicable') === -1) { devices[i].label = parts[1]; } } - if ('PROTOCOL' === parts[0]) devices[i].protocol = parts[1]; - if ('DISKSIZE' === parts[0]) devices[i].size = parseBytes(parts[1]); - if ('FILESYSTEMPERSONALITY' === parts[0]) devices[i].fsType = parts[1]; - if ('MOUNTPOINT' === parts[0]) devices[i].mount = parts[1]; - if ('VOLUMEUUID' === parts[0]) devices[i].uuid = parts[1]; - if ('READ-ONLYMEDIA' === parts[0] && parts[1] === 'Yes') devices[i].physical = 'CD/DVD'; - if ('SOLIDSTATE' === parts[0] && parts[1] === 'Yes') devices[i].physical = 'SSD'; - if ('VIRTUAL' === parts[0]) devices[i].type = 'virtual'; - if ('REMOVABLEMEDIA' === parts[0]) devices[i].removable = (parts[1] === 'Removable'); - if ('PARTITIONTYPE' === parts[0]) devices[i].type = 'part'; - if ('DEVICE/MEDIANAME' === parts[0]) devices[i].model = parts[1]; + if ('PROTOCOL' === parts[0]) { devices[i].protocol = parts[1]; } + if ('DISKSIZE' === parts[0]) { devices[i].size = parseBytes(parts[1]); } + if ('FILESYSTEMPERSONALITY' === parts[0]) { devices[i].fsType = parts[1]; } + if ('MOUNTPOINT' === parts[0]) { devices[i].mount = parts[1]; } + if ('VOLUMEUUID' === parts[0]) { devices[i].uuid = parts[1]; } + if ('READ-ONLYMEDIA' === parts[0] && parts[1] === 'Yes') { devices[i].physical = 'CD/DVD'; } + if ('SOLIDSTATE' === parts[0] && parts[1] === 'Yes') { devices[i].physical = 'SSD'; } + if ('VIRTUAL' === parts[0]) { devices[i].type = 'virtual'; } + if ('REMOVABLEMEDIA' === parts[0]) { devices[i].removable = (parts[1] === 'Removable'); } + if ('PARTITIONTYPE' === parts[0]) { devices[i].type = 'part'; } + if ('DEVICE/MEDIANAME' === parts[0]) { devices[i].model = parts[1]; } } } } @@ -496,7 +498,7 @@ function fsStats(callback) { lines.forEach(function (line) { if (line !== '') { line = line.replace(/[├─│└]+/g, '').trim().split(' '); - if (fs_filter.indexOf(line[0]) === -1) fs_filter.push(line[0]); + if (fs_filter.indexOf(line[0]) === -1) { fs_filter.push(line[0]); } } }); @@ -643,7 +645,7 @@ function disksIO(callback) { let lines = stdout.split('\n'); lines.forEach(function (line) { // ignore empty lines - if (!line) return; + if (!line) { return; } // sum r/wIO of all disks to compute all disks IO let stats = line.split(';'); diff --git a/lib/graphics.js b/lib/graphics.js index 28de77a..64a1da5 100644 --- a/lib/graphics.js +++ b/lib/graphics.js @@ -132,8 +132,8 @@ function graphics(callback) { lastlevel = level; let parts = lines[i].split(':'); if (2 === level) { // grafics controller level - if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('chipsetmodel') !== -1) currentController.model = parts[1].trim(); - if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('vendor') !== -1) currentController.vendor = parts[1].split('(')[0].trim(); + if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('chipsetmodel') !== -1) { currentController.model = parts[1].trim(); } + if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('vendor') !== -1) { currentController.vendor = parts[1].split('(')[0].trim(); } if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('vram(total)') !== -1) { currentController.vram = parseInt(parts[1]); // in MB if (parts[1].toLowerCase().indexOf('gb') !== -1) { @@ -177,9 +177,9 @@ function graphics(callback) { currentDisplay.currentResX = currentDisplay.resolutionX; currentDisplay.currentResY = currentDisplay.resolutionY; } - if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('pixeldepth') !== -1) currentDisplay.pixelDepth = parseInt(parts[1]); // in BIT - if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('framebufferdepth') !== -1) currentDisplay.pixelDepth = parseInt(parts[1]); // in BIT - if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('maindisplay') !== -1 && parts[1].replace(/ +/g, '').toLowerCase() === 'yes') currentDisplay.main = true; + if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('pixeldepth') !== -1) { currentDisplay.pixelDepth = parseInt(parts[1]); } // in BIT + if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('framebufferdepth') !== -1) { currentDisplay.pixelDepth = parseInt(parts[1]); } // in BIT + if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('maindisplay') !== -1 && parts[1].replace(/ +/g, '').toLowerCase() === 'yes') { currentDisplay.main = true; } if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('built-in') !== -1 && parts[1].replace(/ +/g, '').toLowerCase() === 'yes') { currentDisplay.vendor = 'Apple'; currentDisplay.builtin = true; @@ -299,7 +299,7 @@ function graphics(callback) { } if (isGraphicsController) { // within VGA details let parts = lines[i].split(':'); - if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('devicename') !== -1 && parts[1].toLowerCase().indexOf('onboard') !== -1) currentController.bus = 'Onboard'; + if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('devicename') !== -1 && parts[1].toLowerCase().indexOf('onboard') !== -1) { currentController.bus = 'Onboard'; } if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('region') !== -1 && parts[1].toLowerCase().indexOf('memory') !== -1) { let memparts = parts[1].split('='); if (memparts.length > 1) { @@ -325,7 +325,7 @@ function graphics(callback) { } devices[field[1]][field[2]] = field[3]; } - return devices + return devices; }, {}); for (let deviceId in devices) { const device = devices[deviceId]; @@ -398,7 +398,7 @@ function graphics(callback) { _nvidiaSmiPath = [basePath, targetDir, 'nvidia-smi.exe'].join('/'); } } catch (e) { - util.noop() + util.noop(); } } else if (_linux) { _nvidiaSmiPath = 'nvidia-smi'; @@ -409,7 +409,7 @@ function graphics(callback) { function nvidiaSmi(options) { const nvidiaSmiExe = getNvidiaSmi(); if (nvidiaSmiExe) { - const nvidiaSmiOpts = '--query-gpu=driver_version,pci.sub_device_id,name,pci.bus_id,fan.speed,memory.total,memory.used,memory.free,utilization.gpu,utilization.memory,temperature.gpu,temperature.memory,power.draw,power.limit,clocks.gr,clocks.mem --format=csv,noheader,nounits' + const nvidiaSmiOpts = '--query-gpu=driver_version,pci.sub_device_id,name,pci.bus_id,fan.speed,memory.total,memory.used,memory.free,utilization.gpu,utilization.memory,temperature.gpu,temperature.memory,power.draw,power.limit,clocks.gr,clocks.mem --format=csv,noheader,nounits'; const cmd = nvidiaSmiExe + ' ' + nvidiaSmiOpts + (_linux ? ' 2>/dev/null' : ''); try { const res = execSync(cmd, options).toString(); @@ -456,7 +456,7 @@ function graphics(callback) { powerLimit: safeParseNumber(splittedData[13]), clockCore: safeParseNumber(splittedData[14]), clockMemory: safeParseNumber(splittedData[15]), - } + }; } }); @@ -728,9 +728,9 @@ function graphics(callback) { // needs to be rewritten ... using no spread operators result.controllers = result.controllers.map((controller) => { // match by busAddress return mergeControllerNvidia(controller, nvidiaData.find(({ pciBus }) => pciBus.endsWith(controller.busAddress)) || {}); - }) + }); } - let cmd = "clinfo --raw"; + let cmd = 'clinfo --raw'; exec(cmd, function (error, stdout) { if (!error) { let lines = stdout.toString().split('\n'); diff --git a/lib/index.js b/lib/index.js index 4a38e86..2f440fd 100755 --- a/lib/index.js +++ b/lib/index.js @@ -145,9 +145,9 @@ function getDynamicData(srv, iface, callback) { // use closure to track ƒ completion let functionProcessed = (function () { let totalFunctions = 15; - if (_windows) totalFunctions = 11; - if (_freebsd || _openbsd || _netbsd) totalFunctions = 11; - if (_sunos) totalFunctions = 6; + if (_windows) { totalFunctions = 11; } + if (_freebsd || _openbsd || _netbsd) { totalFunctions = 11; } + if (_sunos) { totalFunctions = 6; } return function () { if (--totalFunctions === 0) { @@ -329,9 +329,9 @@ function get(valueObject, callback) { let funcWithoutParams = func.indexOf(')') >= 0 ? func.split(')')[1].trim() : func; funcWithoutParams = func.indexOf('|') >= 0 ? func.split('|')[0].trim() : funcWithoutParams; if (params) { - return exports[funcWithoutParams](params) + return exports[funcWithoutParams](params); } else { - return exports[funcWithoutParams]('') + return exports[funcWithoutParams](''); } }); diff --git a/lib/memory.js b/lib/memory.js index 99a26a9..a208fc6 100644 --- a/lib/memory.js +++ b/lib/memory.js @@ -184,7 +184,7 @@ function mem(callback) { const cache = parseInt(util.getValue(lines, 'vm.stats.vm.v_cache_count'), 10) * pagesize; result.total = parseInt(util.getValue(lines, 'hw.realmem'), 10); - if (isNaN(result.total)) result.total = parseInt(util.getValue(lines, 'hw.physmem'), 10); + if (isNaN(result.total)) { result.total = parseInt(util.getValue(lines, 'hw.physmem'), 10); } result.free = parseInt(util.getValue(lines, 'vm.stats.vm.v_free_count'), 10) * pagesize; result.buffcache = inactive + cache; result.available = result.buffcache + result.free; @@ -219,9 +219,9 @@ function mem(callback) { let line = lines[0].replace(/,/g, '.').replace(/M/g, ''); line = line.trim().split(' '); for (let i = 0; i < line.length; i++) { - if (line[i].toLowerCase().indexOf('total') !== -1) result.swaptotal = parseFloat(line[i].split('=')[1].trim()) * 1024 * 1024; - if (line[i].toLowerCase().indexOf('used') !== -1) result.swapused = parseFloat(line[i].split('=')[1].trim()) * 1024 * 1024; - if (line[i].toLowerCase().indexOf('free') !== -1) result.swapfree = parseFloat(line[i].split('=')[1].trim()) * 1024 * 1024; + if (line[i].toLowerCase().indexOf('total') !== -1) { result.swaptotal = parseFloat(line[i].split('=')[1].trim()) * 1024 * 1024; } + if (line[i].toLowerCase().indexOf('used') !== -1) { result.swapused = parseFloat(line[i].split('=')[1].trim()) * 1024 * 1024; } + if (line[i].toLowerCase().indexOf('free') !== -1) { result.swapfree = parseFloat(line[i].split('=')[1].trim()) * 1024 * 1024; } } } } diff --git a/lib/printer.js b/lib/printer.js index 806fe1d..040cb34 100644 --- a/lib/printer.js +++ b/lib/printer.js @@ -36,10 +36,10 @@ const winPrinterStatus = { 5: 'Warmup', 6: 'Stopped Printing', 7: 'Offline', -} +}; function parseLinuxCupsHeader(lines) { - const result = {} + const result = {}; if (lines && lines.length) { if (lines[0].indexOf(' CUPS v') > 0) { const parts = lines[0].split(' CUPS v'); @@ -67,12 +67,12 @@ function parseLinuxCupsPrinter(lines) { function parseLinuxLpstatPrinter(lines, id) { const result = {}; - result.id = id + result.id = id; result.name = util.getValue(lines, 'Description', ':', true); result.model = lines.length > 0 && lines[0] ? lines[0].split(' ')[0] : ''; result.uri = null; - result.uuid = null - result.status = lines.length > 0 && lines[0] ? (lines[0].indexOf(' idle') > 0 ? 'idle' : (lines[0].indexOf(' printing') > 0 ? 'printing' : 'unknown')) : null + result.uuid = null; + result.status = lines.length > 0 && lines[0] ? (lines[0].indexOf(' idle') > 0 ? 'idle' : (lines[0].indexOf(' printing') > 0 ? 'printing' : 'unknown')) : null; result.local = util.getValue(lines, 'Location', ':', true).toLowerCase().startsWith('local'); result.default = null; result.shared = util.getValue(lines, 'Shared', ' ').toLowerCase().startsWith('yes'); @@ -84,10 +84,10 @@ function parseDarwinPrinters(printerObject, id) { const result = {}; const uriParts = printerObject.uri.split('/'); result.id = id; - result.name = printerObject._name + result.name = printerObject._name; result.model = uriParts.length ? uriParts[uriParts.length - 1] : ''; result.uri = printerObject.uri; - result.uuid = null + result.uuid = null; result.status = printerObject.status; result.local = printerObject.printserver === 'local'; result.default = printerObject.default === 'yes'; @@ -104,7 +104,7 @@ function parseWindowsPrinters(lines, id) { result.name = util.getValue(lines, 'name', '='); result.model = util.getValue(lines, 'DriverName', '='); result.uri = null; - result.uuid = null + result.uuid = null; result.status = winPrinterStatus[status] ? winPrinterStatus[status] : null; result.local = util.getValue(lines, 'Local', '=') === 'TRUE'; result.default = util.getValue(lines, 'Default', '=') === 'TRUE'; @@ -119,7 +119,7 @@ function printer(callback) { process.nextTick(() => { let result = []; if (_linux || _freebsd || _openbsd || _netbsd) { - let cmd = 'cat /etc/cups/printers.conf 2>/dev/null' + let cmd = 'cat /etc/cups/printers.conf 2>/dev/null'; exec(cmd, function (error, stdout) { // printers.conf if (!error) { @@ -164,7 +164,7 @@ function printer(callback) { }); } if (_darwin) { - let cmd = 'system_profiler SPPrintersDataType -json' + let cmd = 'system_profiler SPPrintersDataType -json'; exec(cmd, function (error, stdout) { if (!error) { try { @@ -176,7 +176,7 @@ function printer(callback) { } } } catch (e) { - util.noop() + util.noop(); } } if (callback) { @@ -190,7 +190,7 @@ function printer(callback) { if (!error) { const parts = stdout.toString().split(/\n\s*\n/); for (let i = 0; i < parts.length; i++) { - result.push(parseWindowsPrinters(parts[i].split('\n'), i)) + result.push(parseWindowsPrinters(parts[i].split('\n'), i)); } } if (callback) { diff --git a/lib/processes.js b/lib/processes.js index 3a794ff..345ff25 100644 --- a/lib/processes.js +++ b/lib/processes.js @@ -519,7 +519,7 @@ function processes(callback) { 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'))))))); checkColumn(10); let tty = line.substring(parsedhead[10].from + offset, parsedhead[10].to + offset2).trim(); - if (tty === '?' || tty === '??') tty = ''; + if (tty === '?' || tty === '??') { tty = ''; } checkColumn(11); const user = line.substring(parsedhead[11].from + offset, parsedhead[11].to + offset2).trim(); checkColumn(12); @@ -652,10 +652,10 @@ function processes(callback) { if ((_processes_cpu.ms && Date.now() - _processes_cpu.ms >= 500) || _processes_cpu.ms === 0) { if (_linux || _freebsd || _openbsd || _netbsd || _darwin || _sunos) { - 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'; - 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'; - if (_darwin) cmd = 'export LC_ALL=C; ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,nice,lstart,state,tty,user,command -r; unset LC_ALL'; - if (_sunos) cmd = 'ps -Ao pid,ppid,pcpu,pmem,pri,vsz,rss,nice,stime,s,tty,user,comm'; + 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'; } + 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'; } + if (_darwin) { cmd = 'export LC_ALL=C; ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,nice,lstart,state,tty,user,command -r; unset LC_ALL'; } + if (_sunos) { cmd = 'ps -Ao pid,ppid,pcpu,pmem,pri,vsz,rss,nice,stime,s,tty,user,comm'; } exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) { if (!error) { result.list = (parseProcesses(stdout.toString().split('\n'))).slice(); @@ -955,7 +955,7 @@ function processLoad(proc, callback) { inList = true; pname = proc; } - }) + }); if (processesString === '*' || inList) { let processFound = false; @@ -965,7 +965,7 @@ function processLoad(proc, callback) { item.mem += mem / os.totalmem() * 100; processFound = true; } - }) + }); if (!processFound) { result.push({ proc: pname, @@ -973,7 +973,7 @@ function processLoad(proc, callback) { pids: [pid], cpu: 0, mem: mem / os.totalmem() * 100 - }) + }); } } } @@ -982,7 +982,7 @@ function processLoad(proc, callback) { if (processesString !== '*') { let processesMissing = processes.filter(function (name) { // return procStats.filter(function(item) { return item.name.toLowerCase() === name }).length === 0; - return procStats.filter(function (item) { return item.name.toLowerCase().indexOf(name) >= 0 }).length === 0; + return procStats.filter(function (item) { return item.name.toLowerCase().indexOf(name) >= 0; }).length === 0; }); processesMissing.forEach(function (procName) { @@ -1040,12 +1040,12 @@ function processLoad(proc, callback) { if (!error) { let procStats = []; let lines = stdout.toString().split('\n').filter(function (line) { - if (processesString === '*') return true; - if (line.toLowerCase().indexOf('grep') !== -1) return false; // remove this?? + if (processesString === '*') { return true; } + if (line.toLowerCase().indexOf('grep') !== -1) { return false; } // remove this?? let found = false; processes.forEach(function (item) { - found = found || (line.toLowerCase().indexOf(item.toLowerCase()) >= 0) - }) + found = found || (line.toLowerCase().indexOf(item.toLowerCase()) >= 0); + }); return found; }); @@ -1057,14 +1057,14 @@ function processLoad(proc, callback) { pid: parseInt(data[0]) || 0, cpu: parseFloat(data[1].replace(',', '.')), mem: parseFloat(data[2].replace(',', '.')) - }) + }); } }); procStats.forEach(function (item) { let listPos = -1; let inList = false; - let name = '' + let name = ''; for (let j = 0; j < result.length; j++) { // if (result[j].proc.toLowerCase() === item.name.toLowerCase()) { // if (result[j].proc.toLowerCase().indexOf(item.name.toLowerCase()) >= 0) { @@ -1081,7 +1081,7 @@ function processLoad(proc, callback) { inList = true; name = proc; } - }) + }); // console.log(item); // console.log(listPos); if ((processesString === '*') || inList) { @@ -1092,19 +1092,19 @@ function processLoad(proc, callback) { pids: [item.pid], cpu: item.cpu, mem: item.mem - }) + }); } else { result[listPos].pids.push(item.pid); result[listPos].cpu += item.cpu; result[listPos].mem += item.mem; } } - }) + }); if (processesString !== '*') { // add missing processes let processesMissing = processes.filter(function (name) { - return procStats.filter(function (item) { return item.name.toLowerCase().indexOf(name) >= 0 }).length === 0; + return procStats.filter(function (item) { return item.name.toLowerCase().indexOf(name) >= 0; }).length === 0; }); processesMissing.forEach(function (procName) { result.push({ @@ -1120,7 +1120,7 @@ function processLoad(proc, callback) { // calc process_cpu - ps is not accurate in linux! result.forEach(function (item) { item.cpu = 0; - }) + }); let cmd = 'cat /proc/stat | grep "cpu "'; for (let i in result) { for (let j in result[i].pids) { @@ -1168,7 +1168,7 @@ function processLoad(proc, callback) { result.forEach(function (item) { item.cpu = Math.round(item.cpu * 100) / 100; - }) + }); _process_cpu.all = all; // _process_cpu.list = list_new; diff --git a/lib/system.js b/lib/system.js index 3bc64ac..67842a1 100644 --- a/lib/system.js +++ b/lib/system.js @@ -70,11 +70,11 @@ function system(callback) { } catch (e) { util.noop(); } - if (!result.serial || result.serial.toLowerCase().indexOf('o.e.m.') !== -1) result.serial = '-'; - if (!result.manufacturer || result.manufacturer.toLowerCase().indexOf('o.e.m.') !== -1) result.manufacturer = ''; - if (!result.model || result.model.toLowerCase().indexOf('o.e.m.') !== -1) result.model = 'Computer'; - if (!result.version || result.version.toLowerCase().indexOf('o.e.m.') !== -1) result.version = ''; - if (!result.sku || result.sku.toLowerCase().indexOf('o.e.m.') !== -1) result.sku = '-'; + if (!result.serial || result.serial.toLowerCase().indexOf('o.e.m.') !== -1) { result.serial = '-'; } + if (!result.manufacturer || result.manufacturer.toLowerCase().indexOf('o.e.m.') !== -1) { result.manufacturer = ''; } + if (!result.model || result.model.toLowerCase().indexOf('o.e.m.') !== -1) { result.model = 'Computer'; } + if (!result.version || result.version.toLowerCase().indexOf('o.e.m.') !== -1) { result.version = ''; } + if (!result.sku || result.sku.toLowerCase().indexOf('o.e.m.') !== -1) { result.sku = '-'; } // detect virtual (1) if (result.model.toLowerCase() === 'virtualbox' || result.model.toLowerCase() === 'kvm' || result.model.toLowerCase() === 'virtual machine' || result.model.toLowerCase() === 'bochs' || result.model.toLowerCase().startsWith('vmware') || result.model.toLowerCase().startsWith('droplet')) { @@ -117,7 +117,7 @@ function system(callback) { result.virtualHost = 'VirtualBox'; } } catch (e) { - util.noop(); + util.noop(); } } if ((_freebsd || _openbsd || _netbsd) && !result.virtualHost) { @@ -148,7 +148,7 @@ function system(callback) { result.model = 'Docker Container'; } try { - const stdout = execSync('dmesg | grep -iE "virtual|hypervisor" | grep -iE "vmware|qemu|kvm|xen"') + const stdout = execSync('dmesg | grep -iE "virtual|hypervisor" | grep -iE "vmware|qemu|kvm|xen"'); // detect virtual machines let lines = stdout.toString().split('\n'); if (lines.length > 0) { @@ -405,7 +405,7 @@ function system(callback) { if (callback) { callback(result); } resolve(result); } - }) + }); } else { if (callback) { callback(result); } resolve(result); @@ -478,11 +478,11 @@ function bios(callback) { const hardwareData = JSON.parse(stdout.toString()); if (hardwareData && hardwareData.SPHardwareDataType && hardwareData.SPHardwareDataType.length) { let bootRomVersion = hardwareData.SPHardwareDataType[0].boot_rom_version; - bootRomVersion = bootRomVersion ? bootRomVersion.split('(')[0].trim() : null + bootRomVersion = bootRomVersion ? bootRomVersion.split('(')[0].trim() : null; result.version = bootRomVersion; } } catch (e) { - util.noop() + util.noop(); } if (callback) { callback(result); } resolve(result); @@ -575,8 +575,8 @@ function baseboard(callback) { } catch (e) { util.noop(); } - if (result.serial.toLowerCase().indexOf('o.e.m.') !== -1) result.serial = '-'; - if (result.assetTag.toLowerCase().indexOf('o.e.m.') !== -1) result.assetTag = '-'; + if (result.serial.toLowerCase().indexOf('o.e.m.') !== -1) { result.serial = '-'; } + if (result.assetTag.toLowerCase().indexOf('o.e.m.') !== -1) { result.assetTag = '-'; } if (callback) { callback(result); } resolve(result); @@ -699,8 +699,8 @@ function chassis(callback) { result.version = util.getValue(lines, 'chassis_version'); result.serial = util.getValue(lines, 'chassis_serial'); result.assetTag = util.getValue(lines, 'chassis_asset_tag'); - if (result.serial.toLowerCase().indexOf('o.e.m.') !== -1) result.serial = '-'; - if (result.assetTag.toLowerCase().indexOf('o.e.m.') !== -1) result.assetTag = '-'; + if (result.serial.toLowerCase().indexOf('o.e.m.') !== -1) { result.serial = '-'; } + if (result.assetTag.toLowerCase().indexOf('o.e.m.') !== -1) { result.assetTag = '-'; } if (callback) { callback(result); } resolve(result); diff --git a/lib/usb.js b/lib/usb.js index c3b9d4a..5d1511c 100644 --- a/lib/usb.js +++ b/lib/usb.js @@ -80,11 +80,11 @@ function parseLinuxUsb(usb) { const manufacturer = iManufacturerParts.join(' '); result.id = (idVendor.startsWith('0x') ? idVendor.split(' ')[0].substr(2, 10) : '') + ':' + (idProduct.startsWith('0x') ? idProduct.split(' ')[0].substr(2, 10) : ''); - result.name = product + result.name = product; result.type = getLinuxUsbType(usbType, product); result.removable = null; result.vendor = vendor; - result.manufacturer = manufacturer + result.manufacturer = manufacturer; result.maxPower = util.getValue(lines, 'MaxPower', ' ', true); result.serialNumber = null; @@ -102,7 +102,7 @@ function parseLinuxUsb(usb) { // maxpower(linux) function getDarwinUsbType(name) { - let result = '' + let result = ''; if (name.indexOf('camera') >= 0) { result = 'Camera'; } else if (name.indexOf('touch bar') >= 0) { result = 'Touch Bar'; } else if (name.indexOf('controller') >= 0) { result = 'Controller'; } @@ -126,7 +126,7 @@ function parseDarwinUsb(usb, id) { const result = {}; result.id = id; - usb = usb.replace(/ \|/g, '') + usb = usb.replace(/ \|/g, ''); usb = usb.trim(); let lines = usb.split('\n'); lines.shift(); @@ -184,7 +184,7 @@ function parseDarwinUsb(usb, id) { // } function getWindowsUsbTypeCreation(creationclass, name) { - let result = '' + let result = ''; if (name.indexOf('storage') >= 0) { result = 'Storage'; } else if (name.indexOf('speicher') >= 0) { result = 'Storage'; } else if (creationclass.indexOf('usbhub') >= 0) { result = 'Hub'; } @@ -214,7 +214,7 @@ function parseWindowsUsb(lines, id) { return result; } else { - return null + return null; } } @@ -241,14 +241,14 @@ function usb(callback) { }); } if (_darwin) { - let cmd = 'ioreg -p IOUSB -c AppleUSBRootHubDevice -w0 -l' + let cmd = 'ioreg -p IOUSB -c AppleUSBRootHubDevice -w0 -l'; exec(cmd, { maxBuffer: 1024 * 1024 * 128 }, function (error, stdout) { if (!error) { const parts = (stdout.toString()).split(' +-o '); for (let i = 1; i < parts.length; i++) { const usb = parseDarwinUsb(parts[i]); if (usb) { - result.push(usb) + result.push(usb); } } if (callback) { @@ -267,9 +267,9 @@ function usb(callback) { if (!error) { const parts = stdout.toString().split(/\n\s*\n/); for (let i = 0; i < parts.length; i++) { - const usb = parseWindowsUsb(parts[i].split('\n'), i) + const usb = parseWindowsUsb(parts[i].split('\n'), i); if (usb) { - result.push(usb) + result.push(usb); } } }