added blockDevices, fixed fsSize, added file system type
This commit is contained in:
parent
3bd3069dfe
commit
609f667a85
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
New Functions
|
New Functions
|
||||||
|
|
||||||
|
- `blockDevices`: returns array of block devices like disks, partitions, raids, roms (new in version 3.10)
|
||||||
- `dockerContainerProcesses`: returns processes for a specific docker container (new in version 3.8)
|
- `dockerContainerProcesses`: returns processes for a specific docker container (new in version 3.8)
|
||||||
- `versions`: returns object of versions - kernel, ssl, node, npm, ...(new in version 3.6)
|
- `versions`: returns object of versions - kernel, ssl, node, npm, ...(new in version 3.6)
|
||||||
- `graphics`: returns arrays of graphics controllers and displays (new in version 3.5)
|
- `graphics`: returns arrays of graphics controllers and displays (new in version 3.5)
|
||||||
@ -88,6 +89,7 @@ Other changes
|
|||||||
|
|
||||||
| Version | Date | Comment |
|
| Version | Date | Comment |
|
||||||
| -------------- | -------------- | -------- |
|
| -------------- | -------------- | -------- |
|
||||||
|
| 3.10.0 | 2016-11-12 | added blockDevices, fixed fsSize, added file system type |
|
||||||
| 3.9.0 | 2016-11-11 | added MAC address to networkInterfaces, fixed currentLoad |
|
| 3.9.0 | 2016-11-11 | added MAC address to networkInterfaces, fixed currentLoad |
|
||||||
| 3.8.1 | 2016-11-04 | updated docs |
|
| 3.8.1 | 2016-11-04 | updated docs |
|
||||||
| 3.8.0 | 2016-11-04 | added dockerContainerProcesses |
|
| 3.8.0 | 2016-11-04 | added dockerContainerProcesses |
|
||||||
|
|||||||
10
README.md
10
README.md
@ -42,6 +42,7 @@ si.cpu()
|
|||||||
|
|
||||||
### Latest Activity
|
### Latest Activity
|
||||||
|
|
||||||
|
- Version 3.10.0: added blockDevices (list of disks, partitions, raids and roms).
|
||||||
- Version 3.9.0: extended networkInterfaces (added MAC address).
|
- Version 3.9.0: extended networkInterfaces (added MAC address).
|
||||||
- Version 3.8.0: added dockerContainerProcesses (array of processes inside a docker container).
|
- Version 3.8.0: added dockerContainerProcesses (array of processes inside a docker container).
|
||||||
- Version 3.7.0: extended docker stats.
|
- Version 3.7.0: extended docker stats.
|
||||||
@ -160,10 +161,19 @@ This library is splitted in several sections:
|
|||||||
| - displays[0].sizey | X | X | size in mm vertical |
|
| - displays[0].sizey | X | X | size in mm vertical |
|
||||||
| si.fsSize(cb) | X | X | returns array of mounted file systems |
|
| si.fsSize(cb) | X | X | returns array of mounted file systems |
|
||||||
| - [0].fs | X | X | name of file system |
|
| - [0].fs | X | X | name of file system |
|
||||||
|
| - [0].type | X | X | type of file system |
|
||||||
| - [0].size | X | X | sizes in Bytes |
|
| - [0].size | X | X | sizes in Bytes |
|
||||||
| - [0].used | X | X | used in Bytes |
|
| - [0].used | X | X | used in Bytes |
|
||||||
| - [0].use | X | X | used in % |
|
| - [0].use | X | X | used in % |
|
||||||
| - [0].mount | X | X | mount point |
|
| - [0].mount | X | X | mount point |
|
||||||
|
| si.blockDevices(cb) | X | X | returns array of disks, partitions,<br>raids and roms |
|
||||||
|
| - [0].name | X | X | name |
|
||||||
|
| - [0].type | X | X | type |
|
||||||
|
| - [0].fstype | X | X | file system type (e.g. ext4) |
|
||||||
|
| - [0].mount | X | X | mount point |
|
||||||
|
| - [0].size | X | X | size in bytes |
|
||||||
|
| - [0].physical | X | X | physical type (HDD, SSD, CD/DVD) |
|
||||||
|
| - [0].uuid | X | X | UUID |
|
||||||
| si.fsStats(cb) | X | X | current transfer stats |
|
| si.fsStats(cb) | X | X | current transfer stats |
|
||||||
| - rx | X | X | bytes read since startup |
|
| - rx | X | X | bytes read since startup |
|
||||||
| - wx | X | X | bytes written since startup |
|
| - wx | X | X | bytes written since startup |
|
||||||
|
|||||||
@ -28,7 +28,7 @@ let _fs_speed = {};
|
|||||||
let _disk_io = {};
|
let _disk_io = {};
|
||||||
|
|
||||||
// --------------------------
|
// --------------------------
|
||||||
// FS - devices
|
// FS - mounted file systems
|
||||||
|
|
||||||
function fsSize(callback) {
|
function fsSize(callback) {
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ function fsSize(callback) {
|
|||||||
reject(error);
|
reject(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
exec("df -lk | grep ^/", function (error, stdout) {
|
exec("df -lkPT | grep ^/", function (error, stdout) {
|
||||||
let data = [];
|
let data = [];
|
||||||
if (!error) {
|
if (!error) {
|
||||||
let lines = stdout.toString().split('\n');
|
let lines = stdout.toString().split('\n');
|
||||||
@ -50,9 +50,10 @@ function fsSize(callback) {
|
|||||||
line = line.replace(/ +/g, " ").split(' ');
|
line = line.replace(/ +/g, " ").split(' ');
|
||||||
data.push({
|
data.push({
|
||||||
'fs': line[0],
|
'fs': line[0],
|
||||||
'size': parseInt(line[1]) * 1024,
|
'type': line[1],
|
||||||
'used': parseInt(line[2]) * 1024,
|
'size': parseInt(line[2]) * 1024,
|
||||||
'use': parseFloat((100.0 * line[2] / line[1]).toFixed(2)),
|
'used': parseInt(line[3]) * 1024,
|
||||||
|
'use': parseFloat((100.0 * line[3] / line[2]).toFixed(2)),
|
||||||
'mount': line[line.length - 1]
|
'mount': line[line.length - 1]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -67,6 +68,67 @@ function fsSize(callback) {
|
|||||||
|
|
||||||
exports.fsSize = fsSize;
|
exports.fsSize = fsSize;
|
||||||
|
|
||||||
|
// --------------------------
|
||||||
|
// disks
|
||||||
|
|
||||||
|
function blockDevices(callback) {
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
process.nextTick(() => {
|
||||||
|
if (_windows) {
|
||||||
|
let error = new Error(NOT_SUPPORTED);
|
||||||
|
if (callback) { callback(NOT_SUPPORTED) }
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
let data = [];
|
||||||
|
if (!error) {
|
||||||
|
let lines = stdout.toString().split('\n');
|
||||||
|
let header = lines[0];
|
||||||
|
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, "");
|
||||||
|
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])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
data = util.unique(data);
|
||||||
|
data = util.sortByKey(data, ['type', 'name']);
|
||||||
|
}
|
||||||
|
if (callback) {
|
||||||
|
callback(data)
|
||||||
|
}
|
||||||
|
resolve(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (_darwin) {
|
||||||
|
// last minute decision to remove code ... not stable
|
||||||
|
let data = [];
|
||||||
|
if (callback) {
|
||||||
|
callback(data)
|
||||||
|
}
|
||||||
|
resolve(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.blockDevices = blockDevices;
|
||||||
|
|
||||||
// --------------------------
|
// --------------------------
|
||||||
// FS - speed
|
// FS - speed
|
||||||
|
|
||||||
|
|||||||
@ -81,6 +81,7 @@
|
|||||||
// --------------------------------
|
// --------------------------------
|
||||||
//
|
//
|
||||||
// version date comment
|
// version date comment
|
||||||
|
// 3.10.0 2016-11-12 added blockDevices, fixed fsSize, added file system type
|
||||||
// 3.9.0 2016-11-11 added MAC address to networkInterfaces, fixed currentLoad
|
// 3.9.0 2016-11-11 added MAC address to networkInterfaces, fixed currentLoad
|
||||||
// 3.8.1 2016-11-04 updated docs
|
// 3.8.1 2016-11-04 updated docs
|
||||||
// 3.8.0 2016-11-04 added dockerContainerProcesses
|
// 3.8.0 2016-11-04 added dockerContainerProcesses
|
||||||
@ -396,6 +397,7 @@ exports.battery = battery;
|
|||||||
exports.graphics = graphics.graphics;
|
exports.graphics = graphics.graphics;
|
||||||
|
|
||||||
exports.fsSize = filesystem.fsSize;
|
exports.fsSize = filesystem.fsSize;
|
||||||
|
exports.blockDevices = filesystem.blockDevices;
|
||||||
exports.fsStats = filesystem.fsStats;
|
exports.fsStats = filesystem.fsStats;
|
||||||
exports.disksIO = filesystem.disksIO;
|
exports.disksIO = filesystem.disksIO;
|
||||||
|
|
||||||
|
|||||||
32
lib/util.js
32
lib/util.js
@ -20,6 +20,36 @@ function isFunction(functionToCheck) {
|
|||||||
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
|
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function unique(obj){
|
||||||
|
var uniques=[];
|
||||||
|
var stringify={};
|
||||||
|
for(var i=0;i<obj.length;i++){
|
||||||
|
var keys=Object.keys(obj[i]);
|
||||||
|
keys.sort(function(a,b) {return a-b});
|
||||||
|
var str='';
|
||||||
|
for(var j=0;j<keys.length;j++){
|
||||||
|
str+= JSON.stringify(keys[j]);
|
||||||
|
str+= JSON.stringify(obj[i][keys[j]]);
|
||||||
|
}
|
||||||
|
if(!stringify.hasOwnProperty(str)){
|
||||||
|
uniques.push(obj[i]);
|
||||||
|
stringify[str]=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return uniques;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sortByKey(array, keys) {
|
||||||
|
return array.sort(function(a, b) {
|
||||||
|
let x ='';
|
||||||
|
let y ='';
|
||||||
|
keys.forEach(function (key) {
|
||||||
|
x = x + a[key]; y = y + b[key];
|
||||||
|
});
|
||||||
|
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function cores() {
|
function cores() {
|
||||||
if (_cores == 0) {
|
if (_cores == 0) {
|
||||||
_cores = os.cpus().length;
|
_cores = os.cpus().length;
|
||||||
@ -28,4 +58,6 @@ function cores() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.isFunction = isFunction;
|
exports.isFunction = isFunction;
|
||||||
|
exports.unique = unique;
|
||||||
|
exports.sortByKey= sortByKey;
|
||||||
exports.cores = cores;
|
exports.cores = cores;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user