blockDevices for OSX and extended blockDevices
This commit is contained in:
parent
fe52540499
commit
3e1669e3fb
@ -89,6 +89,7 @@ Other changes
|
||||
|
||||
| Version | Date | Comment |
|
||||
| -------------- | -------------- | -------- |
|
||||
| 3.11.0 | 2016-11-15 | blockDevices for OSX and extended blockDevices |
|
||||
| 3.10.2 | 2016-11-14 | bug fix fsSize on OSX |
|
||||
| 3.10.1 | 2016-11-14 | optimization fsStats, disksIO, networkStats |
|
||||
| 3.10.0 | 2016-11-12 | added blockDevices, fixed fsSize, added file system type |
|
||||
|
||||
@ -10,7 +10,7 @@ Simple system and OS information library for [node.js][nodejs-url]
|
||||
|
||||
## Quick Start
|
||||
|
||||
Collection of 25+ functions to retrieve detailed hardware, system and OS information (linux and OSX only)
|
||||
Collection of 30+ functions to retrieve detailed hardware, system and OS information (linux and OSX only)
|
||||
|
||||
### Installation
|
||||
|
||||
@ -42,6 +42,7 @@ si.cpu()
|
||||
|
||||
### Latest Activity
|
||||
|
||||
- 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).
|
||||
@ -174,6 +175,10 @@ This library is splitted in several sections:
|
||||
| - [0].size | X | X | size in bytes |
|
||||
| - [0].physical | X | X | physical type (HDD, SSD, CD/DVD) |
|
||||
| - [0].uuid | X | X | UUID |
|
||||
| - [0].label | X | X | label |
|
||||
| - [0].model | X | X | model |
|
||||
| - [0].serial | 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 |
|
||||
| - wx | X | X | bytes written since startup |
|
||||
|
||||
@ -72,6 +72,68 @@ exports.fsSize = fsSize;
|
||||
// --------------------------
|
||||
// disks
|
||||
|
||||
function parseBytes(s) {
|
||||
return parseInt(s.substr(s.indexOf(' (')+2, s.indexOf(' Bytes)')-10))
|
||||
}
|
||||
|
||||
function parseDevices (lines) {
|
||||
let devices = [];
|
||||
let i = 0;
|
||||
lines.forEach(line => {
|
||||
if (line.length > 0) {
|
||||
if (line[0] == '*') {
|
||||
i++;
|
||||
} else {
|
||||
let parts = line.split(':');
|
||||
if (parts.length > 1) {
|
||||
if (!devices[i]) devices[i] = {
|
||||
name: '',
|
||||
identifier: '',
|
||||
type: 'disk',
|
||||
fstype: '',
|
||||
mount: '',
|
||||
size: 0,
|
||||
physical: 'HDD',
|
||||
uuid: '',
|
||||
label: '',
|
||||
model: '',
|
||||
serial: '',
|
||||
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 ('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 ('PARTITIONTYPE' == parts[0]) devices[i].type = 'part';
|
||||
if ('DEVICE/MEDIANAME' == parts[0]) devices[i].model = parts[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
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
|
||||
}
|
||||
console.log(label + ' - ' + from + ' ' + to);
|
||||
return {
|
||||
from: from,
|
||||
to: to
|
||||
}
|
||||
}
|
||||
function blockDevices(callback) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -83,18 +145,23 @@ function blockDevices(callback) {
|
||||
}
|
||||
|
||||
if (_linux) {
|
||||
exec("lsblk -bo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,OWNER,GROUP,MODE,LABEL,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,SCHED,RQ-SIZE,RA,WSAME", function (error, stdout) {
|
||||
// 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) {
|
||||
let data = [];
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
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);
|
||||
lines.forEach(function (line) {
|
||||
if (line != '') {
|
||||
if (line.substr(header.indexOf('FSTYPE'), 1) == ' ') { line = line.substr(0, header.indexOf('FSTYPE')) + '-' + line.substr(header.indexOf('FSTYPE') + 1, 1000)}
|
||||
if (line.substr(header.indexOf('MOUNTPOINT'), 1) == ' ') { line = line.substr(0, header.indexOf('MOUNTPOINT')) + '-' + line.substr(header.indexOf('MOUNTPOINT') + 1, 1000)}
|
||||
if (line.substr(header.indexOf('UUID'), 1) == ' ') { line = line.substr(0, header.indexOf('UUID')) + '-' + line.substr(header.indexOf('UUID') + 1, 1000)}
|
||||
line = line.replace(/[├─│└]+/g, "");
|
||||
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],
|
||||
@ -103,7 +170,11 @@ function blockDevices(callback) {
|
||||
'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])
|
||||
'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': orgline.substring(ft_serial.from, ft_serial.to).trim(),
|
||||
'protocol': (line[8] == '-' ? '' : line[8])
|
||||
})
|
||||
}
|
||||
});
|
||||
@ -118,11 +189,18 @@ function blockDevices(callback) {
|
||||
}
|
||||
if (_darwin) {
|
||||
// last minute decision to remove code ... not stable
|
||||
let data = [];
|
||||
if (callback) {
|
||||
callback(data)
|
||||
}
|
||||
resolve(data);
|
||||
exec("diskutil info -all", function (error, stdout) {
|
||||
let data = [];
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
// parse lines into temp array of devices
|
||||
data = parseDevices(lines);
|
||||
}
|
||||
if (callback) {
|
||||
callback(data)
|
||||
}
|
||||
resolve(data);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -81,6 +81,7 @@
|
||||
// --------------------------------
|
||||
//
|
||||
// version date comment
|
||||
// 3.11.0 2016-11-15 blockDevices for OSX and extended blockDevices
|
||||
// 3.10.2 2016-11-14 bug fix fsSize on OSX
|
||||
// 3.10.1 2016-11-14 optimization fsStats, disksIO, networkStats
|
||||
// 3.10.0 2016-11-12 added blockDevices, fixed fsSize, added file system type
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user