Bug-Fix disksIO, users, updated docs
This commit is contained in:
parent
eb2316ca4f
commit
8f54a5d1f3
17
README.md
17
README.md
@ -168,9 +168,9 @@ This library is splitted in several sections:
|
||||
| - speed | X | X | in GHz e.g. '3.40' |
|
||||
| - cores | X | X | # cores |
|
||||
| si.cpuCurrentspeed(cb) | X | X | current CPU speed (in GHz)|
|
||||
| - avg | X | | avg CPU speed (all cores) |
|
||||
| - min | X | | min CPU speed (all cores) |
|
||||
| - max | X | | max CPU speed (all cores) |
|
||||
| - avg | X | X | avg CPU speed (all cores) |
|
||||
| - min | X | X | min CPU speed (all cores) |
|
||||
| - max | X | X | max CPU speed (all cores) |
|
||||
| si.cpuTemperature(cb) | X | | CPU temperature (if sensors is installed) |
|
||||
| - main | X | | main temperature |
|
||||
| - cores | X | | array of temperatures |
|
||||
@ -206,7 +206,7 @@ This library is splitted in several sections:
|
||||
| - rIO_sec | X | X | read IO per sec (* see notes) |
|
||||
| - wIO_sec | X | X | write IO per sec (* see notes) |
|
||||
| - tIO_sec | X | X | total IO per sec (* see notes) |
|
||||
| - ms | X | | interval length (for per second values) |
|
||||
| - ms | X | X | interval length (for per second values) |
|
||||
| si.networkInterfaces(cb) | X | X | array of network interfaces |
|
||||
| - [0].iface | X | X | interface name |
|
||||
| - [0].ip4 | X | X | ip4 address |
|
||||
@ -227,7 +227,9 @@ This library is splitted in several sections:
|
||||
| - [0].peeraddress | X | X | peer address |
|
||||
| - [0].peerport | X | X | peer port |
|
||||
| - [0].state | X | X | like ESTABLISHED, TIME_WAIT, ... |
|
||||
| si.currentLoad(cb) | X | X | CPU-Load in % |
|
||||
| si.currentLoad(cb) | X | X | CPU-Load |
|
||||
| - avgload | X | X | average load |
|
||||
| - currentload | X | X | CPU-Load in % |
|
||||
| si.fullLoad(cb) | X | X | CPU-full load since bootup in % |
|
||||
| si.services('mysql, apache2', cb) | X | X | pass comma separated string of services |
|
||||
| - [0].name | X | X | name of service |
|
||||
@ -235,6 +237,9 @@ This library is splitted in several sections:
|
||||
| - [0].pcpu | X | X | process % CPU |
|
||||
| - [0].pmem | X | X | process % MEM |
|
||||
| si.processes(cb) | X | X | # running processes |
|
||||
| - all | X | X | # of all processes |
|
||||
| - running | X | X | # of all processes running |
|
||||
| - blocked | X | X | # of all processes blocked |
|
||||
| si.processLoad('apache2',cb) | X | X | detailed information about given process |
|
||||
| - proc | X | X | process name |
|
||||
| - pid | X | X | PID |
|
||||
@ -314,6 +319,7 @@ I am happy to discuss any comments and suggestions. Please feel free to contact
|
||||
|
||||
| Version | Date | Comment |
|
||||
| -------------- | -------------- | -------- |
|
||||
| 3.0.1 | 2016-08-17 | Bug-Fix disksIO, users, updated docs |
|
||||
| 3.0.0 | 2016-08-03 | new major version 3.0 |
|
||||
| 2.0.5 | 2016-03-02 | changed .gitignore |
|
||||
| 2.0.4 | 2016-02-22 | tiny correction - removed double quotes CPU brand, ... |
|
||||
@ -353,6 +359,7 @@ Written by Sebastian Hildebrandt [sebhildebrandt](https://github.com/sebhildebra
|
||||
- Guillaume Legrain [glegrain](https://github.com/glegrain)
|
||||
- Riccardo Novaglia [richy24](https://github.com/richy24)
|
||||
- Quentin Busuttil [Buzut](https://github.com/Buzut)
|
||||
- lapsio [lapsio](https://github.com/lapsio)
|
||||
|
||||
## Copyright Information
|
||||
|
||||
|
||||
109
lib/index.js
109
lib/index.js
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
// ==================================================================================
|
||||
@ -77,6 +78,7 @@
|
||||
// --------------------------------
|
||||
//
|
||||
// version date comment
|
||||
// 3.0.1 2016-08-17 Bug-Fix disksIO, users, updated docs
|
||||
// 3.0.0 2016-08-03 new major version 3.0
|
||||
// 2.0.5 2016-02-22 some more tiny correction ...
|
||||
// 2.0.4 2016-02-22 tiny correction - removed double quotes CPU brand, ...
|
||||
@ -988,13 +990,13 @@ function disksIO(callback) {
|
||||
result.tIO = result.rIO + result.wIO;
|
||||
if (_disk_io && _disk_io.ms) {
|
||||
result.ms = Date.now() - _disk_io.ms;
|
||||
result.rIOPS = (result.rIO - _disk_io.rIO) / (result.ms / 1000);
|
||||
result.wIOPS = (result.wIO - _disk_io.wIO) / (result.ms / 1000);
|
||||
result.tIOPS = result.rIOPS + result.wIOPS;
|
||||
result.rIO_sec = (result.rIO - _disk_io.rIO) / (result.ms / 1000);
|
||||
result.wIO_sec = (result.wIO - _disk_io.wIO) / (result.ms / 1000);
|
||||
result.tIO_sec = result.rIO_sec + result.wIO_sec;
|
||||
} else {
|
||||
result.rIOPS = -1;
|
||||
result.wIOPS = -1;
|
||||
result.tIOPS = -1;
|
||||
result.rIO_sec = -1;
|
||||
result.wIO_sec = -1;
|
||||
result.tIO_sec = -1;
|
||||
}
|
||||
_disk_io.rIO = result.rIO;
|
||||
_disk_io.wIO = result.wIO;
|
||||
@ -1361,7 +1363,7 @@ function getLoad() {
|
||||
result.avgload = parseFloat((Math.max.apply(Math, loads)).toFixed(2));
|
||||
result.currentload = -1;
|
||||
|
||||
let cmd = (_darwin) ? "ps -caxm -o pcpu" : "ps axo pcpu";
|
||||
let cmd = (_darwin) ? "ps -cax -o pcpu" : "ps axo pcpu";
|
||||
exec(cmd, function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().replace(/,+/g, ".").split('\n');
|
||||
@ -1658,16 +1660,7 @@ exports.processLoad = processLoad;
|
||||
// --------------------------
|
||||
// array of users online = sessions
|
||||
|
||||
function users(callback) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
process.nextTick(() => {
|
||||
if (_windows) {
|
||||
let error = new Error(NOT_SUPPORTED);
|
||||
if (callback) { callback(NOT_SUPPORTED) }
|
||||
reject(error);
|
||||
}
|
||||
|
||||
function parseUsers1(lines) {
|
||||
var result = [];
|
||||
var result_who = [];
|
||||
var result_w = {};
|
||||
@ -1677,12 +1670,6 @@ function users(callback) {
|
||||
var w_headerline = '';
|
||||
var who_line = {};
|
||||
|
||||
// linux
|
||||
if (_linux) {
|
||||
exec("who --ips; echo '---'; w | tail -n +2", function (error, stdout) {
|
||||
if (!error) {
|
||||
// lines / split
|
||||
var lines = stdout.toString().split('\n');
|
||||
var is_whopart = true;
|
||||
lines.forEach(function (line) {
|
||||
if (line == '---') {
|
||||
@ -1697,7 +1684,7 @@ function users(callback) {
|
||||
tty: l[1],
|
||||
date: l[2],
|
||||
time: l[3],
|
||||
ip: (l && l.length > 4) ? l[4] : ''
|
||||
ip: (l && l.length > 4) ? l[4].replace(/\(/g, "").replace(/\)/g, "") : ''
|
||||
})
|
||||
} else {
|
||||
// w part
|
||||
@ -1714,7 +1701,7 @@ function users(callback) {
|
||||
// split by w_pos
|
||||
result_w.user = line.substring(w_pos[0], w_pos[1]-1).trim();
|
||||
result_w.tty = line.substring(w_pos[1], w_pos[2]-1).trim();
|
||||
result_w.ip = line.substring(w_pos[2], w_pos[3]-1).trim();
|
||||
result_w.ip = line.substring(w_pos[2], w_pos[3]-1).replace(/\(/g, "").replace(/\)/g, "").trim();
|
||||
result_w.command = line.substring(w_pos[7], 1000).trim();
|
||||
// console.log(result_w);
|
||||
// find corresponding 'who' line
|
||||
@ -1735,20 +1722,15 @@ function users(callback) {
|
||||
}
|
||||
}
|
||||
});
|
||||
if (callback) { callback(result) }
|
||||
resolve(result);
|
||||
} else {
|
||||
if (callback) { callback(result) }
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
if (_darwin) {
|
||||
exec("who; echo '---'; w -ih", function (error, stdout) {
|
||||
if (!error) {
|
||||
// lines / split
|
||||
var lines = stdout.toString().split('\n');
|
||||
function parseUsers2(lines) {
|
||||
var result = [];
|
||||
var result_who = [];
|
||||
var result_w = {};
|
||||
var who_line = {};
|
||||
|
||||
var is_whopart = true;
|
||||
lines.forEach(function (line) {
|
||||
if (line == '---') {
|
||||
@ -1788,6 +1770,59 @@ function users(callback) {
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
function users(callback) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
process.nextTick(() => {
|
||||
if (_windows) {
|
||||
let error = new Error(NOT_SUPPORTED);
|
||||
if (callback) { callback(NOT_SUPPORTED) }
|
||||
reject(error);
|
||||
}
|
||||
|
||||
var result = [];
|
||||
|
||||
// linux
|
||||
if (_linux) {
|
||||
exec("who --ips; echo '---'; w | tail -n +2", function (error, stdout) {
|
||||
if (!error) {
|
||||
// lines / split
|
||||
var lines = stdout.toString().split('\n');
|
||||
result = parseUsers1(lines);
|
||||
if (result.length == 0) {
|
||||
exec("who; echo '---'; w | tail -n +2", function (error, stdout) {
|
||||
if (!error) {
|
||||
// lines / split
|
||||
lines = stdout.toString().split('\n');
|
||||
result = parseUsers1(lines);
|
||||
if (callback) { callback(result) }
|
||||
resolve(result);
|
||||
} else {
|
||||
if (callback) { callback(result) }
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (callback) { callback(result) }
|
||||
resolve(result);
|
||||
}
|
||||
} else {
|
||||
if (callback) { callback(result) }
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (_darwin) {
|
||||
exec("who; echo '---'; w -ih", function (error, stdout) {
|
||||
if (!error) {
|
||||
// lines / split
|
||||
var lines = stdout.toString().split('\n');
|
||||
result = parseUsers2(lines);
|
||||
|
||||
if (callback) { callback(result) }
|
||||
resolve(result);
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user