luci-app-dockerman: fixed the issue that the container status under cgroup v2 has no data

Signed-off-by: sbwml <admin@cooluc.com>
This commit is contained in:
sbwml 2025-04-02 21:01:49 +08:00
parent 14362bf1f0
commit 2482225993

View File

@ -75,10 +75,17 @@ local calculate_cpu_percent = function(d)
local cpu_count = tonumber(d["cpu_stats"]["online_cpus"]) local cpu_count = tonumber(d["cpu_stats"]["online_cpus"])
local cpu_percent = 0.0 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 cpu_total_usage_current = tonumber(d["cpu_stats"]["cpu_usage"]["total_usage"])
local system_delta = tonumber(d["cpu_stats"]["system_cpu_usage"]) - tonumber(d["precpu_stats"]["system_cpu_usage"]) local cpu_total_usage_previous = tonumber(d["precpu_stats"]["cpu_usage"]["total_usage"])
if system_delta > 0.0 then local system_cpu_usage_current = tonumber(d["cpu_stats"]["system_cpu_usage"])
cpu_percent = string.format("%.2f", cpu_delta / system_delta * 100.0 * cpu_count) 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 end
return cpu_percent return cpu_percent
@ -89,10 +96,11 @@ local get_memory = function(d)
return return
end end
local limit =tonumber(d["memory_stats"]["limit"]) local limit = tonumber(d["memory_stats"]["limit"])
local usage = tonumber(d["memory_stats"]["usage"]) - tonumber(d["memory_stats"]["stats"]["total_cache"]) 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 end
local get_rx_tx = function(d) local get_rx_tx = function(d)