fixed issue calculation docker cpu_percent linux
This commit is contained in:
parent
e9a6f35ab1
commit
de097b5667
@ -110,7 +110,7 @@ exports.dockerContainers = dockerContainers;
|
|||||||
// --------------------------
|
// --------------------------
|
||||||
// helper functions for calculation of docker stats
|
// helper functions for calculation of docker stats
|
||||||
|
|
||||||
function docker_calcCPUPercent(cpu_stats, id) {
|
function docker_calcCPUPercent(cpu_stats, precpu_stats) {
|
||||||
/**
|
/**
|
||||||
* @namespace
|
* @namespace
|
||||||
* @property {object} cpu_usage
|
* @property {object} cpu_usage
|
||||||
@ -122,16 +122,13 @@ function docker_calcCPUPercent(cpu_stats, id) {
|
|||||||
|
|
||||||
let cpuPercent = 0.0;
|
let cpuPercent = 0.0;
|
||||||
// calculate the change for the cpu usage of the container in between readings
|
// calculate the change for the cpu usage of the container in between readings
|
||||||
let cpuDelta = cpu_stats.cpu_usage.total_usage - (_docker_container_stats[id] && _docker_container_stats[id].prev_CPU ? _docker_container_stats[id].prev_CPU : 0);
|
let cpuDelta = cpu_stats.cpu_usage.total_usage - precpu_stats.cpu_usage.total_usage;
|
||||||
// calculate the change for the entire system between readings
|
// calculate the change for the entire system between readings
|
||||||
let systemDelta = cpu_stats.system_cpu_usage - (_docker_container_stats[id] && _docker_container_stats[id].prev_system ? _docker_container_stats[id].prev_system : 0);
|
let systemDelta = cpu_stats.system_cpu_usage - precpu_stats.system_cpu_usage;
|
||||||
|
|
||||||
if (systemDelta > 0.0 && cpuDelta > 0.0) {
|
if (systemDelta > 0.0 && cpuDelta > 0.0) {
|
||||||
cpuPercent = (cpuDelta / systemDelta) * cpu_stats.cpu_usage.percpu_usage.length * 100.0;
|
cpuPercent = (cpuDelta / systemDelta) * cpu_stats.cpu_usage.percpu_usage.length * 100.0;
|
||||||
}
|
}
|
||||||
if (!_docker_container_stats[id]) _docker_container_stats[id] = {};
|
|
||||||
_docker_container_stats[id].prev_CPU = cpu_stats.cpu_usage.total_usage;
|
|
||||||
_docker_container_stats[id].prev_system = cpu_stats.system_cpu_usage;
|
|
||||||
|
|
||||||
return cpuPercent;
|
return cpuPercent;
|
||||||
}
|
}
|
||||||
@ -235,7 +232,7 @@ function dockerContainerStats(containerID, callback) {
|
|||||||
result.mem_usage = (stats.memory_stats && stats.memory_stats.usage ? stats.memory_stats.usage : 0);
|
result.mem_usage = (stats.memory_stats && stats.memory_stats.usage ? stats.memory_stats.usage : 0);
|
||||||
result.mem_limit = (stats.memory_stats && stats.memory_stats.limit ? stats.memory_stats.limit : 0);
|
result.mem_limit = (stats.memory_stats && stats.memory_stats.limit ? stats.memory_stats.limit : 0);
|
||||||
result.mem_percent = (stats.memory_stats && stats.memory_stats.usage && stats.memory_stats.limit ? stats.memory_stats.usage / stats.memory_stats.limit * 100.0 : 0);
|
result.mem_percent = (stats.memory_stats && stats.memory_stats.usage && stats.memory_stats.limit ? stats.memory_stats.usage / stats.memory_stats.limit * 100.0 : 0);
|
||||||
result.cpu_percent = (stats.cpu_stats ? docker_calcCPUPercent(stats.cpu_stats, containerID) : 0);
|
result.cpu_percent = (stats.cpu_stats && stats.precpu_stats ? docker_calcCPUPercent(stats.cpu_stats, stats.precpu_stats) : 0);
|
||||||
result.pids = (stats.pids_stats && stats.pids_stats.current ? stats.pids_stats.current : 0);
|
result.pids = (stats.pids_stats && stats.pids_stats.current ? stats.pids_stats.current : 0);
|
||||||
if (stats.networks) result.netIO = docker_calcNetworkIO(stats.networks);
|
if (stats.networks) result.netIO = docker_calcNetworkIO(stats.networks);
|
||||||
if (stats.blkio_stats) result.blockIO = docker_calcBlockIO(stats.blkio_stats);
|
if (stats.blkio_stats) result.blockIO = docker_calcBlockIO(stats.blkio_stats);
|
||||||
@ -283,7 +280,7 @@ function dockerContainerProcesses(containerID, callback) {
|
|||||||
**/
|
**/
|
||||||
try {
|
try {
|
||||||
if (data && data.Titles && data.Processes) {
|
if (data && data.Titles && data.Processes) {
|
||||||
let titles = data.Titles.map(function(value) {
|
let titles = data.Titles.map(function (value) {
|
||||||
return value.toUpperCase();
|
return value.toUpperCase();
|
||||||
});
|
});
|
||||||
let pos_pid = titles.indexOf('PID');
|
let pos_pid = titles.indexOf('PID');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user