Commit 2752ecec by Dwight Engen Committed by Serge Hallyn

lxc-top: show kernel memory being used if available

- Also removed duplicate stats_clear lua function Signed-off-by: 's avatarDwight Engen <dwight.engen@oracle.com> Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent 891f838b
...@@ -58,11 +58,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ...@@ -58,11 +58,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
<title>Description</title> <title>Description</title>
<para> <para>
<command>lxc-top</command> displays container statistics. The output <command>lxc-top</command> displays container statistics. The output
is updated every <replaceable>delay</replaceable> seconds, and is is updated every <replaceable>delay</replaceable> seconds, and is
ordered according to the <replaceable>sortby</replaceable> value ordered according to the <replaceable>sortby</replaceable> value
given. Specifying <replaceable>count</replaceable> will limit the given. Specifying <replaceable>count</replaceable> will limit the
number of containers displayed, otherwise <command>lxc-top</command> number of containers displayed, otherwise <command>lxc-top</command>
will display as many containers as can fit in your terminal. will display as many containers as can fit in your terminal.
</para> </para>
</refsect1> </refsect1>
...@@ -103,8 +103,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ...@@ -103,8 +103,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
<para> <para>
Sort the containers by name, cpu use, or memory use. The Sort the containers by name, cpu use, or memory use. The
<replaceable>sortby</replaceable> argument should be one of <replaceable>sortby</replaceable> argument should be one of
the letters n,c,d,m to sort by name, cpu use, disk I/O, or the letters n,c,d,m,k to sort by name, cpu use, disk I/O, memory,
memory use respectively. The default is 'n'. or kernel memory use respectively. The default is 'n'.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -137,6 +137,25 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ...@@ -137,6 +137,25 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
</variablelist> </variablelist>
</refsect1> </refsect1>
<refsect1>
<title>Notes</title>
<para>
For performance reasons the kernel does not account kernel memory use
unless a kernel memory limit is set. If a limit is not set, <command>
lxc-top</command> 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
<programlisting>
lxc.cgroup.memory.kmem.limit_in_bytes = <replaceable>number</replaceable>
</programlisting>
in your container configuration file, see
<citerefentry>
<refentrytitle>lxc.conf</refentrytitle>
<manvolnum>5</manvolnum>
</citerefentry>.
</para>
</refsect1>
&seealso; &seealso;
<refsect1> <refsect1>
......
...@@ -289,6 +289,8 @@ function container:stats_get(total) ...@@ -289,6 +289,8 @@ function container:stats_get(total)
stat.mem_limit = self:stat_get_int("memory.limit_in_bytes") 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_used = self:stat_get_int("memory.memsw.usage_in_bytes")
stat.memsw_limit = self:stat_get_int("memory.memsw.limit_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_nanos = self:stat_get_int("cpuacct.usage")
stat.cpu_use_user, stat.cpu_use_user,
stat.cpu_use_sys = self:stat_get_ints("cpuacct.stat", {{1, 2}, {2, 2}}) stat.cpu_use_sys = self:stat_get_ints("cpuacct.stat", {{1, 2}, {2, 2}})
...@@ -299,6 +301,8 @@ function container:stats_get(total) ...@@ -299,6 +301,8 @@ function container:stats_get(total)
total.mem_limit = total.mem_limit + stat.mem_limit total.mem_limit = total.mem_limit + stat.mem_limit
total.memsw_used = total.memsw_used + stat.memsw_used total.memsw_used = total.memsw_used + stat.memsw_used
total.memsw_limit = total.memsw_limit + stat.memsw_limit 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_nanos = total.cpu_use_nanos + stat.cpu_use_nanos
total.cpu_use_user = total.cpu_use_user + stat.cpu_use_user total.cpu_use_user = total.cpu_use_user + stat.cpu_use_user
total.cpu_use_sys = total.cpu_use_sys + stat.cpu_use_sys total.cpu_use_sys = total.cpu_use_sys + stat.cpu_use_sys
...@@ -314,17 +318,8 @@ function M.stats_clear(stat) ...@@ -314,17 +318,8 @@ function M.stats_clear(stat)
stat.mem_limit = 0 stat.mem_limit = 0
stat.memsw_used = 0 stat.memsw_used = 0
stat.memsw_limit = 0 stat.memsw_limit = 0
stat.cpu_use_nanos = 0 stat.kmem_used = 0
stat.cpu_use_user = 0 stat.kmem_limit = 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.cpu_use_nanos = 0 stat.cpu_use_nanos = 0
stat.cpu_use_user = 0 stat.cpu_use_user = 0
stat.cpu_use_sys = 0 stat.cpu_use_sys = 0
......
...@@ -117,12 +117,14 @@ function container_sort(a, b) ...@@ -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"] == "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"] == "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"] == "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
else else
if (optarg["s"] == "n") then return (a < b) 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"] == "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"] == "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"] == "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 end
end end
...@@ -163,14 +165,19 @@ function container_list_update() ...@@ -163,14 +165,19 @@ function container_list_update()
table.sort(containers, container_sort) table.sort(containers, container_sort)
end end
function stats_print_header() function stats_print_header(stats_total)
printf(TERMRVRS .. TERMBOLD) printf(TERMRVRS .. TERMBOLD)
printf("%-15s %8s %8s %8s %10s %10s\n", "Container", "CPU", "CPU", "CPU", "BlkIO", "Mem") printf("%-15s %8s %8s %8s %10s %10s", "Container", "CPU", "CPU", "CPU", "BlkIO", "Mem")
printf("%-15s %8s %8s %8s %10s %10s\n", "Name", "Used", "Sys", "User", "Total", "Used") 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) printf(TERMNORM)
end end
function stats_print(name, stats) function stats_print(name, stats, stats_total)
printf("%-15s %8.2f %8.2f %8.2f %10s %10s", printf("%-15s %8.2f %8.2f %8.2f %10s %10s",
name, name,
stats.cpu_use_nanos / 1000000000, stats.cpu_use_nanos / 1000000000,
...@@ -178,6 +185,9 @@ function stats_print(name, stats) ...@@ -178,6 +185,9 @@ function stats_print(name, stats)
stats.cpu_use_user / USER_HZ, stats.cpu_use_user / USER_HZ,
strsisize(stats.blkio), strsisize(stats.blkio),
strsisize(stats.mem_used)) strsisize(stats.mem_used))
if (stats_total.kmem_used > 0) then
printf(" %10s", strsisize(stats.kmem_used))
end
end end
function usage() function usage()
...@@ -190,6 +200,7 @@ function usage() ...@@ -190,6 +200,7 @@ function usage()
" c = CPU use\n" .. " c = CPU use\n" ..
" d = Disk I/O use\n" .. " d = Disk I/O use\n" ..
" m = Memory use\n" .. " m = Memory use\n" ..
" k = Kernel memory use\n" ..
" -r|--reverse sort in reverse (descending) order\n" " -r|--reverse sort in reverse (descending) order\n"
) )
os.exit(1) os.exit(1)
...@@ -219,15 +230,15 @@ do ...@@ -219,15 +230,15 @@ do
-- may fall back to this, or ncurses. ug. -- may fall back to this, or ncurses. ug.
--os.execute("tput clear") --os.execute("tput clear")
printf(TERMCLEAR) printf(TERMCLEAR)
stats_print_header() stats_print_header(stats_total)
for index,ctname in ipairs(containers) do for index,ctname in ipairs(containers) do
stats_print(ctname, stats[ctname]) stats_print(ctname, stats[ctname], stats_total)
printf("\n") printf("\n")
if (index >= optarg["m"]) then if (index >= optarg["m"]) then
break break
end end
end end
stats_print(string.format("TOTAL (%-2d)", #containers), stats_total) stats_print(string.format("TOTAL (%-2d)", #containers), stats_total, stats_total)
io.flush() io.flush()
core.usleep(optarg["d"] * 1000000) core.usleep(optarg["d"] * 1000000)
end end
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