bugfix cpu_currentspeed, cpu_temperature; updated docs

This commit is contained in:
Sebastian Hildebrandt 2015-07-18 13:10:37 +02:00
parent c62ef0d69b
commit 83decf3962
2 changed files with 31 additions and 28 deletions

View File

@ -51,7 +51,7 @@ This library is splitted in several sections:
| command | Linux | OSX | Comments |
| -------------- | ------ | ------ | ------- |
| si.osinfo() | X | X | |
| si.osinfo() | X | X | OS information|
| - platform | X | X | 'Linux' or 'Darwin' |
| - distro | X | X | |
| - release | X | X | |
@ -60,16 +60,15 @@ This library is splitted in several sections:
| - arch | X | X | same as os.arch() |
| - hostname | X | X | same as os.hostname() |
| - logofile | X | X | e.g. 'apple', 'debian', 'fedora', ... |
| si.cpu() | X | X | |
| - brand | X | X | e.g. 'Intel' |
| si.cpu() | X | X | CPU information|
| - brand | X | X | e.g. 'Intel(R)' |
| - speed | X | X | e.g. '3.40GHz' |
| si.cpu_speed() | X | X | |
| - current | X | X | current speed |
| si.cpu_currentspeed() | X | X | current speed (GHz)|
| si.cores() | X | X | # cores |
| si.sensors() | X | | |
| si.cpu_temperature() | X | | CPU temperature (if sensors is installed) |
| - main | X | X | main temperature |
| - cores | X | X | array of temperatures |
| si.mem() | X | X | |
| si.mem() | X | X | Memory information|
| - total | X | X | |
| - free | X | X | |
| - used | X | X | |

View File

@ -207,13 +207,13 @@ exports.cpu = function(callback) {
// --------------------------
// CPU - current speed
exports.cpu_speed = function(callback) {
exports.cpu_currentspeed = function(callback) {
var result = {current : tmp_cpu_speed};
if (tmp_platform == 'Darwin') {
exec("sysctl -n hw.cpufrequency", function(error, stdout, stderr) {
if (!error) {
var lines = stdout.toString().split('\n');
result.current = parseInt(lines[0]);
result = parseInt(lines[0]);
}
callback(result);
});
@ -226,7 +226,7 @@ exports.cpu_speed = function(callback) {
}
if (output.trim()) {
var lines = output.toString().split('\n');
result.current = parseInt(lines[0]) * 1000;
result = parseInt(lines[0]) * 1000;
}
callback(result);
}
@ -252,27 +252,31 @@ exports.cores = cores;
// CPU - temperature
// if sensors are installed
exports.sensors = function(callback) {
exports.cpu_temperature = function(callback) {
var result = {
main : 0.0,
cores : []
}
var regex = /\+([^°]*)/g;
exec("sensors", function(error, stdout, stderr) {
if (!error) {
var lines = stdout.toString().split('\n');
lines.forEach(function(line) {
var temps = line.match(regex);
if (line.split(':')[0].toUpperCase().indexOf('PHYSICAL') != -1) {
result.main = parseFloat(temps);
}
if (line.split(':')[0].toUpperCase().indexOf('CORE ') != -1) {
result.cores.push(parseFloat(temps));
}
})
}
callback(result)
});
if (tmp_platform == 'Linux') {
var regex = /\+([^°]*)/g;
exec("sensors", function(error, stdout, stderr) {
if (!error) {
var lines = stdout.toString().split('\n');
lines.forEach(function(line) {
var temps = line.match(regex);
if (line.split(':')[0].toUpperCase().indexOf('PHYSICAL') != -1) {
result.main = parseFloat(temps);
}
if (line.split(':')[0].toUpperCase().indexOf('CORE ') != -1) {
result.cores.push(parseFloat(temps));
}
})
}
callback(result)
});
} else {
callback(result)
}
};
@ -538,7 +542,7 @@ function getfullload(callback) {
output = output.replace(/ +/g, " ").split(' ');
var uptime = parseFloat(output[0])
var idletime = parseFloat(output[1]) / tmp_cores;
result.fullload = (uptime - idletime) / uptime
result.fullload = (uptime - idletime) / uptime * 100.0
callback(result);
}
} else {