diff --git a/CHANGELOG.md b/CHANGELOG.md index 79eb53f..bd8acd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -94,6 +94,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.16.0 | 2017-01-19 | blockDevices: added removable attribute + fix | | 3.15.1 | 2017-01-17 | minor cpuTemperature fix (OSX) | | 3.15.0 | 2017-01-15 | added cpuTemperature also for OSX | | 3.14.0 | 2017-01-14 | added currentLoad per cpu/core, cpu cache and cpu flags | diff --git a/README.md b/README.md index aff69b3..90fe4e6 100644 --- a/README.md +++ b/README.md @@ -42,22 +42,23 @@ si.cpu() ### Latest Activity -- 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). -- Version 3.10.0: added blockDevices (list of disks, partitions, raids and roms). -- Version 3.9.0: extended networkInterfaces (added MAC address). -- Version 3.8.0: added dockerContainerProcesses (array of processes inside a docker container). -- Version 3.7.0: extended docker stats. -- Version 3.6.0: added versions (kernel, ssl, node, npm, pm2, ...). -- Version 3.5.0: added graphics info (controller and display). -- Version 3.4.0: rewritten currentLoad and CPU load for processes (linux). This is now much more accurate. -- Version 3.3.0: added process list. Get full process list including details like cpu and mem usage, status, command, ... -- Version 3.2.0: added battery support. If a battery is installed, you get information about status and current capacity level +- 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.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). +- Version 3.10.0: added `blockDevices` (list of disks, partitions, raids and roms). +- Version 3.9.0: extended `networkInterfaces` (added MAC address). +- Version 3.8.0: added `dockerContainerProcesses` (array of processes inside a docker container). +- Version 3.7.0: extended `dockerContainerStats`. +- Version 3.6.0: added `versions` (kernel, ssl, node, npm, pm2, ...). +- Version 3.5.0: added `graphics` info (controller and display). +- Version 3.4.0: rewritten `currentLoad` and CPU load for processes (linux). This is now much more accurate. +- Version 3.3.0: added `processes.list`. Get full process list including details like cpu and mem usage, status, command, ... +- Version 3.2.0: added `battery` support. If a battery is installed, you get information about status and current capacity level - Version 3.1.0: added [Docker][docker-url] support. Now you can scan your docker containers and get their stats -- Version 3.0.0: added DisksIO - overall diskIO and IOPS values for all mounted volumes +- Version 3.0.0: added `disksIO` - overall diskIO and IOPS values for all mounted volumes ### Changelog @@ -188,7 +189,8 @@ This library is splitted in several sections: | - [0].uuid | X | X | UUID | | - [0].label | X | X | label | | - [0].model | X | X | model | -| - [0].serial | X | | serial | +| - [0].serial | X | | serial | +| - [0].removable | X | X | serial | | - [0].protocol | X | X | protocol (SATA, PCI-Express, ...) | | si.fsStats(cb) | X | X | current transfer stats | | - rx | X | X | bytes read since startup | @@ -381,6 +383,7 @@ Written by Sebastian Hildebrandt [sebhildebrandt](https://github.com/sebhildebra - Riccardo Novaglia [richy24](https://github.com/richy24) - Quentin Busuttil [Buzut](https://github.com/Buzut) - lapsio [lapsio](https://github.com/lapsio) +- csy [csy](https://github.com/csy1983) OSX Temperature: Credits here are going to: diff --git a/lib/battery.js b/lib/battery.js index 0e626d2..fff2f06 100644 --- a/lib/battery.js +++ b/lib/battery.js @@ -1,10 +1,10 @@ 'use strict'; // ================================================================================== -// index.js +// battery.js // ---------------------------------------------------------------------------------- // Description: System Information - library // for Node.js -// Copyright: (c) 2014 - 2016 +// Copyright: (c) 2014 - 2017 // Author: Sebastian Hildebrandt // ---------------------------------------------------------------------------------- // License: MIT diff --git a/lib/cpu.js b/lib/cpu.js index 9e1d06a..ad507df 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -1,10 +1,10 @@ 'use strict'; // ================================================================================== -// index.js +// cpu.js // ---------------------------------------------------------------------------------- // Description: System Information - library // for Node.js -// Copyright: (c) 2014 - 2016 +// Copyright: (c) 2014 - 2017 // Author: Sebastian Hildebrandt // ---------------------------------------------------------------------------------- // License: MIT diff --git a/lib/docker.js b/lib/docker.js index e4038fc..1360582 100644 --- a/lib/docker.js +++ b/lib/docker.js @@ -1,10 +1,10 @@ 'use strict'; // ================================================================================== -// index.js +// docker.js // ---------------------------------------------------------------------------------- // Description: System Information - library // for Node.js -// Copyright: (c) 2014 - 2016 +// Copyright: (c) 2014 - 2017 // Author: Sebastian Hildebrandt // ---------------------------------------------------------------------------------- // License: MIT diff --git a/lib/filesystem.js b/lib/filesystem.js index 3a54559..2626945 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -1,10 +1,10 @@ 'use strict'; // ================================================================================== -// index.js +// filesystem.js // ---------------------------------------------------------------------------------- // Description: System Information - library // for Node.js -// Copyright: (c) 2014 - 2016 +// Copyright: (c) 2014 - 2017 // Author: Sebastian Hildebrandt // ---------------------------------------------------------------------------------- // License: MIT @@ -36,7 +36,9 @@ function fsSize(callback) { process.nextTick(() => { if (_windows) { let error = new Error(NOT_SUPPORTED); - if (callback) { callback(NOT_SUPPORTED) } + if (callback) { + callback(NOT_SUPPORTED) + } reject(error); } @@ -60,7 +62,9 @@ function fsSize(callback) { } }); } - if (callback) { callback(data) } + if (callback) { + callback(data) + } resolve(data); }); }); @@ -98,13 +102,16 @@ function parseDevices(lines) { 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 ('VOLUMENAME' == parts[0]) { if (parts[1].indexOf('Not applicable') == -1) devices[i].label = 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]; @@ -113,6 +120,7 @@ function parseDevices(lines) { 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]; } @@ -122,80 +130,79 @@ function parseDevices(lines) { return devices; } -function fromTo(header, label) { - let from = header.indexOf(label); - let to = from + label.length; - for (let i = to; i < header.length && header[i] == ' '; i++) { - to = i - } - return { - from: from, - to: to - } -} - function parseBlk(lines) { - let header = lines[0]; - let ft_label = fromTo(header, 'LABEL'); - let ft_model = fromTo(header, 'MODEL'); - let ft_serial = fromTo(header, 'SERIAL'); - lines.splice(0, 1); - let data = []; - lines.forEach(orgline => { - if (orgline != '') { - if (orgline.substr(header.indexOf('FSTYPE'), 1) == ' ') { orgline = orgline.substr(0, header.indexOf('FSTYPE')) + '-' + orgline.substr(header.indexOf('FSTYPE') + 1, 1000)} - if (orgline.substr(header.indexOf('MOUNTPOINT'), 1) == ' ') { orgline = orgline.substr(0, header.indexOf('MOUNTPOINT')) + '-' + orgline.substr(header.indexOf('MOUNTPOINT') + 1, 1000)} - if (orgline.substr(header.indexOf('UUID'), 1) == ' ') { orgline = orgline.substr(0, header.indexOf('UUID')) + '-' + orgline.substr(header.indexOf('UUID') + 1, 1000)} - if (orgline.substr(header.indexOf('TRAN'), 1) == ' ') { orgline = orgline.substr(0, header.indexOf('TRAN')) + '-' + orgline.substr(header.indexOf('TRAN') + 1, 1000)} - let line = orgline.replace(/[├─│└]+/g, ""); - line = line.replace(/ +/g, " ").trim().split(' '); - data.push({ - 'name': line[0], - 'type': line[1], - 'fstype': (line[3] == '-' ? '' : line[3]), - 'mount': (line[4] == '-' ? '' : line[4]), - 'size': parseInt(line[2]), - 'physical': (line[1] == 'disk' ? (line[6] == '0' ? 'SSD' : 'HDD') : (line[1] == 'rom' ? 'CD/DVD' : '')), - 'uuid': (line[5] == '-' ? '' : line[5]), - 'label': orgline.substring(ft_label.from, ft_label.to).trim(), - 'model': orgline.substring(ft_model.from, ft_model.to).trim(), - 'serial': (ft_serial.from >= 0 ? orgline.substring(ft_serial.from, ft_serial.to).trim() : ''), - 'protocol': (ft_serial.from >= 0 && line[8] == '-' ? '' : line[8]) - }) - } + + lines.filter(line => line != '').forEach((line) => { + let disk = JSON.parse(line); + data.push({ + 'name': disk.name, + 'type': disk.type, + 'fstype': disk.fstype, + 'mount': disk.mountpoint, + 'size': parseInt(disk.size), + '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', + 'protocol': disk.tran + }) }); + data = util.unique(data); data = util.sortByKey(data, ['type', 'name']); return data; } +function blkStdoutToObject(stdout) { + return stdout.toString() + .replace(/NAME=/g, '{"name":') + .replace(/FSTYPE=/g, ',"fstype":') + .replace(/TYPE=/g, ',"type":') + .replace(/SIZE=/g, ',"size":') + .replace(/MOUNTPOINT=/g, ',"mountpoint":') + .replace(/UUID=/g, ',"uuid":') + .replace(/ROTA=/g, ',"rota":') + .replace(/RO=/g, ',"ro":') + .replace(/RM=/g, ',"rm":') + .replace(/TRAN=/g, ',"tran":') + .replace(/SERIAL=/g, ',"serial":') + .replace(/LABEL=/g, ',"label":') + .replace(/MODEL=/g, ',"model":') + .replace(/OWNER=/g, ',"owner":') + .replace(/\n/g, '}\n'); +} + function blockDevices(callback) { return new Promise((resolve, reject) => { process.nextTick(() => { if (_windows) { let error = new Error(NOT_SUPPORTED); - if (callback) { callback(NOT_SUPPORTED) } + if (callback) { + callback(NOT_SUPPORTED) + } reject(error); } if (_linux) { // see https://wiki.ubuntuusers.de/lsblk/ // exec("lsblk -bo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,TRAN,SERIAL,LABEL,MODEL,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,SCHED,RQ-SIZE,RA,WSAME", function (error, stdout) { - exec("lsblk -bo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,TRAN,SERIAL,LABEL,MODEL,OWNER", function (error, stdout) { + exec("lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,TRAN,SERIAL,LABEL,MODEL,OWNER", function (error, stdout) { let data = []; if (!error) { - let lines = stdout.toString().split('\n'); + let lines = blkStdoutToObject(stdout).split('\n'); data = parseBlk(lines); if (callback) { callback(data) } resolve(data); } else { - exec("lsblk -bo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,LABEL,MODEL,OWNER", function (error, stdout) { + exec("lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER", function (error, stdout) { if (!error) { - let lines = stdout.toString().split('\n'); + let lines = blkStdoutToObject(stdout).split('\n'); data = parseBlk(lines); } if (callback) { @@ -207,7 +214,6 @@ function blockDevices(callback) { }); } if (_darwin) { - // last minute decision to remove code ... not stable exec("diskutil info -all", function (error, stdout) { let data = []; if (!error) { @@ -279,7 +285,9 @@ function fsStats(callback) { process.nextTick(() => { if (_windows) { let error = new Error(NOT_SUPPORTED); - if (callback) { callback(NOT_SUPPORTED) } + if (callback) { + callback(NOT_SUPPORTED) + } reject(error); } @@ -324,11 +332,15 @@ function fsStats(callback) { }); result = calcFsSpeed(rx, wx); } - if (callback) { callback(result) } + if (callback) { + callback(result) + } resolve(result); }) } else { - if (callback) { callback(result) } + if (callback) { + callback(result) + } resolve(result); } }) @@ -348,7 +360,9 @@ function fsStats(callback) { }); result = calcFsSpeed(rx, wx); } - if (callback) { callback(result) } + if (callback) { + callback(result) + } resolve(result); }) } @@ -360,7 +374,9 @@ function fsStats(callback) { result.rx_sec = _fs_speed.rx_sec; result.wx_sec = _fs_speed.wx_sec; result.tx_sec = _fs_speed.tx_sec; - if (callback) { callback(result) } + if (callback) { + callback(result) + } resolve(result); } }); @@ -415,7 +431,9 @@ function disksIO(callback) { process.nextTick(() => { if (_windows) { let error = new Error(NOT_SUPPORTED); - if (callback) { callback(NOT_SUPPORTED) } + if (callback) { + callback(NOT_SUPPORTED) + } reject(error); } @@ -452,10 +470,14 @@ function disksIO(callback) { }); result = calcDiskIO(rIO, wIO); - if (callback) { callback(result) } + if (callback) { + callback(result) + } resolve(result); } else { - if (callback) { callback(result) } + if (callback) { + callback(result) + } resolve(result); } }); @@ -475,7 +497,9 @@ function disksIO(callback) { }); result = calcDiskIO(rIO, wIO); } - if (callback) { callback(result) } + if (callback) { + callback(result) + } resolve(result); }) } @@ -487,7 +511,9 @@ function disksIO(callback) { result.rIO_sec = _disk_io.rIO_sec; result.wIO_sec = _disk_io.wIO_sec; result.tIO_sec = _disk_io.tIO_sec; - if (callback) { callback(result) } + if (callback) { + callback(result) + } resolve(result); } }); diff --git a/lib/graphics.js b/lib/graphics.js index cef03da..c019d8b 100644 --- a/lib/graphics.js +++ b/lib/graphics.js @@ -1,10 +1,10 @@ 'use strict'; // ================================================================================== -// index.js +// graphics.js // ---------------------------------------------------------------------------------- // Description: System Information - library // for Node.js -// Copyright: (c) 2014 - 2016 +// Copyright: (c) 2014 - 2017 // Author: Sebastian Hildebrandt // ---------------------------------------------------------------------------------- // License: MIT diff --git a/lib/index.js b/lib/index.js index 0ecdf41..4841b86 100644 --- a/lib/index.js +++ b/lib/index.js @@ -4,13 +4,14 @@ // ---------------------------------------------------------------------------------- // Description: System Information - library // for Node.js -// Copyright: (c) 2014 - 2016 +// Copyright: (c) 2014 - 2017 // Author: Sebastian Hildebrandt // ---------------------------------------------------------------------------------- // Contributors: Guillaume Legrain (https://github.com/glegrain) // Riccardo Novaglia (https://github.com/richy24) // Quentin Busuttil (https://github.com/Buzut) // Lapsio (https://github.com/lapsio) +// csy (https://github.com/csy1983) // ---------------------------------------------------------------------------------- // License: MIT // ================================================================================== @@ -81,6 +82,7 @@ // -------------------------------- // // version date comment +// 3.16.0 2017-01-19 blockDevices: added removable attribute + fix // 3.15.1 2017-01-17 minor cpuTemperature fix (OSX) // 3.15.0 2017-01-15 added cpuTemperature also for OSX // 3.14.0 2017-01-14 added currentLoad per cpu/core, cpu cache (L1, L2, L3) and cpu flags diff --git a/lib/internet.js b/lib/internet.js index 6ba05d0..3fe9b0e 100644 --- a/lib/internet.js +++ b/lib/internet.js @@ -1,10 +1,10 @@ 'use strict'; // ================================================================================== -// index.js +// internet.js // ---------------------------------------------------------------------------------- // Description: System Information - library // for Node.js -// Copyright: (c) 2014 - 2016 +// Copyright: (c) 2014 - 2017 // Author: Sebastian Hildebrandt // ---------------------------------------------------------------------------------- // License: MIT diff --git a/lib/memory.js b/lib/memory.js index f4b3b3c..1f5a4e7 100644 --- a/lib/memory.js +++ b/lib/memory.js @@ -1,10 +1,10 @@ 'use strict'; // ================================================================================== -// index.js +// memory.js // ---------------------------------------------------------------------------------- // Description: System Information - library // for Node.js -// Copyright: (c) 2014 - 2016 +// Copyright: (c) 2014 - 2017 // Author: Sebastian Hildebrandt // ---------------------------------------------------------------------------------- // License: MIT diff --git a/lib/network.js b/lib/network.js index 64c47d4..f3a45c9 100644 --- a/lib/network.js +++ b/lib/network.js @@ -1,10 +1,10 @@ 'use strict'; // ================================================================================== -// index.js +// network.js // ---------------------------------------------------------------------------------- // Description: System Information - library // for Node.js -// Copyright: (c) 2014 - 2016 +// Copyright: (c) 2014 - 2017 // Author: Sebastian Hildebrandt // ---------------------------------------------------------------------------------- // License: MIT diff --git a/lib/osinfo.js b/lib/osinfo.js index 1d64a34..548e78d 100644 --- a/lib/osinfo.js +++ b/lib/osinfo.js @@ -1,17 +1,12 @@ 'use strict'; // ================================================================================== -// index.js +// osinfo.js // ---------------------------------------------------------------------------------- // Description: System Information - library // for Node.js -// Copyright: (c) 2014 - 2016 +// Copyright: (c) 2014 - 2017 // Author: Sebastian Hildebrandt // ---------------------------------------------------------------------------------- -// Contributors: Guillaume Legrain (https://github.com/glegrain) -// Riccardo Novaglia (https://github.com/richy24) -// Quentin Busuttil (https://github.com/Buzut) -// Lapsio (https://github.com/lapsio) -// ---------------------------------------------------------------------------------- // License: MIT // ================================================================================== // 3. Operating System @@ -152,14 +147,8 @@ function osInfo(callback) { exports.osInfo = osInfo; function versions(callback) { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { process.nextTick(() => { - if (_windows) { - let error = new Error(NOT_SUPPORTED); - if (callback) { callback(NOT_SUPPORTED) } - reject(error); - } - let result = { kernel: os.release(), node: process.versions.node, diff --git a/lib/processes.js b/lib/processes.js index 6e63eb6..83222e4 100644 --- a/lib/processes.js +++ b/lib/processes.js @@ -1,10 +1,10 @@ 'use strict'; // ================================================================================== -// index.js +// processes.js // ---------------------------------------------------------------------------------- // Description: System Information - library // for Node.js -// Copyright: (c) 2014 - 2016 +// Copyright: (c) 2014 - 2017 // Author: Sebastian Hildebrandt // ---------------------------------------------------------------------------------- // License: MIT diff --git a/lib/system.js b/lib/system.js index 4cb8691..ad077c3 100644 --- a/lib/system.js +++ b/lib/system.js @@ -1,17 +1,12 @@ 'use strict'; // ================================================================================== -// index.js +// system.js // ---------------------------------------------------------------------------------- // Description: System Information - library // for Node.js -// Copyright: (c) 2014 - 2016 +// Copyright: (c) 2014 - 2017 // Author: Sebastian Hildebrandt // ---------------------------------------------------------------------------------- -// Contributors: Guillaume Legrain (https://github.com/glegrain) -// Riccardo Novaglia (https://github.com/richy24) -// Quentin Busuttil (https://github.com/Buzut) -// Lapsio (https://github.com/lapsio) -// ---------------------------------------------------------------------------------- // License: MIT // ================================================================================== // 2. System (Hardware) diff --git a/lib/users.js b/lib/users.js index a10989d..eb69971 100644 --- a/lib/users.js +++ b/lib/users.js @@ -1,10 +1,10 @@ 'use strict'; // ================================================================================== -// index.js +// users.js // ---------------------------------------------------------------------------------- // Description: System Information - library // for Node.js -// Copyright: (c) 2014 - 2016 +// Copyright: (c) 2014 - 2017 // Author: Sebastian Hildebrandt // ---------------------------------------------------------------------------------- // License: MIT diff --git a/lib/util.js b/lib/util.js index 9452eaf..3bc4a8a 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,10 +1,10 @@ 'use strict'; // ================================================================================== -// index.js +// utils.js // ---------------------------------------------------------------------------------- // Description: System Information - library // for Node.js -// Copyright: (c) 2014 - 2016 +// Copyright: (c) 2014 - 2017 // Author: Sebastian Hildebrandt // ---------------------------------------------------------------------------------- // License: MIT