fixed cpu cores, updated docs

This commit is contained in:
Sebastian Hildebrandt
2015-07-18 20:06:22 +02:00
parent a61654f347
commit 1cdd178c6a
2 changed files with 37 additions and 21 deletions
+31 -19
View File
@@ -171,12 +171,13 @@ exports.osinfo =function(callback) {
// ----------------------------------------------------------------------------------
// --------------------------
// CPU - data
// CPU - brand, speed
exports.cpu = function(callback) {
function getcpu(callback) {
var result = {
brand : 'unknown',
speed : 'unknown'
speed : 'unknown',
cores : tmp_cores
};
// grep "^model name" /proc/cpuinfo 2>/dev/null || sysctl -n machdep.cpu.brand_string
if (tmp_platform == 'Darwin') {
@@ -204,6 +205,33 @@ exports.cpu = function(callback) {
}
}
// --------------------------
// CPU - Processor cores
function cores(callback) {
exec("grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu", function(error, stdout, stderr) {
var result = {cores: 1};
if (!error) {
result.cores = parseInt(stdout.toString());
tmp_cores = result.cores;
}
if (callback) callback(result);
});
}
// --------------------------
// CPU - Processor Data
exports.cpu = function(callback) {
if (tmp_cores == 0) {
cores(function(data) {
getcpu(callback)
})
} else {
getcpu(callback)
}
}
// --------------------------
// CPU - current speed
@@ -232,22 +260,6 @@ exports.cpu_currentspeed = function(callback) {
}
}
// --------------------------
// CPU - Processor cores
function cores(callback) {
exec("grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu", function(error, stdout, stderr) {
var result = {cores: 1};
if (!error) {
result.cores = parseInt(stdout.toString());
tmp_cores = result.cores;
}
if (callback) callback(result);
});
}
exports.cores = cores;
// --------------------------
// CPU - temperature
// if sensors are installed