mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-25 22:55:52 -05:00
Linux CPU utilization improvement, #4039
This commit is contained in:
parent
4e9daa4286
commit
1188f0711f
@ -106,32 +106,39 @@ function windows_memUtilization()
|
||||
return (ret);
|
||||
}
|
||||
|
||||
function linux_cpuUtilization()
|
||||
{
|
||||
var cpuLastIdle = [];
|
||||
var cpuLastSum = [];
|
||||
function linux_cpuUtilization() {
|
||||
var ret = { cpus: [] };
|
||||
var info = require('fs').readFileSync('/proc/stat');
|
||||
var lines = info.toString().split('\n');
|
||||
var columns;
|
||||
var x, y;
|
||||
var sum, idle, utilization;
|
||||
for (var i in lines)
|
||||
{
|
||||
var cpuNo = 0;
|
||||
var currSum, currIdle, utilization;
|
||||
for (var i in lines) {
|
||||
columns = lines[i].split(' ');
|
||||
if (!columns[0].startsWith('cpu')) { break; }
|
||||
|
||||
x = 0, sum = 0;
|
||||
x = 0, currSum = 0;
|
||||
while (columns[++x] == '');
|
||||
for (y = x; y < columns.length; ++y) { sum += parseInt(columns[y]); }
|
||||
idle = parseInt(columns[3 + x]);
|
||||
utilization = (100 - ((idle / sum) * 100)); //.toFixed(2);
|
||||
if (!ret.total)
|
||||
{
|
||||
for (y = x; y < columns.length; ++y) { currSum += parseInt(columns[y]); }
|
||||
currIdle = parseInt(columns[3 + x]);
|
||||
|
||||
var diffIdle = currIdle - cpuLastIdle[cpuNo];
|
||||
var diffSum = currSum - cpuLastSum[cpuNo];
|
||||
|
||||
utilization = (100 - ((diffIdle / diffSum) * 100));
|
||||
|
||||
cpuLastSum[cpuNo] = currSum;
|
||||
cpuLastIdle[cpuNo] = currIdle;
|
||||
|
||||
if (!ret.total) {
|
||||
ret.total = utilization;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ret.cpus.push(utilization);
|
||||
}
|
||||
++cpuNo;
|
||||
}
|
||||
|
||||
var p = new promise(function (res, rej) { this._res = res; this._rej = rej; });
|
||||
|
@ -106,32 +106,39 @@ function windows_memUtilization()
|
||||
return (ret);
|
||||
}
|
||||
|
||||
function linux_cpuUtilization()
|
||||
{
|
||||
var cpuLastIdle = [];
|
||||
var cpuLastSum = [];
|
||||
function linux_cpuUtilization() {
|
||||
var ret = { cpus: [] };
|
||||
var info = require('fs').readFileSync('/proc/stat');
|
||||
var lines = info.toString().split('\n');
|
||||
var columns;
|
||||
var x, y;
|
||||
var sum, idle, utilization;
|
||||
for (var i in lines)
|
||||
{
|
||||
var cpuNo = 0;
|
||||
var currSum, currIdle, utilization;
|
||||
for (var i in lines) {
|
||||
columns = lines[i].split(' ');
|
||||
if (!columns[0].startsWith('cpu')) { break; }
|
||||
|
||||
x = 0, sum = 0;
|
||||
x = 0, currSum = 0;
|
||||
while (columns[++x] == '');
|
||||
for (y = x; y < columns.length; ++y) { sum += parseInt(columns[y]); }
|
||||
idle = parseInt(columns[3 + x]);
|
||||
utilization = (100 - ((idle / sum) * 100)); //.toFixed(2);
|
||||
if (!ret.total)
|
||||
{
|
||||
for (y = x; y < columns.length; ++y) { currSum += parseInt(columns[y]); }
|
||||
currIdle = parseInt(columns[3 + x]);
|
||||
|
||||
var diffIdle = currIdle - cpuLastIdle[cpuNo];
|
||||
var diffSum = currSum - cpuLastSum[cpuNo];
|
||||
|
||||
utilization = (100 - ((diffIdle / diffSum) * 100));
|
||||
|
||||
cpuLastSum[cpuNo] = currSum;
|
||||
cpuLastIdle[cpuNo] = currIdle;
|
||||
|
||||
if (!ret.total) {
|
||||
ret.total = utilization;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ret.cpus.push(utilization);
|
||||
}
|
||||
++cpuNo;
|
||||
}
|
||||
|
||||
var p = new promise(function (res, rej) { this._res = res; this._rej = rej; });
|
||||
|
Loading…
Reference in New Issue
Block a user