Commit 330da5fa by Dwight Engen Committed by Stéphane Graber

lua: fix stats gathering

- remove lxc subdir in cgroup paths (done in commit b98f7d6e) - remove extraneous debug printfs - remove extra call to stats_clear Signed-off-by: 's avatarDwight Engen <dwight.engen@oracle.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent c25c2970
...@@ -254,7 +254,7 @@ end ...@@ -254,7 +254,7 @@ end
-- methods for stats collection from various cgroup files -- methods for stats collection from various cgroup files
-- read integers at given coordinates from a cgroup file -- read integers at given coordinates from a cgroup file
function container:stat_get_ints(controller, item, coords) function container:stat_get_ints(controller, item, coords)
local f = io.open(cgroup_path.."/"..controller.."/lxc/"..self.ctname.."/"..item, "r") local f = io.open(cgroup_path.."/"..controller.."/"..self.ctname.."/"..item, "r")
local lines = {} local lines = {}
local result = {} local result = {}
...@@ -280,7 +280,7 @@ end ...@@ -280,7 +280,7 @@ end
-- read an integer from a cgroup file -- read an integer from a cgroup file
function container:stat_get_int(controller, item) function container:stat_get_int(controller, item)
local f = io.open(cgroup_path.."/"..controller.."/lxc/"..self.ctname.."/"..item, "r") local f = io.open(cgroup_path.."/"..controller.."/"..self.ctname.."/"..item, "r")
if (not f) then if (not f) then
return 0 return 0
end end
...@@ -294,19 +294,17 @@ end ...@@ -294,19 +294,17 @@ end
function container:stat_match_get_int(controller, item, match, column) function container:stat_match_get_int(controller, item, match, column)
local val local val
local f = io.open(cgroup_path.."/"..controller.."/lxc/"..self.ctname.."/"..item, "r") local f = io.open(cgroup_path.."/"..controller.."/"..self.ctname.."/"..item, "r")
if (not f) then if (not f) then
return 0 return 0
end end
for line in f:lines() do for line in f:lines() do
printf("matching line:%s with match:%s\n", line, match)
if (string.find(line, match)) then if (string.find(line, match)) then
local col local col
col = line:split(" ", 80) col = line:split(" ", 80)
val = tonumber(col[column]) or 0 val = tonumber(col[column]) or 0
printf("found line!! val:%d\n", val)
end end
end end
f:close() f:close()
...@@ -350,6 +348,17 @@ function M.stats_clear(stat) ...@@ -350,6 +348,17 @@ function M.stats_clear(stat)
stat.blkio = 0 stat.blkio = 0
end end
function M.stats_clear(stat)
stat.mem_used = 0
stat.mem_limit = 0
stat.memsw_used = 0
stat.memsw_limit = 0
stat.cpu_use_nanos = 0
stat.cpu_use_user = 0
stat.cpu_use_sys = 0
stat.blkio = 0
end
-- return configured containers found in LXC_PATH directory -- return configured containers found in LXC_PATH directory
function M.containers_configured(names_only) function M.containers_configured(names_only)
local containers = {} local containers = {}
...@@ -381,34 +390,22 @@ end ...@@ -381,34 +390,22 @@ end
-- return running containers found in cgroup fs -- return running containers found in cgroup fs
function M.containers_running(names_only) function M.containers_running(names_only)
local containers = {} local containers = {}
local attr local names = M.containers_configured(true)
-- the lxc directory won't exist if no containers has ever been started
attr = lfs.attributes(cgroup_path .. "/cpu/lxc")
if (not attr) then
return containers
end
for file in lfs.dir(cgroup_path .. "/cpu/lxc") do
if (file ~= "." and file ~= "..")
then
local pathfile = cgroup_path .. "/cpu/lxc/" .. file
local attr = lfs.attributes(pathfile)
if (attr.mode == "directory") then for _,name in ipairs(names) do
local ct = container:new(name)
if ct:running() then
-- note, this is a "mixed" table, ie both dictionary and list
table.insert(containers, name)
if (names_only) then if (names_only) then
-- note, this is a "mixed" table, ie both dictionary and list containers[name] = true
containers[file] = true ct = nil
table.insert(containers, file)
else else
local ct = container:new(file) containers[name] = ct
-- note, this is a "mixed" table, ie both dictionary and list
containers[file] = ct
table.insert(containers, file)
end end
end
end end
end end
table.sort(containers, function (a,b) return (a < b) end) table.sort(containers, function (a,b) return (a < b) end)
return containers return containers
end end
......
...@@ -130,7 +130,6 @@ end ...@@ -130,7 +130,6 @@ end
function container_list_update() function container_list_update()
local now_running local now_running
lxc.stats_clear(stats_total)
now_running = lxc.containers_running(true) now_running = lxc.containers_running(true)
-- check for newly started containers -- check for newly started containers
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment