update (c) year, blockDevices: added removable attribute

This commit is contained in:
Sebastian Hildebrandt 2017-01-19 09:45:27 +01:00
parent 5821afd5e9
commit d637bd9261
16 changed files with 135 additions and 119 deletions

View File

@ -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 |

View File

@ -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
@ -189,6 +190,7 @@ This library is splitted in several sections:
| - [0].label | X | X | label |
| - [0].model | X | X | model |
| - [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:

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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(' ');
lines.filter(line => line != '').forEach((line) => {
let disk = JSON.parse(line);
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])
'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);
}
});

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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