lxc-top.lua revision 5a21336025eec5b4228994d0efece129257411bd
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano-- This library is free software; you can redistribute it and/or modify
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano-- it under the terms of the GNU General Public License version 2, as
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano-- This program is distributed in the hope that it will be useful,
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano-- but WITHOUT ANY WARRANTY; without even the implied warranty of
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano-- You should have received a copy of the GNU General Public License along
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano-- with this program; if not, write to the Free Software Foundation, Inc.,
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano local function wrapper(...) io.write(string.format(...)) end
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano table.insert(cols, string.sub(self, start, nextc-1))
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano table.insert(cols, string.sub(self, start, string.len(self)))
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano local KiB = 1024
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano local MiB = 1048576
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano local GiB = 1073741824
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano local TiB = 1099511627776
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano local PiB = 1125899906842624
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano local EiB = 1152921504606846976
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano local ZiB = 1180591620717411303424
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano return string.format("%d.%2.2d ZB", size / ZiB, (math.floor(size % ZiB) * 100) / ZiB)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano return string.format("%d.%2.2d EB", size / EiB, (math.floor(size % EiB) * 100) / EiB)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano return string.format("%d.%2.2d PB", size / PiB, (math.floor(size % PiB) * 100) / PiB)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano return string.format("%d.%2.2d TB", size / TiB, (math.floor(size % TiB) * 100) / TiB)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano return string.format("%d.%2.2d GB", size / GiB, (math.floor(size % GiB) * 100) / GiB)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano return string.format("%d.%2.2d MB", size / MiB, (math.floor(size % MiB) * 1000) / (MiB * 10))
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano return string.format("%d.%2.2d KB", size / KiB, (math.floor(size % KiB) * 1000) / (KiB * 10))
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano elseif (optarg["s"] == "c") then return (stats[a].cpu_use_nanos < stats[b].cpu_use_nanos)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano elseif (optarg["s"] == "d") then return (stats[a].blkio < stats[b].blkio)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano elseif (optarg["s"] == "m") then return (stats[a].mem_used < stats[b].mem_used)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano elseif (optarg["s"] == "k") then return (stats[a].kmem_used < stats[b].kmem_used)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano elseif (optarg["s"] == "c") then return (stats[a].cpu_use_nanos > stats[b].cpu_use_nanos)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano elseif (optarg["s"] == "d") then return (stats[a].blkio > stats[b].blkio)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano elseif (optarg["s"] == "m") then return (stats[a].mem_used > stats[b].mem_used)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano elseif (optarg["s"] == "k") then return (stats[a].kmem_used > stats[b].kmem_used)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano -- note, this is a "mixed" table, ie both dictionary and list
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano -- get stats for all current containers and resort the list
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano stats[ctname] = containers[ctname]:stats_get(stats_total)
name,
stats.cpu_use_nanos / 1000000000,
--os.execute("tput clear")
stats_print(string.format("TOTAL (%-2d)", #containers), stats_total, stats_total)
io.flush()
core.usleep(optarg["d"] * 1000000)