luci-app-dockerman: fix stats page always blank 6652/head
authorLiangbin Lian <jjm2473@gmail.com>
Thu, 26 Oct 2023 11:48:49 +0000 (19:48 +0800)
committerLiangbin Lian <jjm2473@gmail.com>
Thu, 26 Oct 2023 12:01:44 +0000 (20:01 +0800)
Signed-off-by: Liangbin Lian <jjm2473@gmail.com>
applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua

index f8329ba703080505d188ce9086555247633d54b6..5caad4f93fd510d4cbcc31dde6be51302081e333 100644 (file)
@@ -752,35 +752,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 ~= 409 then
+               if response.code ~= 200 then
+                       response = dk.containers:top({id = container_id})
+               end
+
+               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
+                       container_top = response.body
                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={
+               local table_stats = {
+                       cpu = {
                                key=translate("CPU Usage"),
                                value='-'
                        },
-                       memory={
+                       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