Comparing version 1.8.1 to 1.8.2
@@ -9,2 +9,45 @@ 'use strict'; | ||
/* | ||
* user nice system idle iowait irq softirq steal guest guest_nice | ||
* cpu 74608 2520 24433 1117073 6176 4054 0 0 0 0 | ||
* | ||
* Idle = idle + iowait + steal | ||
* NonIdle = user + nice + system + irq + softirq + steal | ||
* Total = Idle + NonIdle; | ||
* cpu% = 1 - diffIdle / diffTotal | ||
* this is a description for "steal", it is useful in a VM env. | ||
* http://blog.scoutapp.com/articles/2013/07/25/understanding-cpu-steal-time-when-should-you-be-worried | ||
*/ | ||
var calculateLinuxCPU = function () { | ||
var raw = fs.readFileSync('/proc/stat'); | ||
if (!raw) { | ||
return 0; | ||
} | ||
var lines = raw.toString().trim().split('\n'); | ||
for (var i = 0; i < lines.length; i++) { | ||
if (lines[i].indexOf('cpu ') >= 0) { | ||
var stat = lines[i].split(' '); | ||
// [ 'cpu', '', '327248', '602', '82615', '1556436', | ||
// '22886', '0', '134', '0', '0', '0' ] | ||
stat.shift(); | ||
stat.shift(); | ||
var idle = parseInt(stat[3], 10) + | ||
parseInt(stat[4], 10) + parseInt(stat[7], 10); | ||
var total = 0; | ||
for (var j = 0; j < 8; j++) { | ||
total += parseInt(stat[j], 10); | ||
} | ||
var diffTotal = total - lastTotal; | ||
var diffIdle = idle - lastIdle; | ||
lastTotal = total; | ||
lastIdle = idle; | ||
return 1 - diffIdle / diffTotal; | ||
} | ||
} | ||
return 0; | ||
}; | ||
var calculateCPU = function () { | ||
@@ -36,7 +79,7 @@ var cpus = os.cpus(); | ||
if (['MemFree', 'Buffers', 'Cached'].indexOf(pair[0]) >= 0) { | ||
real_free += parseInt(pair[1]); | ||
real_free += parseInt(pair[1], 10); | ||
} | ||
}); | ||
return real_free * 1024; | ||
} | ||
}; | ||
@@ -52,3 +95,3 @@ var status = function () { | ||
load15: loadavg[2], | ||
cpu: calculateCPU(), | ||
cpu: os.type() === 'Linux' ? calculateLinuxCPU() : calculateCPU(), | ||
cpu_count: os.cpus().length | ||
@@ -55,0 +98,0 @@ }; |
{ | ||
"name": "agentx", | ||
"version": "1.8.1", | ||
"version": "1.8.2", | ||
"description": "agentx is powered by alinode", | ||
@@ -5,0 +5,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37583
1239