diff --git a/luasrc/controller/dockerman.lua b/luasrc/controller/dockerman.lua index 7467bc0..b11acf7 100644 --- a/luasrc/controller/dockerman.lua +++ b/luasrc/controller/dockerman.lua @@ -75,10 +75,17 @@ local calculate_cpu_percent = function(d) local cpu_count = tonumber(d["cpu_stats"]["online_cpus"]) local cpu_percent = 0.0 - local cpu_delta = tonumber(d["cpu_stats"]["cpu_usage"]["total_usage"]) - tonumber(d["precpu_stats"]["cpu_usage"]["total_usage"]) - local system_delta = tonumber(d["cpu_stats"]["system_cpu_usage"]) - tonumber(d["precpu_stats"]["system_cpu_usage"]) - if system_delta > 0.0 then - cpu_percent = string.format("%.2f", cpu_delta / system_delta * 100.0 * cpu_count) + local cpu_total_usage_current = tonumber(d["cpu_stats"]["cpu_usage"]["total_usage"]) + local cpu_total_usage_previous = tonumber(d["precpu_stats"]["cpu_usage"]["total_usage"]) + local system_cpu_usage_current = tonumber(d["cpu_stats"]["system_cpu_usage"]) + local system_cpu_usage_previous = tonumber(d["precpu_stats"]["system_cpu_usage"]) + + if cpu_total_usage_current and cpu_total_usage_previous and system_cpu_usage_current and system_cpu_usage_previous then + local cpu_delta = cpu_total_usage_current - cpu_total_usage_previous + local system_delta = system_cpu_usage_current - system_cpu_usage_previous + if system_delta > 0.0 then + cpu_percent = string.format("%.2f", cpu_delta / system_delta * 100.0 * cpu_count) + end end return cpu_percent @@ -89,10 +96,11 @@ local get_memory = function(d) return end - local limit =tonumber(d["memory_stats"]["limit"]) - local usage = tonumber(d["memory_stats"]["usage"]) - tonumber(d["memory_stats"]["stats"]["total_cache"]) + local limit = tonumber(d["memory_stats"]["limit"]) + local usage = tonumber(d["memory_stats"]["usage"]) or 0 + local total_cache = tonumber(d["memory_stats"]["stats"]["total_cache"]) or 0 - return usage, limit + return usage - total_cache, limit end local get_rx_tx = function(d)