added battery, bugfix disksIO
This commit is contained in:
+142
-25
@@ -22,13 +22,14 @@
|
||||
// 3. OS - Operating System
|
||||
// 4. CPU
|
||||
// 5. Memory
|
||||
// 6. File System
|
||||
// 7. Network
|
||||
// 8. Processes
|
||||
// 9. Users/Sessions
|
||||
// 10. Internet
|
||||
// 11. Docker
|
||||
// 12. GetAll - get all data
|
||||
// 6. Battery
|
||||
// 7. File System
|
||||
// 8. Network
|
||||
// 9. Processes
|
||||
// 10. Users/Sessions
|
||||
// 11. Internet
|
||||
// 12. Docker
|
||||
// 13. GetAll - get all data
|
||||
//
|
||||
// ==================================================================================
|
||||
//
|
||||
@@ -79,6 +80,8 @@
|
||||
// --------------------------------
|
||||
//
|
||||
// version date comment
|
||||
// 3.2.0 2016-08-19 added battery info
|
||||
// 3.1.1 2016-08-18 improved system and os detection (vm, ...), bugfix disksIO
|
||||
// 3.1.0 2016-08-18 added docker stats
|
||||
// 3.0.1 2016-08-17 Bug-Fix disksIO, users, updated docs
|
||||
// 3.0.0 2016-08-03 new major version 3.0
|
||||
@@ -149,9 +152,9 @@ function system(callback) {
|
||||
}
|
||||
|
||||
var result = {
|
||||
manufacturer: '-',
|
||||
model: '-',
|
||||
version: '-',
|
||||
manufacturer: '',
|
||||
model: 'Computer',
|
||||
version: '',
|
||||
serial: '-',
|
||||
uuid: '-'
|
||||
};
|
||||
@@ -218,11 +221,26 @@ function system(callback) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback) { callback(result) }
|
||||
resolve(result);
|
||||
})
|
||||
} else {
|
||||
if (callback) { callback(result) }
|
||||
resolve(result);
|
||||
}
|
||||
} else {
|
||||
exec("dmesg | grep -i virtual | grep -iE 'vmware|qemu|kvm|xen'", function (error, stdout) {
|
||||
if (!error) {
|
||||
var lines = stdout.toString().split('\n');
|
||||
if (lines.length > 0) result.model = 'Virtual machine'
|
||||
}
|
||||
if (fs.existsSync('/.dockerenv') || fs.existsSync('/.dockerinit')) {
|
||||
result.model = 'Docker Container'
|
||||
}
|
||||
if (callback) { callback(result) }
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (callback) { callback(result) }
|
||||
resolve(result);
|
||||
})
|
||||
}
|
||||
if (_darwin) {
|
||||
@@ -340,7 +358,7 @@ function osInfo(callback) {
|
||||
if (_linux) {
|
||||
|
||||
exec("cat /etc/*-release", function (error, stdout) {
|
||||
if (!error) {
|
||||
//if (!error) {
|
||||
/**
|
||||
* @namespace
|
||||
* @property {string} DISTRIB_ID
|
||||
@@ -360,7 +378,7 @@ function osInfo(callback) {
|
||||
result.logofile = getLogoFile(result.distro);
|
||||
result.release = (release.DISTRIB_RELEASE || release.VERSION_ID || 'unknown').replace(/"/g, '');
|
||||
result.codename = (release.DISTRIB_CODENAME || '').replace(/"/g, '');
|
||||
}
|
||||
//}
|
||||
if (callback) { callback(result) }
|
||||
resolve(result);
|
||||
})
|
||||
@@ -766,8 +784,102 @@ function mem(callback) {
|
||||
|
||||
exports.mem = mem;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// 6. File System
|
||||
// 6. Battery
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
function battery(callback) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
process.nextTick(() => {
|
||||
if (_windows) {
|
||||
let error = new Error(NOT_SUPPORTED);
|
||||
if (callback) { callback(NOT_SUPPORTED) }
|
||||
reject(error);
|
||||
}
|
||||
|
||||
let result = {
|
||||
hasbattery: false,
|
||||
cyclecount: 0,
|
||||
ischarging: false,
|
||||
maxcapacity: 0,
|
||||
currentcapacity: 0,
|
||||
percent: 0
|
||||
};
|
||||
|
||||
if (_linux) {
|
||||
let battery_path = '';
|
||||
if (fs.existsSync('/sys/class/power_supply/BAT1/status')) {
|
||||
battery_path = '/sys/class/power_supply/BAT1/'
|
||||
} else if (fs.existsSync('/sys/class/power_supply/BAT0/status')) {
|
||||
battery_path = '/sys/class/power_supply/BAT0/'
|
||||
}
|
||||
if (battery_path) {
|
||||
exec("cat " + battery_path + "status", function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
if (lines.length > 0 && lines[0]) result.ischarging = (lines[0].trim().toLowerCase() == 'charging')
|
||||
}
|
||||
exec("cat " + battery_path + "cyclec_ount", function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
if (lines.length > 0 && lines[0]) result.cyclecount = parseFloat(lines[0].trim());
|
||||
}
|
||||
exec("cat " + battery_path + "charge_full", function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
if (lines.length > 0 && lines[0]) result.maxcapacity = parseFloat(lines[0].trim());
|
||||
}
|
||||
exec("cat " + battery_path + "charge_now", function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
if (lines.length > 0 && lines[0]) result.currentcapacity = parseFloat(lines[0].trim());
|
||||
}
|
||||
if (result.maxcapacity && result.currentcapacity) {
|
||||
result.hasbattery = true;
|
||||
result.percent = 100.0 * result.currentcapacity / result.maxcapacity;
|
||||
}
|
||||
if (callback) { callback(result) }
|
||||
resolve(result);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
} else {
|
||||
if (callback) { callback(result) }
|
||||
resolve(result);
|
||||
}
|
||||
}
|
||||
if (_darwin) {
|
||||
exec("ioreg -n AppleSmartBattery -r | grep '\"CycleCount\"';ioreg -n AppleSmartBattery -r | grep '\"IsCharging\"';ioreg -n AppleSmartBattery -r | grep '\"MaxCapacity\"';ioreg -n AppleSmartBattery -r | grep '\"CurrentCapacity\"'", function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().replace(/ +/g, "").replace(/\"+/g, "").split('\n');
|
||||
lines.forEach(function (line) {
|
||||
if (line.indexOf('=') != -1) {
|
||||
if (line.toLowerCase().indexOf('cyclecount') != -1) result.cyclecount = parseFloat(line.split('=')[1].trim());
|
||||
if (line.toLowerCase().indexOf('ischarging') != -1) result.ischarging = (line.split('=')[1].trim().toLowerCase() == 'yes');
|
||||
if (line.toLowerCase().indexOf('maxcapacity') != -1) result.maxcapacity = parseFloat(line.split('=')[1].trim());
|
||||
if (line.toLowerCase().indexOf('currentcapacity') != -1) result.currentcapacity = parseFloat(line.split('=')[1].trim());
|
||||
}
|
||||
});
|
||||
}
|
||||
if (result.maxcapacity && result.currentcapacity) {
|
||||
result.hasbattery = true;
|
||||
result.percent = 100.0 * result.currentcapacity / result.maxcapacity;
|
||||
}
|
||||
if (callback) { callback(result) }
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.battery = battery;
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// 7. File System
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
// --------------------------
|
||||
@@ -993,8 +1105,8 @@ function disksIO(callback) {
|
||||
if (line != '') {
|
||||
line = line.split(' ');
|
||||
|
||||
result.rIO += parseInt(line[0]);
|
||||
result.wIO += parseInt(line[1]);
|
||||
result.rIO += parseInt(line[1]);
|
||||
result.wIO += parseInt(line[0]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1025,7 +1137,7 @@ function disksIO(callback) {
|
||||
exports.disksIO = disksIO;
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// 7. Network
|
||||
// 8. Network
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
function getFirstExternalNetworkInterface() {
|
||||
@@ -1359,7 +1471,7 @@ function networkConnections(callback) {
|
||||
exports.networkConnections = networkConnections;
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// 8. Processes
|
||||
// 9. Processes
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
// --------------------------
|
||||
@@ -1665,7 +1777,7 @@ function processLoad(proc, callback) {
|
||||
exports.processLoad = processLoad;
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// 9. Users/Sessions
|
||||
// 10. Users/Sessions
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
// --------------------------
|
||||
@@ -1851,7 +1963,7 @@ function users(callback) {
|
||||
exports.users = users;
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// 10. Internet
|
||||
// 11. Internet
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
// --------------------------
|
||||
@@ -1940,7 +2052,7 @@ function inetLatency(host, callback) {
|
||||
exports.inetLatency = inetLatency;
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// 11. Docker
|
||||
// 12. Docker
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
// --------------------------
|
||||
@@ -2228,7 +2340,7 @@ function dockerAll(callback) {
|
||||
exports.dockerAll = dockerAll;
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// 12. get all
|
||||
// 13. get all
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
// --------------------------
|
||||
@@ -2300,7 +2412,7 @@ function getDynamicData(srv, iface, callback) {
|
||||
|
||||
// use closure to track ƒ completion
|
||||
var functionProcessed = (function () {
|
||||
var totalFunctions = 13;
|
||||
var totalFunctions = 14;
|
||||
|
||||
return function () {
|
||||
if (--totalFunctions === 0) {
|
||||
@@ -2310,7 +2422,7 @@ function getDynamicData(srv, iface, callback) {
|
||||
};
|
||||
})();
|
||||
|
||||
// var totalFunctions = 12;
|
||||
// var totalFunctions = 14;
|
||||
// function functionProcessed() {
|
||||
// if (--totalFunctions === 0) {
|
||||
// if (callback) { callback(data) }
|
||||
@@ -2372,6 +2484,11 @@ function getDynamicData(srv, iface, callback) {
|
||||
functionProcessed();
|
||||
});
|
||||
|
||||
battery().then(res => {
|
||||
data.battery = res;
|
||||
functionProcessed();
|
||||
});
|
||||
|
||||
services(srv).then(res => {
|
||||
data.services = res;
|
||||
functionProcessed();
|
||||
|
||||
Reference in New Issue
Block a user