fixed bugs fsSize(win), si.processes (command), si.osinfo(win)

This commit is contained in:
Sebastian Hildebrandt 2017-04-23 14:36:41 +02:00
parent 07c772a147
commit 5f000fba3a
16 changed files with 269 additions and 240 deletions

View File

@ -94,6 +94,7 @@ Other changes
| Version | Date | Comment |
| -------------- | -------------- | -------- |
| 3.17.1 | 2017-04-23 | fixed bugs fsSize(win), si.processes (command), si.osinfo(win) |
| 3.17.0 | 2017-02-19 | windows support for some first functions, extended process list (linux)|
| 3.16.0 | 2017-01-19 | blockDevices: added removable attribute + fix |
| 3.15.1 | 2017-01-17 | minor cpuTemperature fix (OSX) |

View File

@ -44,8 +44,8 @@ si.cpu()
- Version 3.17.0: windows support for some very first functions (work in progress)
- Version 3.16.0: `blockDevices`: added removable attribute
- Version 3.15.0: added `cpuTemperature` also for OSX
- Version 3.14.0: added `currentLoad` per cpu/core, cpu cache (L1, L2, L3) and cpu flags
- Version 3.15.0: added `cpuTemperature` also for OSX
- Version 3.14.0: added `currentLoad` per cpu/core, cpu cache (L1, L2, L3) and cpu flags
- Version 3.13.0: added `shell` (returns standard shell)
- Version 3.12.0: refactoring and extended `currentLoad` (better OSX coverage and added irq load).
- Version 3.11.0: `blockDevices` now also for OSX and also extended (+ label, model, serial, protocol).
@ -72,7 +72,7 @@ little library. This library is still work in progress. Version 3 comes with fur
requires now node.js version 4.0 and above. Another big change is, that all functions now return promises. You can use them
like before with callbacks OR with promises (see example in this documentation). I am sure, there is for sure room for improvement.
I was only able to test it on several Debian, Raspbian, Ubuntu distributions as well as OS X (Mavericks, Yosemite, El Captain).
Since version 2 nearly all functionality is available on OS X/Darwin platforms.
Since version 2 nearly all functionality is available on OS X/Darwin platforms.
Be careful, this library has only very limited Windows support!
If you have comments, suggestions & reports, please feel free to contact me!
@ -254,8 +254,8 @@ This library is splitted in several sections:
| - list[] | X | X | | list of all processes incl. details |
| - ...[0].pid | X | X | | process PID |
| - ...[0].pcpu | X | X | | process % CPU usage |
| - ...[0].pcpuu | X | X | | process % CPU usage (user) |
| - ...[0].pcpus | X | X | | process % CPU usage (system) |
| - ...[0].pcpuu | X | | | process % CPU usage (user) |
| - ...[0].pcpus | X | | | process % CPU usage (system) |
| - ...[0].pmem | X | X | | process memory % |
| - ...[0].priority | X | X | | process priotity |
| - ...[0].mem_vsz | X | X | | process virtual memory size |
@ -264,6 +264,8 @@ This library is splitted in several sections:
| - ...[0].started | X | X | | process start time |
| - ...[0].state | X | X | | process state (e.g. sleeping) |
| - ...[0].tty | X | X | | tty from which process was started |
| - ...[0].user | X | X | | user who started process |
| - ...[0].command | X | X | | process starting command |
| si.processLoad('apache2',cb) | X | X | | detailed information about given process |
| - proc | X | X | | process name |
| - pid | X | X | | PID |
@ -402,7 +404,7 @@ Written by Sebastian Hildebrandt [sebhildebrandt](https://github.com/sebhildebra
OSX Temperature: Credits here are going to:
- Massimiliano Marcon [mmarcon](https://github.com/mmarcon) - for his work on [smc-code][smc-code-url]
- Sébastien Lavoie[lavoiesl](https://github.com/lavoiesl) for his work on [osx-cpu-temp][osx-cpu-temp-url] code.
- Sébastien Lavoie [lavoiesl](https://github.com/lavoiesl) for his work on [osx-cpu-temp][osx-cpu-temp-url] code.
## Copyright Information

View File

@ -19,9 +19,9 @@ const util = require('./util');
let _platform = os.type();
const _linux = (_platform == 'Linux');
const _darwin = (_platform == 'Darwin');
const _windows = (_platform == 'Windows_NT');
const _linux = (_platform === 'Linux');
const _darwin = (_platform === 'Darwin');
const _windows = (_platform === 'Windows_NT');
const NOT_SUPPORTED = 'not supported';
module.exports = function (callback) {
@ -54,7 +54,7 @@ module.exports = function (callback) {
exec("cat " + battery_path + "status", function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
if (lines.length > 0 && lines[0]) result.ischarging = (lines[0].trim().toLowerCase() == 'charging')
if (lines.length > 0 && lines[0]) result.ischarging = (lines[0].trim().toLowerCase() === 'charging')
}
exec("cat " + battery_path + "cyclec_ount", function (error, stdout) {
if (!error) {
@ -91,11 +91,11 @@ module.exports = function (callback) {
if (!error) {
let lines = stdout.toString().replace(/ +/g, "").replace(/"+/g, "").split('\n');
lines.forEach(function (line) {
if (line.indexOf('=') != -1) {
if (line.toLowerCase().indexOf('cyclecount') != -1) result.cyclecount = parseFloat(line.split('=')[1].trim());
if (line.toLowerCase().indexOf('ischarging') != -1) result.ischarging = (line.split('=')[1].trim().toLowerCase() == 'yes');
if (line.toLowerCase().indexOf('maxcapacity') != -1) result.maxcapacity = parseFloat(line.split('=')[1].trim());
if (line.toLowerCase().indexOf('currentcapacity') != -1) result.currentcapacity = parseFloat(line.split('=')[1].trim());
if (line.indexOf('=') !== -1) {
if (line.toLowerCase().indexOf('cyclecount') !== -1) result.cyclecount = parseFloat(line.split('=')[1].trim());
if (line.toLowerCase().indexOf('ischarging') !== -1) result.ischarging = (line.split('=')[1].trim().toLowerCase() === 'yes');
if (line.toLowerCase().indexOf('maxcapacity') !== -1) result.maxcapacity = parseFloat(line.split('=')[1].trim());
if (line.toLowerCase().indexOf('currentcapacity') !== -1) result.currentcapacity = parseFloat(line.split('=')[1].trim());
}
});
}

View File

@ -19,9 +19,9 @@ const util = require('./util');
let _platform = os.type();
const _linux = (_platform == 'Linux');
const _darwin = (_platform == 'Darwin');
const _windows = (_platform == 'Windows_NT');
const _linux = (_platform === 'Linux');
const _darwin = (_platform === 'Darwin');
const _windows = (_platform === 'Windows_NT');
const NOT_SUPPORTED = 'not supported';
let _cpu_speed = '0.00';
@ -89,9 +89,9 @@ function getCpu() {
let line = lines[0].split(':')[1];
result.brand = line.split('@')[0].trim();
result.speed = line.split('@')[1] ? parseFloat(line.split('@')[1].trim()).toFixed(2) : '0.00';
if (result.speed == '0.00') {
if (result.speed === '0.00') {
let current = getCpuCurrentSpeedSync();
if (current != '0.00') result.speed = current;
if (current !== '0.00') result.speed = current;
}
_cpu_speed = result.speed;
}
@ -102,7 +102,7 @@ function getCpu() {
if (_windows) {
exec("wmic cpu get name", function (error, stdout) {
if (!error) {
let lines = stdout.split('\r\n').filter(line => line.trim() != '').filter((line, idx) => idx > 0);
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
let line = (lines && lines[0]) ? lines[0] : '';
result.brand = line.split('@')[0].trim();
result.speed = line.split('@')[1].trim();
@ -172,7 +172,7 @@ function cpuCurrentspeed(callback) {
return new Promise((resolve) => {
process.nextTick(() => {
let result = getCpuCurrentSpeedSync();
if (result == 0 && _cpu_speed != '0.00') result = parseFloat(_cpu_speed);
if (result === 0 && _cpu_speed !== '0.00') result = parseFloat(_cpu_speed);
if (callback) { callback(result) }
resolve(result);
@ -202,10 +202,10 @@ function cpuTemperature(callback) {
lines.forEach(function (line) {
let regex = /\+([^°]*)/g;
let temps = line.match(regex);
if (line.split(':')[0].toUpperCase().indexOf('PHYSICAL') != -1) {
if (line.split(':')[0].toUpperCase().indexOf('PHYSICAL') !== -1) {
result.main = parseFloat(temps);
}
if (line.split(':')[0].toUpperCase().indexOf('CORE ') != -1) {
if (line.split(':')[0].toUpperCase().indexOf('CORE ') !== -1) {
result.cores.push(parseFloat(temps));
}
});
@ -217,7 +217,7 @@ function cpuTemperature(callback) {
resolve(result);
} else {
fs.stat('/sys/class/thermal/thermal_zone0/temp', function(err, stat) {
if(err == null) {
if(err === null) {
exec("cat /sys/class/thermal/thermal_zone0/temp", function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
@ -255,7 +255,7 @@ function cpuTemperature(callback) {
let id = 0;
cores.forEach(function(key) {
let value = smc.get(key);
if (id == 0) {
if (id === 0) {
if (value > 0) {
result.main = value;
result.max = value;
@ -323,7 +323,7 @@ function cpuFlags(callback) {
if (!error) {
let lines = stdout.toString().split('\n');
lines.forEach(function (line) {
if (line.split(':')[0].toUpperCase().indexOf('FLAGS') != -1) {
if (line.split(':')[0].toUpperCase().indexOf('FLAGS') !== -1) {
result = line.split(':')[1].trim().toLowerCase();
}
});
@ -336,7 +336,7 @@ function cpuFlags(callback) {
exec("sysctl machdep.cpu.features", function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
if (lines.length > 0 && lines[0].indexOf('machdep.cpu.features:') != -1) {
if (lines.length > 0 && lines[0].indexOf('machdep.cpu.features:') !== -1) {
result = lines[0].split(':')[1].trim().toLowerCase();
}
}
@ -370,17 +370,17 @@ function cpuCache(callback) {
let lines = stdout.toString().split('\n');
lines.forEach(function (line) {
let parts = line.split(':');
if (parts[0].toUpperCase().indexOf('L1D CACHE') != -1) {
result.l1d = parseInt(parts[1].trim()) * (parts[1].indexOf('K') != -1 ? 1024 : 1);
if (parts[0].toUpperCase().indexOf('L1D CACHE') !== -1) {
result.l1d = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
}
if (parts[0].toUpperCase().indexOf('L1I CACHE') != -1) {
result.l1i = parseInt(parts[1].trim()) * (parts[1].indexOf('K') != -1 ? 1024 : 1);
if (parts[0].toUpperCase().indexOf('L1I CACHE') !== -1) {
result.l1i = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
}
if (parts[0].toUpperCase().indexOf('L2 CACHE') != -1) {
result.l2 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') != -1 ? 1024 : 1);
if (parts[0].toUpperCase().indexOf('L2 CACHE') !== -1) {
result.l2 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
}
if (parts[0].toUpperCase().indexOf('L3 CACHE') != -1) {
result.l3 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') != -1 ? 1024 : 1);
if (parts[0].toUpperCase().indexOf('L3 CACHE') !== -1) {
result.l3 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
}
});
}
@ -394,17 +394,17 @@ function cpuCache(callback) {
let lines = stdout.toString().split('\n');
lines.forEach(function (line) {
let parts = line.split(':');
if (parts[0].toLowerCase().indexOf('hw.l1icachesize') != -1) {
result.l1d = parseInt(parts[1].trim()) * (parts[1].indexOf('K') != -1 ? 1024 : 1);
if (parts[0].toLowerCase().indexOf('hw.l1icachesize') !== -1) {
result.l1d = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
}
if (parts[0].toLowerCase().indexOf('hw.l1dcachesize') != -1) {
result.l1i = parseInt(parts[1].trim()) * (parts[1].indexOf('K') != -1 ? 1024 : 1);
if (parts[0].toLowerCase().indexOf('hw.l1dcachesize') !== -1) {
result.l1i = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
}
if (parts[0].toLowerCase().indexOf('hw.l2cachesize') != -1) {
result.l2 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') != -1 ? 1024 : 1);
if (parts[0].toLowerCase().indexOf('hw.l2cachesize') !== -1) {
result.l2 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
}
if (parts[0].toLowerCase().indexOf('hw.l3cachesize') != -1) {
result.l3 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') != -1 ? 1024 : 1);
if (parts[0].toLowerCase().indexOf('hw.l3cachesize') !== -1) {
result.l3 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
}
});
}

View File

@ -18,7 +18,7 @@ const DockerSocket = require('./dockerSocket');
let _platform = os.type();
const _windows = (_platform == 'Windows_NT');
const _windows = (_platform === 'Windows_NT');
const NOT_SUPPORTED = 'not supported';
let _docker_container_stats = {};
@ -192,10 +192,10 @@ function docker_calcBlockIO(blkio_stats) {
* @property {number} value
*/
if (element.op && element.op.toLowerCase() == 'read' && element.value) {
if (element.op && element.op.toLowerCase() === 'read' && element.value) {
result.r += element.value;
}
if (element.op && element.op.toLowerCase() == 'write' && element.value) {
if (element.op && element.op.toLowerCase() === 'write' && element.value) {
result.w += element.value;
}
})
@ -395,7 +395,7 @@ function dockerAll(callback) {
element.processes = processes;
l -= 1;
if (l == 0) {
if (l === 0) {
if (callback) { callback(result) }
resolve(result);
}

View File

@ -19,9 +19,9 @@ const util = require('./util');
let _platform = os.type();
const _linux = (_platform == 'Linux');
const _darwin = (_platform == 'Darwin');
const _windows = (_platform == 'Windows_NT');
const _linux = (_platform === 'Linux');
const _darwin = (_platform === 'Darwin');
const _windows = (_platform === 'Windows_NT');
const NOT_SUPPORTED = 'not supported';
let _fs_speed = {};
@ -34,15 +34,15 @@ function fsSize(callback) {
return new Promise((resolve, reject) => {
process.nextTick(() => {
let data = [];
if (_linux || _darwin) {
let cmd = (_darwin ? "df -lkP | grep ^/" : "df -lkPT | grep ^/");
exec(cmd, function (error, stdout) {
let data = [];
if (!error) {
let lines = stdout.toString().split('\n');
//lines.splice(0, 1);
lines.forEach(function (line) {
if (line != '') {
if (line !== '') {
line = line.replace(/ +/g, " ").split(' ');
data.push({
'fs': line[0],
@ -63,9 +63,9 @@ function fsSize(callback) {
}
if (_windows) {
exec('wmic logicaldisk get Caption,FileSystem,FreeSpace,Size', function (error, stdout) {
let lines = stdout.split('\r\n').filter(line => line.trim() != '').filter((line, idx) => idx > 0);
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) {
if (line != '') {
if (line !== '') {
line = line.trim().split(/\s\s+/);
data.push({
'fs': line[0],
@ -101,7 +101,7 @@ function parseDevices(lines) {
let i = 0;
lines.forEach(line => {
if (line.length > 0) {
if (line[0] == '*') {
if (line[0] === '*') {
i++;
} else {
let parts = line.split(':');
@ -123,22 +123,22 @@ function parseDevices(lines) {
};
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 ('VOLUMENAME' == parts[0]) {
if (parts[1].indexOf('Not applicable') == -1) devices[i].label = 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 ('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];
}
}
}
@ -149,7 +149,7 @@ function parseDevices(lines) {
function parseBlk(lines) {
let data = [];
lines.filter(line => line != '').forEach((line) => {
lines.filter(line => line !== '').forEach((line) => {
let disk = JSON.parse(line);
data.push({
'name': disk.name,
@ -157,12 +157,12 @@ function parseBlk(lines) {
'fstype': disk.fstype,
'mount': disk.mountpoint,
'size': parseInt(disk.size),
'physical': (disk.type == 'disk' ? (disk.rota == '0' ? 'SSD' : 'HDD') : (disk.type == 'rom' ? 'CD/DVD' : '')),
'physical': (disk.type === 'disk' ? (disk.rota === '0' ? 'SSD' : 'HDD') : (disk.type === 'rom' ? 'CD/DVD' : '')),
'uuid': disk.uuid,
'label': disk.label,
'model': disk.model,
'serial': disk.serial,
'removable': disk.rm == '1',
'removable': disk.rm === '1',
'protocol': disk.tran
})
});
@ -238,9 +238,9 @@ function blockDevices(callback) {
if (_windows) {
exec('wmic logicaldisk get Caption,Description,DeviceID,DriveType,FileSystem,FreeSpace,Name,Size,VolumeName,VolumeSerialNumber /format:csv', function (error, stdout) {
if (!error) {
let lines = stdout.split('\r\n').filter(line => line.trim() != '').filter((line, idx) => idx > 0);
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) {
if (line != '') {
if (line !== '') {
line = line.replace('\r', '').split(',');
data.push({
name: line[7],
@ -249,12 +249,12 @@ function blockDevices(callback) {
fstype: line[5].toLowerCase(),
mount: line[1],
size: line[8],
physical: line[4] == '5' ? 'CD/DVD' : 'HDD',
physical: line[4] === '5' ? 'CD/DVD' : 'HDD',
uuid: line[10],
label: line[9],
model: '',
serial: line[10],
removable: line[4] == '2',
removable: line[4] === '2',
protocol: ''
});
}
@ -350,9 +350,9 @@ function fsStats(callback) {
let lines = stdout.toString().split('\n');
let fs_filter = [];
lines.forEach(function (line) {
if (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])
}
});
@ -362,7 +362,7 @@ function fsStats(callback) {
let lines = stdout.toString().split('\n');
lines.forEach(function (line) {
line = line.trim();
if (line != '') {
if (line !== '') {
line = line.replace(/ +/g, " ").split(' ');
rx += parseInt(line[5]) * 512;
@ -390,7 +390,7 @@ function fsStats(callback) {
let lines = stdout.toString().split('\n');
lines.forEach(function (line) {
line = line.trim();
if (line != '') {
if (line !== '') {
line = line.split(' ');
rx += parseInt(line[0]);
@ -527,7 +527,7 @@ function disksIO(callback) {
let lines = stdout.toString().split('\n');
lines.forEach(function (line) {
line = line.trim();
if (line != '') {
if (line !== '') {
line = line.split(' ');
rIO += parseInt(line[1]);

View File

@ -19,9 +19,9 @@ const util = require('./util');
let _platform = os.type();
const _linux = (_platform == 'Linux');
const _darwin = (_platform == 'Darwin');
const _windows = (_platform == 'Windows_NT');
const _linux = (_platform === 'Linux');
const _darwin = (_platform === 'Darwin');
const _windows = (_platform === 'Windows_NT');
const NOT_SUPPORTED = 'not supported';
function graphics(callback) {
@ -35,9 +35,9 @@ function graphics(callback) {
let currentController = {};
let currentDisplay = {};
for (let i = 0; i < lines.length; i++) {
if ('' != lines[i].trim()) {
if ('' !== lines[i].trim()) {
let start = lines[i].search(/\S|$/);
if (-1 == starts.indexOf(start)) {
if (-1 === starts.indexOf(start)) {
starts.push(start);
}
level = starts.indexOf(start);
@ -53,21 +53,21 @@ 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('bus') != -1) currentController.bus = 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) {
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('bus') !== -1) currentController.bus = 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
currentController.vramDynamic = false;
}
if (parts.length > 1 && parts[0].replace(/ +/g, "").toLowerCase().indexOf('vram(dynamic,max)') != -1) {
if (parts.length > 1 && parts[0].replace(/ +/g, "").toLowerCase().indexOf('vram(dynamic,max)') !== -1) {
currentController.vram = parseInt(parts[1]); // in MB
currentController.vramDynamic = true;
}
}
if (3 == level) { // display controller level
if (parts.length > 1 && '' == parts[1]) {
if (3 === level) { // display controller level
if (parts.length > 1 && '' === parts[1]) {
currentDisplay.model = parts[0].trim();
currentDisplay.main = false;
currentDisplay.builtin = false;
@ -76,19 +76,19 @@ function graphics(callback) {
currentDisplay.sizey = -1;
}
}
if (4 == level) { // display controller details level
if (parts.length > 1 && parts[0].replace(/ +/g, "").toLowerCase().indexOf('resolution') != -1) {
if (4 === level) { // display controller details level
if (parts.length > 1 && parts[0].replace(/ +/g, "").toLowerCase().indexOf('resolution') !== -1) {
let resolution = parts[1].split('x');
currentDisplay.resolutionx = (resolution.length > 1 ? parseInt(resolution[0]) : 0);
currentDisplay.resolutiony = (resolution.length > 1 ? parseInt(resolution[1]) : 0);
}
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('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') {
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('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.builtin = true;
currentDisplay.connection = '';
}
if (parts.length > 1 && parts[0].replace(/ +/g, "").toLowerCase().indexOf('connectiontype') != -1) {
if (parts.length > 1 && parts[0].replace(/ +/g, "").toLowerCase().indexOf('connectiontype') !== -1) {
currentDisplay.builtin = false;
currentDisplay.connection = parts[1].trim();
}
@ -112,10 +112,10 @@ function graphics(callback) {
let currentController = {};
let is_vga = false;
for (let i = 0; i < lines.length; i++) {
if ('' != lines[i].trim()) {
if (' ' != lines[i][0] && '\t' != lines[i][0]) { // first line of new entry
if ('' !== lines[i].trim()) {
if (' ' !== lines[i][0] && '\t' !== lines[i][0]) { // first line of new entry
let vgapos = lines[i].toLowerCase().indexOf('vga');
if (vgapos != -1) { // VGA
if (vgapos !== -1) { // VGA
if (Object.keys(currentController).length > 0) {// already a controller found
controllers.push(currentController);
currentController = {};
@ -140,8 +140,8 @@ function graphics(callback) {
}
if (is_vga) { // within VGA details
let parts = lines[i].split(':');
if (parts.length > 1 && parts[0].replace(/ +/g, "").toLowerCase().indexOf('devicename') != -1 && parts[0].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) {
if (parts.length > 1 && parts[0].replace(/ +/g, "").toLowerCase().indexOf('devicename') !== -1 && parts[0].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) {
currentController.vram = parseInt(memparts[1]);
@ -168,16 +168,16 @@ function graphics(callback) {
let result = {};
// find first "Detailed Timing Description"
let start = 108;
if (edid.substr(start, 6) == '000000') {
if (edid.substr(start, 6) === '000000') {
start += 36;
}
if (edid.substr(start, 6) == '000000') {
if (edid.substr(start, 6) === '000000') {
start += 36;
}
if (edid.substr(start, 6) == '000000') {
if (edid.substr(start, 6) === '000000') {
start += 36;
}
if (edid.substr(start, 6) == '000000') {
if (edid.substr(start, 6) === '000000') {
start += 36;
}
result.resolutionx = parseInt('0x0' + edid.substr(start + 8, 1) + edid.substr(start + 4, 2));
@ -188,7 +188,7 @@ function graphics(callback) {
start = edid.indexOf('000000fc00'); // find first "Monitor Description Data"
if (start >= 0) {
let model_raw = edid.substr(start + 10, 26);
if (model_raw.indexOf('0a') != -1) {
if (model_raw.indexOf('0a') !== -1) {
model_raw = model_raw.substr(0, model_raw.indexOf('0a'))
}
result.model = model_raw.match(/.{1,2}/g).map(function (v) {
@ -207,15 +207,15 @@ function graphics(callback) {
let edid_raw = '';
let start = 0;
for (let i = 1; i < lines.length; i++) { // start with second line
if ('' != lines[i].trim()) {
if (' ' != lines[i][0] && '\t' != lines[i][0] && lines[i].toLowerCase().indexOf(' connected ') != -1) { // first line of new entry
if ('' !== lines[i].trim()) {
if (' ' !== lines[i][0] && '\t' !== lines[i][0] && lines[i].toLowerCase().indexOf(' connected ') !== -1) { // first line of new entry
if (Object.keys(currentDisplay).length > 0) { // push last display to array
displays.push(currentDisplay);
currentDisplay = {};
}
let parts = lines[i].split(' ');
currentDisplay.connection = parts[0];
currentDisplay.main = (parts[2] == 'primary');
currentDisplay.main = (parts[2] === 'primary');
currentDisplay.builtin = (parts[0].toLowerCase().indexOf('edp') >= 0)
}
@ -235,7 +235,7 @@ function graphics(callback) {
is_edid = false;
}
}
if (lines[i].toLowerCase().indexOf('edid:') != -1) {
if (lines[i].toLowerCase().indexOf('edid:') !== -1) {
is_edid = true;
start = lines[i].search(/\S|$/);
}

View File

@ -82,6 +82,7 @@
// --------------------------------
//
// version date comment
// 3.17.1 2017-04-23 fixed bugs fsSize(win), si.processes (command), si.osinfo(win)
// 3.17.0 2017-02-19 windows support for some first functions
// 3.16.0 2017-01-19 blockDevices: added removable attribute + fix
// 3.15.1 2017-01-17 minor cpuTemperature fix (OSX)
@ -158,7 +159,7 @@ const internet = require('./internet');
const docker = require('./docker');
let _platform = os.type();
let _windows = (_platform == 'Windows_NT');
let _windows = (_platform === 'Windows_NT');
const NOT_SUPPORTED = 'not supported';

View File

@ -18,9 +18,9 @@ const util = require('./util');
let _platform = os.type();
const _linux = (_platform == 'Linux');
const _darwin = (_platform == 'Darwin');
const _windows = (_platform == 'Windows_NT');
const _linux = (_platform === 'Linux');
const _darwin = (_platform === 'Darwin');
const _windows = (_platform === 'Windows_NT');
const NOT_SUPPORTED = 'not supported';
// --------------------------
@ -49,7 +49,7 @@ function inetChecksite(url, callback) {
exec(cmd + args, function (error, stdout) {
let statusCode = parseInt(stdout.toString());
result.status = statusCode || 404;
result.ok = !error && (statusCode == 200 || statusCode == 301 || statusCode == 302 || statusCode == 304);
result.ok = !error && (statusCode === 200 || statusCode === 301 || statusCode === 302 || statusCode === 304);
result.ms = (result.ok ? Date.now() - t : -1);
if (callback) { callback(result) }
resolve(result);

View File

@ -19,9 +19,9 @@ const util = require('./util');
let _platform = os.type();
const _linux = (_platform == 'Linux');
const _darwin = (_platform == 'Darwin');
const _windows = (_platform == 'Windows_NT');
const _linux = (_platform === 'Linux');
const _darwin = (_platform === 'Darwin');
const _windows = (_platform === 'Windows_NT');
const NOT_SUPPORTED = 'not supported';
// _______________________________________________________________________________________
@ -138,9 +138,9 @@ module.exports = function (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;
}
}

View File

@ -20,9 +20,9 @@ const util = require('./util');
let _platform = os.type();
const _linux = (_platform == 'Linux');
const _darwin = (_platform == 'Darwin');
const _windows = (_platform == 'Windows_NT');
const _linux = (_platform === 'Linux');
const _darwin = (_platform === 'Darwin');
const _windows = (_platform === 'Windows_NT');
const NOT_SUPPORTED = 'not supported';
let _network = {};
@ -44,7 +44,7 @@ function getDefaultNetworkInterface() {
for (let dev in ifaces) {
if (ifaces.hasOwnProperty(dev)) {
ifaces[dev].forEach(function (details) {
if (details && details.internal == false) {
if (details && details.internal === false) {
ifacename = ifacename || dev;
}
})
@ -93,10 +93,10 @@ function networkInterfaces(callback) {
let mac = '';
if (ifaces.hasOwnProperty(dev)) {
ifaces[dev].forEach(function (details) {
if (details.family == 'IPv4') {
if (details.family === 'IPv4') {
ip4 = details.address
}
if (details.family == 'IPv6') {
if (details.family === 'IPv6') {
ip6 = details.address
}
mac = details.mac
@ -217,13 +217,13 @@ function networkStats(iface, callback) {
exec(cmd, function (error, stdout) {
result.operstate = (stdout.toString().split(':')[1] || '').trim();
result.operstate = (result.operstate || '').toLowerCase();
result.operstate = (result.operstate == 'active' ? 'up' : (result.operstate == 'inactive' ? 'down' : 'unknown'));
result.operstate = (result.operstate === 'active' ? 'up' : (result.operstate === 'inactive' ? 'down' : 'unknown'));
cmd = "netstat -bI " + iface;
exec(cmd, function (error, stdout) {
if (!error) {
lines = stdout.toString().split('\n');
// if there is less than 2 lines, no information for this interface was found
if (lines.length > 1 && lines[1].trim() != '') {
if (lines.length > 1 && lines[1].trim() !== '') {
// skip header line
// use the second line because it is tied to the NIC instead of the ipv4 or ipv6 address
stats = lines[1].replace(/ +/g, " ").split(' ');
@ -292,7 +292,7 @@ function networkConnections(callback) {
peerip = peeraddress.join(':');
}
let connstate = line[5];
if (connstate == 'VERBUNDEN') connstate = 'ESTABLISHED';
if (connstate === 'VERBUNDEN') connstate = 'ESTABLISHED';
if (connstate) {
result.push({
protocol: line[0],
@ -335,8 +335,8 @@ function networkConnections(callback) {
peerip = peeraddress.join(':');
}
let connstate = line[1];
if (connstate == 'ESTAB') connstate = 'ESTABLISHED';
if (connstate == 'TIME-WAIT') connstate = 'TIME_WAIT';
if (connstate === 'ESTAB') connstate = 'ESTABLISHED';
if (connstate === 'TIME-WAIT') connstate = 'TIME_WAIT';
if (connstate) {
result.push({
protocol: line[0],

View File

@ -19,9 +19,9 @@ const util = require('./util');
let _platform = os.type();
const _linux = (_platform == 'Linux');
const _darwin = (_platform == 'Darwin');
const _windows = (_platform == 'Windows_NT');
const _linux = (_platform === 'Linux');
const _darwin = (_platform === 'Darwin');
const _windows = (_platform === 'Windows_NT');
const NOT_SUPPORTED = 'not supported';
// --------------------------
@ -40,90 +40,91 @@ exports.time = time;
// Get logo filename of OS distribution
function getLogoFile(distro) {
distro = distro || '';
distro = distro.toLowerCase();
let result = 'linux';
if (_windows) {
result = 'windows'
}
else if (distro.indexOf('mac os') != -1) {
else if (distro.indexOf('mac os') !== -1) {
result = 'apple'
}
else if (distro.indexOf('arch') != -1) {
else if (distro.indexOf('arch') !== -1) {
result = 'arch'
}
else if (distro.indexOf('centos') != -1) {
else if (distro.indexOf('centos') !== -1) {
result = 'centos'
}
else if (distro.indexOf('coreos') != -1) {
else if (distro.indexOf('coreos') !== -1) {
result = 'coreos'
}
else if (distro.indexOf('debian') != -1) {
else if (distro.indexOf('debian') !== -1) {
result = 'debian'
}
else if (distro.indexOf('elementary') != -1) {
else if (distro.indexOf('elementary') !== -1) {
result = 'elementary'
}
else if (distro.indexOf('fedora') != -1) {
else if (distro.indexOf('fedora') !== -1) {
result = 'fedora'
}
else if (distro.indexOf('gentoo') != -1) {
else if (distro.indexOf('gentoo') !== -1) {
result = 'gentoo'
}
else if (distro.indexOf('mageia') != -1) {
else if (distro.indexOf('mageia') !== -1) {
result = 'mageia'
}
else if (distro.indexOf('mandriva') != -1) {
else if (distro.indexOf('mandriva') !== -1) {
result = 'mandriva'
}
else if (distro.indexOf('manjaro') != -1) {
else if (distro.indexOf('manjaro') !== -1) {
result = 'manjaro'
}
else if (distro.indexOf('mint') != -1) {
else if (distro.indexOf('mint') !== -1) {
result = 'mint'
}
else if (distro.indexOf('openbsd') != -1) {
else if (distro.indexOf('openbsd') !== -1) {
result = 'openbsd'
}
else if (distro.indexOf('opensuse') != -1) {
else if (distro.indexOf('opensuse') !== -1) {
result = 'opensuse'
}
else if (distro.indexOf('pclinuxos') != -1) {
else if (distro.indexOf('pclinuxos') !== -1) {
result = 'pclinuxos'
}
else if (distro.indexOf('puppy') != -1) {
else if (distro.indexOf('puppy') !== -1) {
result = 'puppy'
}
else if (distro.indexOf('raspbian') != -1) {
else if (distro.indexOf('raspbian') !== -1) {
result = 'raspbian'
}
else if (distro.indexOf('reactos') != -1) {
else if (distro.indexOf('reactos') !== -1) {
result = 'reactos'
}
else if (distro.indexOf('redhat') != -1) {
else if (distro.indexOf('redhat') !== -1) {
result = 'redhat'
}
else if (distro.indexOf('slackware') != -1) {
else if (distro.indexOf('slackware') !== -1) {
result = 'slackware'
}
else if (distro.indexOf('sugar') != -1) {
else if (distro.indexOf('sugar') !== -1) {
result = 'sugar'
}
else if (distro.indexOf('steam') != -1) {
else if (distro.indexOf('steam') !== -1) {
result = 'steam'
}
else if (distro.indexOf('suse') != -1) {
else if (distro.indexOf('suse') !== -1) {
result = 'suse'
}
else if (distro.indexOf('mate') != -1) {
else if (distro.indexOf('mate') !== -1) {
result = 'ubuntu-mate'
}
else if (distro.indexOf('lubuntu') != -1) {
else if (distro.indexOf('lubuntu') !== -1) {
result = 'lubuntu'
}
else if (distro.indexOf('xubuntu') != -1) {
else if (distro.indexOf('xubuntu') !== -1) {
result = 'xubuntu'
}
else if (distro.indexOf('ubuntu') != -1) {
else if (distro.indexOf('ubuntu') !== -1) {
result = 'ubuntu'
}
return result;
@ -138,7 +139,7 @@ function osInfo(callback) {
process.nextTick(() => {
let result = {
platform: (_platform == 'Windows_NT' ? 'Windows' : _platform),
platform: (_platform === 'Windows_NT' ? 'Windows' : _platform),
distro: 'unknown',
release: 'unknown',
codename: '',
@ -163,7 +164,7 @@ function osInfo(callback) {
let release = {};
let lines = stdout.toString().split('\n');
lines.forEach(function (line) {
if (line.indexOf('=') != -1) {
if (line.indexOf('=') !== -1) {
release[line.split('=')[0].trim().toUpperCase()] = line.split('=')[1].trim();
}
});
@ -182,11 +183,11 @@ function osInfo(callback) {
exec("sw_vers", function (error, stdout) {
let lines = stdout.toString().split('\n');
lines.forEach(function (line) {
if (line.indexOf('ProductName') != -1) {
if (line.indexOf('ProductName') !== -1) {
result.distro = line.split(':')[1].trim();
result.logofile = getLogoFile(result.distro);
}
if (line.indexOf('ProductVersion') != -1) result.release = line.split(':')[1].trim();
if (line.indexOf('ProductVersion') !== -1) result.release = line.split(':')[1].trim();
});
if (callback) {
callback(result)

View File

@ -19,9 +19,9 @@ const util = require('./util');
let _platform = os.type();
const _linux = (_platform == 'Linux');
const _darwin = (_platform == 'Darwin');
const _windows = (_platform == 'Windows_NT');
const _linux = (_platform === 'Linux');
const _darwin = (_platform === 'Darwin');
const _windows = (_platform === 'Windows_NT');
const NOT_SUPPORTED = 'not supported';
let _process_cpu = {
@ -56,13 +56,13 @@ function services(srv, callback) {
let srvs = srv.split('|');
let comm = (_darwin) ? "ps -caxm -o pcpu,pmem,comm" : "ps axo pcpu,pmem,comm";
let data = [];
if (srv != '' && srvs.length > 0) {
if (srv !== '' && srvs.length > 0) {
exec(comm + " | grep -v grep | egrep '" + srv + "'", function (error, stdout) {
if (!error) {
let lines = stdout.toString().replace(/ +/g, " ").replace(/,+/g, ".").split('\n');
srvs.forEach(function (srv) {
let ps = lines.filter(function (e) {
return e.indexOf(srv) != -1
return e.indexOf(srv) !== -1
});
data.push({
'name': srv,
@ -115,7 +115,7 @@ function processes(callback) {
let result = [];
for (let i = 0; i < head.length; i++) {
if (count <= rights) {
if (head[i] == ' ' && !space) {
if (head[i] === ' ' && !space) {
to = i - 1;
result.push({
from: from,
@ -125,9 +125,9 @@ function processes(callback) {
from = to + 2;
count++;
}
space = head[i] == ' ';
space = head[i] === ' ';
} else {
if (head[i] != ' ' && space) {
if (head[i] !== ' ' && space) {
to = i - 1;
if (from < to) {
result.push({
@ -139,7 +139,7 @@ function processes(callback) {
from = to + 1;
count++;
}
space = head[i] == ' ';
space = head[i] === ' ';
}
}
to = 1000;
@ -153,20 +153,43 @@ function processes(callback) {
}
function parseLine(line) {
let pid = parseInt(line.substring(parsedhead[0].from, parsedhead[0].to));
let pcpu = parseFloat(line.substring(parsedhead[1].from, parsedhead[1].to).replace(/,/g, "."));
let pmem = parseFloat(line.substring(parsedhead[2].from, parsedhead[2].to).replace(/,/g, "."));
let priority = parseInt(line.substring(parsedhead[3].from, parsedhead[3].to));
let vsz = parseInt(line.substring(parsedhead[4].from, parsedhead[4].to));
let rss = parseInt(line.substring(parsedhead[5].from, parsedhead[5].to));
let nice = parseInt(line.substring(parsedhead[6].from, parsedhead[6].to));
let started = line.substring(parsedhead[7].from, parsedhead[7].to).trim();
let state = line.substring(parsedhead[8].from, parsedhead[8].to).trim();
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')))))));
let tty = line.substring(parsedhead[9].from, parsedhead[9].to).trim();
if (tty == '?' || tty == '??') tty = '';
let user = line.substring(parsedhead[10].from, parsedhead[10].to).trim();
let command = line.substring(parsedhead[11].from, parsedhead[11].to).trim().replace(/\[/g, "").replace(/]/g, "");
let offset = 0;
let offset2 = 0;
function checkColumn(i) {
offset = offset2;
offset2 = line.substring(parsedhead[i].to + offset, 1000).indexOf(' ')
// if (line.substring(parsedhead[i].to + offset, parsedhead[i].to + offset + 1) !== ' ') {
// offset2++;
// }
}
checkColumn(0)
let pid = parseInt(line.substring(parsedhead[0].from + offset, parsedhead[0].to + offset2));
checkColumn(1)
let pcpu = parseFloat(line.substring(parsedhead[1].from + offset, parsedhead[1].to + offset2).replace(/,/g, "."));
checkColumn(2)
let pmem = parseFloat(line.substring(parsedhead[2].from + offset, parsedhead[2].to + offset2).replace(/,/g, "."));
checkColumn(3)
let priority = parseInt(line.substring(parsedhead[3].from + offset, parsedhead[3].to + offset2));
checkColumn(4)
let vsz = parseInt(line.substring(parsedhead[4].from + offset, parsedhead[4].to + offset2));
checkColumn(5)
let rss = parseInt(line.substring(parsedhead[5].from + offset, parsedhead[5].to + offset2));
checkColumn(6)
let nice = parseInt(line.substring(parsedhead[6].from + offset, parsedhead[6].to + offset2));
checkColumn(7)
let started = line.substring(parsedhead[7].from + offset, parsedhead[7].to + offset2).trim();
checkColumn(8)
let state = line.substring(parsedhead[8].from + offset, parsedhead[8].to + offset2).trim();
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(9)
let tty = line.substring(parsedhead[9].from + offset, parsedhead[9].to + offset2).trim();
if (tty === '?' || tty === '??') tty = '';
checkColumn(10)
let user = line.substring(parsedhead[10].from + offset, parsedhead[10].to + offset2).trim();
checkColumn(11)
let command = line.substring(parsedhead[11].from + offset, parsedhead[11].to + offset2).trim().replace(/\[/g, "").replace(/]/g, "");
return ({
pid: pid,
@ -190,10 +213,11 @@ function processes(callback) {
let result = [];
if (lines.length > 1) {
let head = lines[0];
parsedhead = parseHead(head, 7);
parsedhead = parseHead(head, 8);
console.log(parsedhead)
lines.shift();
lines.forEach(function (line) {
if (line.trim() != '') {
if (line.trim() !== '') {
result.push(parseLine(line));
}
});
@ -287,7 +311,7 @@ function processes(callback) {
let cmd = "";
if ((_process_cpu.ms && Date.now() - _process_cpu.ms >= 500) || _process_cpu.ms == 0) {
if ((_process_cpu.ms && Date.now() - _process_cpu.ms >= 500) || _process_cpu.ms === 0) {
if (_linux) cmd = "ps axo pid:10,pcpu:6,pmem:6,pri:5,vsz:10,rss:10,ni:5,start:20,state:20,tty:20,user:20,command";
if (_darwin) cmd = "ps acxo pid,pcpu,pmem,pri,vsz,rss,nice,start,state,tty,user,command -r";
exec(cmd, function (error, stdout) {
@ -295,13 +319,13 @@ function processes(callback) {
result.list = parseProcesses(stdout.toString().split('\n'));
result.all = result.list.length;
result.running = result.list.filter(function (e) {
return e.state == 'running'
return e.state === 'running'
}).length;
result.blocked = result.list.filter(function (e) {
return e.state == 'blocked'
return e.state === 'blocked'
}).length;
result.sleeping = result.list.filter(function (e) {
return e.state == 'sleeping'
return e.state === 'sleeping'
}).length;
if (_linux) {

View File

@ -19,9 +19,9 @@ const util = require('./util');
let _platform = os.type();
const _linux = (_platform == 'Linux');
const _darwin = (_platform == 'Darwin');
const _windows = (_platform == 'Windows_NT');
const _linux = (_platform === 'Linux');
const _darwin = (_platform === 'Darwin');
const _windows = (_platform === 'Windows_NT');
const NOT_SUPPORTED = 'not supported';
module.exports = function (callback) {
@ -42,39 +42,39 @@ module.exports = function (callback) {
if (!error) {
let lines = stdout.toString().split('\n');
lines.forEach(function (line) {
if (line.indexOf(':') != -1) {
if (line.toLowerCase().indexOf('manufacturer') != -1) result.manufacturer = result.manufacturer || line.split(':')[1].trim();
if (line.toLowerCase().indexOf('product name') != -1) result.model = line.split(':')[1].trim();
if (line.toLowerCase().indexOf('version') != -1) result.version = result.version || line.split(':')[1].trim();
if (line.toLowerCase().indexOf('serial number') != -1) result.serial = line.split(':')[1].trim();
if (line.toLowerCase().indexOf('uuid') != -1) result.uuid = line.split(':')[1].trim();
if (line.indexOf(':') !== -1) {
if (line.toLowerCase().indexOf('manufacturer') !== -1) result.manufacturer = result.manufacturer || line.split(':')[1].trim();
if (line.toLowerCase().indexOf('product name') !== -1) result.model = line.split(':')[1].trim();
if (line.toLowerCase().indexOf('version') !== -1) result.version = result.version || line.split(':')[1].trim();
if (line.toLowerCase().indexOf('serial number') !== -1) result.serial = line.split(':')[1].trim();
if (line.toLowerCase().indexOf('uuid') !== -1) result.uuid = line.split(':')[1].trim();
}
});
if (result.serial.toLowerCase().indexOf('o.e.m.') != -1) result.serial = '-';
if (result.manufacturer.toLowerCase().indexOf('o.e.m.') != -1) result.manufacturer = '';
if (result.model.toLowerCase().indexOf('o.e.m.') != -1) result.model = 'Computer';
if (result.version.toLowerCase().indexOf('o.e.m.') != -1) result.version = '-';
if (result.serial.toLowerCase().indexOf('o.e.m.') !== -1) result.serial = '-';
if (result.manufacturer.toLowerCase().indexOf('o.e.m.') !== -1) result.manufacturer = '';
if (result.model.toLowerCase().indexOf('o.e.m.') !== -1) result.model = 'Computer';
if (result.version.toLowerCase().indexOf('o.e.m.') !== -1) result.version = '-';
if (result.manufacturer == '' && result.model == 'Computer' && result.version == '-') {
if (result.manufacturer === '' && result.model === 'Computer' && result.version === '-') {
// Check Raspberry Pi
exec("grep Hardware /proc/cpuinfo; grep Serial /proc/cpuinfo; grep Revision /proc/cpuinfo", function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
lines.forEach(function (line) {
if (line.indexOf(':') != -1) {
if (line.toLowerCase().indexOf('hardware') != -1) result.model = line.split(':')[1].trim();
if (line.toLowerCase().indexOf('revision') != -1) result.version = line.split(':')[1].trim();
if (line.toLowerCase().indexOf('serial') != -1) result.serial = line.split(':')[1].trim();
if (line.indexOf(':') !== -1) {
if (line.toLowerCase().indexOf('hardware') !== -1) result.model = line.split(':')[1].trim();
if (line.toLowerCase().indexOf('revision') !== -1) result.version = line.split(':')[1].trim();
if (line.toLowerCase().indexOf('serial') !== -1) result.serial = line.split(':')[1].trim();
}
});
if (result.model == 'BCM2709') {
if (result.model === 'BCM2709') {
result.manufacturer = 'Raspberry Pi Foundation';
result.model = result.model + ' - Pi 2 Model B';
if (['a01041', 'a21041'].indexOf(result.version) >= 0) {
result.version = result.version + ' - Rev. 1.1'
}
}
if (result.model == 'BCM2708') {
if (result.model === 'BCM2708') {
result.manufacturer = 'Raspberry Pi Foundation';
if (['0002', '0003'].indexOf(result.version) >= 0) {
result.model = result.model + ' - Pi Model B';
@ -130,12 +130,12 @@ module.exports = function (callback) {
let lines = stdout.toString().split('\n');
lines.forEach(function (line) {
line = line.replace(/[<>"]/g, "");
if (line.indexOf('=') != -1) {
if (line.toLowerCase().indexOf('manufacturer') != -1) result.manufacturer = line.split('=')[1].trim();
if (line.toLowerCase().indexOf('model') != -1) result.model = line.split('=')[1].trim();
if (line.toLowerCase().indexOf('version') != -1) result.version = line.split('=')[1].trim();
if (line.toLowerCase().indexOf('ioplatformserialnumber') != -1) result.serial = line.split('=')[1].trim();
if (line.toLowerCase().indexOf('ioplatformuuid') != -1) result.uuid = line.split('=')[1].trim();
if (line.indexOf('=') !== -1) {
if (line.toLowerCase().indexOf('manufacturer') !== -1) result.manufacturer = line.split('=')[1].trim();
if (line.toLowerCase().indexOf('model') !== -1) result.model = line.split('=')[1].trim();
if (line.toLowerCase().indexOf('version') !== -1) result.version = line.split('=')[1].trim();
if (line.toLowerCase().indexOf('ioplatformserialnumber') !== -1) result.serial = line.split('=')[1].trim();
if (line.toLowerCase().indexOf('ioplatformuuid') !== -1) result.uuid = line.split('=')[1].trim();
}
});
}
@ -146,7 +146,7 @@ module.exports = function (callback) {
if (_windows) {
exec("wmic csproduct get", function (error, stdout) {
if (!error) {
let lines = stdout.split('\r\n').filter(line => line.trim() != '').filter((line, idx) => idx > 0)[0].trim().split(/\s\s+/);
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0)[0].trim().split(/\s\s+/);
result.manufacturer = lines[5];
result.model = lines[3];
result.version = lines[6];

View File

@ -18,9 +18,9 @@ const util = require('./util');
let _platform = os.type();
const _linux = (_platform == 'Linux');
const _darwin = (_platform == 'Darwin');
const _windows = (_platform == 'Windows_NT');
const _linux = (_platform === 'Linux');
const _darwin = (_platform === 'Darwin');
const _windows = (_platform === 'Windows_NT');
const NOT_SUPPORTED = 'not supported';
// --------------------------
@ -38,7 +38,7 @@ function parseUsers1(lines) {
let is_whopart = true;
lines.forEach(function (line) {
if (line == '---') {
if (line === '---') {
is_whopart = false;
} else {
let l = line.replace(/ +/g, " ").split(' ');
@ -69,9 +69,9 @@ function parseUsers1(lines) {
result_w.command = line.substring(w_pos[7], 1000).trim();
// find corresponding 'who' line
who_line = result_who.filter(function (obj) {
return (obj.user.substring(0, 8).trim() == result_w.user && obj.tty == result_w.tty)
return (obj.user.substring(0, 8).trim() === result_w.user && obj.tty === result_w.tty)
});
if (who_line.length == 1) {
if (who_line.length === 1) {
result.push({
user: who_line[0].user,
tty: who_line[0].tty,
@ -96,7 +96,7 @@ function parseUsers2(lines) {
let is_whopart = true;
lines.forEach(function (line) {
if (line == '---') {
if (line === '---') {
is_whopart = false;
} else {
let l = line.replace(/ +/g, " ").split(' ');
@ -114,13 +114,13 @@ function parseUsers2(lines) {
// split by w_pos
result_w.user = l[0];
result_w.tty = l[1];
result_w.ip = (l[2] != '-') ? l[2] : '';
result_w.ip = (l[2] !== '-') ? l[2] : '';
result_w.command = l.slice(5, 1000).join(' ');
// find corresponding 'who' line
who_line = result_who.filter(function (obj) {
return (obj.user == result_w.user && (obj.tty.substring(3, 1000) == result_w.tty || obj.tty == result_w.tty))
return (obj.user === result_w.user && (obj.tty.substring(3, 1000) === result_w.tty || obj.tty === result_w.tty))
});
if (who_line.length == 1) {
if (who_line.length === 1) {
result.push({
user: who_line[0].user,
tty: who_line[0].tty,
@ -155,7 +155,7 @@ function users(callback) {
// lines / split
let lines = stdout.toString().split('\n');
result = parseUsers1(lines);
if (result.length == 0) {
if (result.length === 0) {
exec("who; echo '---'; w | tail -n +2", function (error, stdout) {
if (!error) {
// lines / split

View File

@ -51,7 +51,7 @@ function sortByKey(array, keys) {
}
function cores() {
if (_cores == 0) {
if (_cores === 0) {
_cores = os.cpus().length;
}
return _cores;