From 70a3c24849dd2ad9175bc639b2da278c0dc92a52 Mon Sep 17 00:00:00 2001 From: sbwml Date: Tue, 2 Apr 2024 18:27:07 +0800 Subject: [PATCH] luci-app-dockerman: fix stats page always blank Signed-off-by: sbwml --- luasrc/model/cbi/dockerman/container.lua | 43 +++++++++++++----------- po/zh_Hans/dockerman.po | 6 ++-- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/luasrc/model/cbi/dockerman/container.lua b/luasrc/model/cbi/dockerman/container.lua index 8ec5293..5153497 100644 --- a/luasrc/model/cbi/dockerman/container.lua +++ b/luasrc/model/cbi/dockerman/container.lua @@ -761,35 +761,40 @@ elseif action == "stats" then local response = dk.containers:top({id = container_id, query = {ps_args="-aux"}}) local container_top - if response.code == 200 then - container_top=response.body - else - response = dk.containers:top({id = container_id}) - if response.code == 200 then - container_top=response.body + if response.code ~= 409 then + if response.code ~= 200 then + response = dk.containers:top({id = container_id}) end - end - if type(container_top) == "table" then - s = m:section(SimpleSection) - s.container_id = container_id - s.template = "dockerman/container_stats" - table_stats = { - cpu={ - key=translate("CPU Useage"), + if response.code ~= 200 then + response = dk.containers:top({id = container_id, query = {ps_args="-ww"}}) + end + + if response.code == 200 then + container_top = response.body + end + + local table_stats = { + cpu = { + key=translate("CPU Usage"), value='-' }, - memory={ - key=translate("Memory Useage"), + memory = { + key=translate("Memory Usage"), value='-' } } - - container_top = response.body s = m:section(Table, table_stats, translate("Stats")) s:option(DummyValue, "key", translate("Stats")).width="33%" s:option(DummyValue, "value") - top_section = m:section(Table, container_top.Processes, translate("TOP")) + + s = m:section(SimpleSection) + s.container_id = container_id + s.template = "dockerman/container_stats" + end + + if type(container_top) == "table" then + local top_section = m:section(Table, container_top.Processes, translate("TOP")) for i, v in ipairs(container_top.Titles) do top_section:option(DummyValue, i, translate(v)) end diff --git a/po/zh_Hans/dockerman.po b/po/zh_Hans/dockerman.po index 1932856..e0d3ce8 100644 --- a/po/zh_Hans/dockerman.po +++ b/po/zh_Hans/dockerman.po @@ -103,7 +103,7 @@ msgid "CPU Shares Weight" msgstr "CPU 共享权重" #: applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua:770 -msgid "CPU Useage" +msgid "CPU Usage" msgstr "CPU 使用率" #: applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newcontainer.lua:621 @@ -523,7 +523,7 @@ msgstr "负载" #: applications/luci-app-dockerman/luasrc/model/cbi/dockerman/configuration.lua:54 msgid "Log Level" -msgstr "日志等级" +msgstr "日志级别" #: applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newcontainer.lua:646 msgid "Log driver options" @@ -543,7 +543,7 @@ msgid "Memory" msgstr "内存" #: applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua:774 -msgid "Memory Useage" +msgid "Memory Usage" msgstr "内存使用率" #: applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newcontainer.lua:630