From: Dwight Engen Date: Thu, 31 Oct 2013 20:38:36 +0000 (-0400) Subject: lxc-top: show kernel memory being used if available X-Git-Tag: lxc-1.0.0.alpha3~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2752ecec3232c231469a2ad8513a5527fef66fd6;p=thirdparty%2Flxc.git lxc-top: show kernel memory being used if available - Also removed duplicate stats_clear lua function Signed-off-by: Dwight Engen Signed-off-by: Serge Hallyn --- diff --git a/doc/lxc-top.sgml.in b/doc/lxc-top.sgml.in index 002115495..ba727c571 100644 --- a/doc/lxc-top.sgml.in +++ b/doc/lxc-top.sgml.in @@ -58,11 +58,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Description lxc-top displays container statistics. The output - is updated every delay seconds, and is - ordered according to the sortby value - given. Specifying count will limit the - number of containers displayed, otherwise lxc-top - will display as many containers as can fit in your terminal. + is updated every delay seconds, and is + ordered according to the sortby value + given. Specifying count will limit the + number of containers displayed, otherwise lxc-top + will display as many containers as can fit in your terminal. @@ -103,8 +103,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Sort the containers by name, cpu use, or memory use. The sortby argument should be one of - the letters n,c,d,m to sort by name, cpu use, disk I/O, or - memory use respectively. The default is 'n'. + the letters n,c,d,m,k to sort by name, cpu use, disk I/O, memory, + or kernel memory use respectively. The default is 'n'. @@ -137,6 +137,25 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + Notes + + For performance reasons the kernel does not account kernel memory use + unless a kernel memory limit is set. If a limit is not set, + lxc-top will display kernel memory use as 0. If no containers + are being accounted, the KMem column will not be displayed. A limit can + be set by specifying + + lxc.cgroup.memory.kmem.limit_in_bytes = number + + in your container configuration file, see + + lxc.conf + 5 + . + + + &seealso; diff --git a/src/lua-lxc/lxc.lua b/src/lua-lxc/lxc.lua index 5a3b49e2c..265e991ad 100755 --- a/src/lua-lxc/lxc.lua +++ b/src/lua-lxc/lxc.lua @@ -289,6 +289,8 @@ function container:stats_get(total) stat.mem_limit = self:stat_get_int("memory.limit_in_bytes") stat.memsw_used = self:stat_get_int("memory.memsw.usage_in_bytes") stat.memsw_limit = self:stat_get_int("memory.memsw.limit_in_bytes") + stat.kmem_used = self:stat_get_int("memory.kmem.usage_in_bytes") + stat.kmem_limit = self:stat_get_int("memory.kmem.limit_in_bytes") stat.cpu_use_nanos = self:stat_get_int("cpuacct.usage") stat.cpu_use_user, stat.cpu_use_sys = self:stat_get_ints("cpuacct.stat", {{1, 2}, {2, 2}}) @@ -299,6 +301,8 @@ function container:stats_get(total) total.mem_limit = total.mem_limit + stat.mem_limit total.memsw_used = total.memsw_used + stat.memsw_used total.memsw_limit = total.memsw_limit + stat.memsw_limit + total.kmem_used = total.kmem_used + stat.kmem_used + total.kmem_limit = total.kmem_limit + stat.kmem_limit total.cpu_use_nanos = total.cpu_use_nanos + stat.cpu_use_nanos total.cpu_use_user = total.cpu_use_user + stat.cpu_use_user total.cpu_use_sys = total.cpu_use_sys + stat.cpu_use_sys @@ -314,17 +318,8 @@ function M.stats_clear(stat) 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 - -function M.stats_clear(stat) - stat.mem_used = 0 - stat.mem_limit = 0 - stat.memsw_used = 0 - stat.memsw_limit = 0 + stat.kmem_used = 0 + stat.kmem_limit = 0 stat.cpu_use_nanos = 0 stat.cpu_use_user = 0 stat.cpu_use_sys = 0 diff --git a/src/lxc/lxc-top b/src/lxc/lxc-top index 35d7e02ac..a1f025010 100755 --- a/src/lxc/lxc-top +++ b/src/lxc/lxc-top @@ -117,12 +117,14 @@ function container_sort(a, b) elseif (optarg["s"] == "c") then return (stats[a].cpu_use_nanos < stats[b].cpu_use_nanos) elseif (optarg["s"] == "d") then return (stats[a].blkio < stats[b].blkio) elseif (optarg["s"] == "m") then return (stats[a].mem_used < stats[b].mem_used) + elseif (optarg["s"] == "k") then return (stats[a].kmem_used < stats[b].kmem_used) end else if (optarg["s"] == "n") then return (a < b) elseif (optarg["s"] == "c") then return (stats[a].cpu_use_nanos > stats[b].cpu_use_nanos) elseif (optarg["s"] == "d") then return (stats[a].blkio > stats[b].blkio) elseif (optarg["s"] == "m") then return (stats[a].mem_used > stats[b].mem_used) + elseif (optarg["s"] == "k") then return (stats[a].kmem_used > stats[b].kmem_used) end end end @@ -163,14 +165,19 @@ function container_list_update() table.sort(containers, container_sort) end -function stats_print_header() +function stats_print_header(stats_total) printf(TERMRVRS .. TERMBOLD) - printf("%-15s %8s %8s %8s %10s %10s\n", "Container", "CPU", "CPU", "CPU", "BlkIO", "Mem") - printf("%-15s %8s %8s %8s %10s %10s\n", "Name", "Used", "Sys", "User", "Total", "Used") + printf("%-15s %8s %8s %8s %10s %10s", "Container", "CPU", "CPU", "CPU", "BlkIO", "Mem") + if (stats_total.kmem_used > 0) then printf(" %10s", "KMem") end + printf("\n") + + printf("%-15s %8s %8s %8s %10s %10s", "Name", "Used", "Sys", "User", "Total", "Used") + if (stats_total.kmem_used > 0) then printf(" %10s", "Used") end + printf("\n") printf(TERMNORM) end -function stats_print(name, stats) +function stats_print(name, stats, stats_total) printf("%-15s %8.2f %8.2f %8.2f %10s %10s", name, stats.cpu_use_nanos / 1000000000, @@ -178,6 +185,9 @@ function stats_print(name, stats) stats.cpu_use_user / USER_HZ, strsisize(stats.blkio), strsisize(stats.mem_used)) + if (stats_total.kmem_used > 0) then + printf(" %10s", strsisize(stats.kmem_used)) + end end function usage() @@ -190,6 +200,7 @@ function usage() " c = CPU use\n" .. " d = Disk I/O use\n" .. " m = Memory use\n" .. + " k = Kernel memory use\n" .. " -r|--reverse sort in reverse (descending) order\n" ) os.exit(1) @@ -219,15 +230,15 @@ do -- may fall back to this, or ncurses. ug. --os.execute("tput clear") printf(TERMCLEAR) - stats_print_header() + stats_print_header(stats_total) for index,ctname in ipairs(containers) do - stats_print(ctname, stats[ctname]) + stats_print(ctname, stats[ctname], stats_total) printf("\n") if (index >= optarg["m"]) then break end end - stats_print(string.format("TOTAL (%-2d)", #containers), stats_total) + stats_print(string.format("TOTAL (%-2d)", #containers), stats_total, stats_total) io.flush() core.usleep(optarg["d"] * 1000000) end