The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/1808
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From e46441d3c131c886cfde9c928e211b246ca80497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com> Date: Fri, 25 Mar 2016 20:07:12 -0400 Subject: [PATCH] Add resource reporting to lxc info MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber <stgra...@ubuntu.com> --- lxc/info.go | 60 ++++++++++++++++++++++++++++++++++++++-- po/lxd.pot | 86 +++++++++++++++++++++++++++++++++++++++++++++------------- shared/util.go | 17 ++++++++++++ 3 files changed, 142 insertions(+), 21 deletions(-) diff --git a/lxc/info.go b/lxc/info.go index 9f76181..58e495c 100644 --- a/lxc/info.go +++ b/lxc/info.go @@ -8,6 +8,7 @@ import ( "gopkg.in/yaml.v2" "github.com/lxc/lxd" + "github.com/lxc/lxd/shared" "github.com/lxc/lxd/shared/gnuflag" "github.com/lxc/lxd/shared/i18n" ) @@ -98,8 +99,8 @@ func (c *infoCmd) containerInfo(d *lxd.Client, name string, showLog bool) error fmt.Printf(i18n.G("Profiles: %s")+"\n", strings.Join(ct.Profiles, ", ")) if cs.Pid != 0 { fmt.Printf(i18n.G("Pid: %d")+"\n", cs.Pid) - fmt.Printf(i18n.G("Processes: %d")+"\n", cs.Processes) + // IP addresses ipInfo := "" for netName, net := range cs.Network { vethStr := "" @@ -113,9 +114,64 @@ func (c *infoCmd) containerInfo(d *lxd.Client, name string, showLog bool) error } if ipInfo != "" { - fmt.Printf(i18n.G("Ips:") + "\n") + fmt.Println(i18n.G("Ips:")) fmt.Printf(ipInfo) } + fmt.Println(i18n.G("Resources:")) + + // Processes + fmt.Printf(" "+i18n.G("Processes: %d")+"\n", cs.Processes) + + // Disk usage + diskInfo := "" + for entry, disk := range cs.Disk { + if disk.Usage != 0 { + diskInfo += fmt.Sprintf(" %s: %s\n", entry, shared.GetByteSizeString(disk.Usage)) + } + } + + if diskInfo != "" { + fmt.Println(i18n.G(" Disk usage:")) + fmt.Printf(diskInfo) + } + + // Memory usage + memoryInfo := "" + if cs.Memory.Usage != 0 { + memoryInfo += fmt.Sprintf(" %s: %s\n", i18n.G("Memory (current)"), shared.GetByteSizeString(cs.Memory.Usage)) + } + + if cs.Memory.UsagePeak != 0 { + memoryInfo += fmt.Sprintf(" %s: %s\n", i18n.G("Memory (peak)"), shared.GetByteSizeString(cs.Memory.UsagePeak)) + } + + if cs.Memory.SwapUsage != 0 { + memoryInfo += fmt.Sprintf(" %s: %s\n", i18n.G("Swap (current)"), shared.GetByteSizeString(cs.Memory.SwapUsage)) + } + + if cs.Memory.SwapUsagePeak != 0 { + memoryInfo += fmt.Sprintf(" %s: %s\n", i18n.G("Swap (peak)"), shared.GetByteSizeString(cs.Memory.SwapUsagePeak)) + } + + if memoryInfo != "" { + fmt.Println(i18n.G(" Memory usage:")) + fmt.Printf(memoryInfo) + } + + // Network usage + networkInfo := "" + for netName, net := range cs.Network { + networkInfo += fmt.Sprintf(" %s:\n", netName) + networkInfo += fmt.Sprintf(" %s: %s\n", i18n.G("Bytes received"), shared.GetByteSizeString(net.Counters.BytesReceived)) + networkInfo += fmt.Sprintf(" %s: %s\n", i18n.G("Bytes sent"), shared.GetByteSizeString(net.Counters.BytesSent)) + networkInfo += fmt.Sprintf(" %s: %d\n", i18n.G("Packets received"), net.Counters.PacketsReceived) + networkInfo += fmt.Sprintf(" %s: %d\n", i18n.G("Packets sent"), net.Counters.PacketsReceived) + } + + if networkInfo != "" { + fmt.Println(i18n.G(" Network usage:")) + fmt.Printf(networkInfo) + } } // List snapshots diff --git a/po/lxd.pot b/po/lxd.pot index 5d98666..b78cf8a 100644 --- a/po/lxd.pot +++ b/po/lxd.pot @@ -7,7 +7,7 @@ msgid "" msgstr "Project-Id-Version: lxd\n" "Report-Msgid-Bugs-To: lxc-devel@lists.linuxcontainers.org\n" - "POT-Creation-Date: 2016-03-23 17:02-0400\n" + "POT-Creation-Date: 2016-03-25 20:07-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <l...@li.org>\n" @@ -16,6 +16,18 @@ msgstr "Project-Id-Version: lxd\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" +#: lxc/info.go:134 +msgid " Disk usage:" +msgstr "" + +#: lxc/info.go:157 +msgid " Memory usage:" +msgstr "" + +#: lxc/info.go:172 +msgid " Network usage:" +msgstr "" + #: lxc/config.go:37 msgid "### This is a yaml representation of the configuration.\n" "### Any line starting with a '# will be ignored.\n" @@ -107,7 +119,7 @@ msgstr "" msgid "An environment variable of the form HOME=/home/foo" msgstr "" -#: lxc/image.go:316 lxc/info.go:87 +#: lxc/image.go:316 lxc/info.go:88 #, c-format msgid "Architecture: %s" msgstr "" @@ -121,6 +133,14 @@ msgstr "" msgid "Available commands:" msgstr "" +#: lxc/info.go:165 +msgid "Bytes received" +msgstr "" + +#: lxc/info.go:166 +msgid "Bytes sent" +msgstr "" + #: lxc/config.go:270 msgid "COMMON NAME" msgstr "" @@ -225,7 +245,7 @@ msgid "Create a read-only snapshot of a container.\n" "lxc snapshot u1 snap0" msgstr "" -#: lxc/image.go:321 lxc/info.go:89 +#: lxc/image.go:321 lxc/info.go:90 #, c-format msgid "Created: %s" msgstr "" @@ -403,7 +423,7 @@ msgstr "" msgid "Invalid target %s" msgstr "" -#: lxc/info.go:116 +#: lxc/info.go:117 msgid "Ips:" msgstr "" @@ -429,7 +449,7 @@ msgid "Launch a container from a particular image.\n" "lxc launch ubuntu u1" msgstr "" -#: lxc/info.go:24 +#: lxc/info.go:25 msgid "List information on containers.\n" "\n" "This will support remotes and images as well, but only containers for now.\n" @@ -466,7 +486,7 @@ msgid "Lists the available resources.\n" "Fast column layout: nsacPt" msgstr "" -#: lxc/info.go:159 +#: lxc/info.go:215 msgid "Log:" msgstr "" @@ -633,6 +653,14 @@ msgid "Manipulate container images.\n" " List the aliases.\n" msgstr "" +#: lxc/info.go:141 +msgid "Memory (current)" +msgstr "" + +#: lxc/info.go:145 +msgid "Memory (peak)" +msgstr "" + #: lxc/help.go:86 msgid "Missing summary." msgstr "" @@ -677,7 +705,7 @@ msgstr "" msgid "NO" msgstr "" -#: lxc/info.go:86 +#: lxc/info.go:87 #, c-format msgid "Name: %s" msgstr "" @@ -735,6 +763,14 @@ msgstr "" msgid "PUBLIC" msgstr "" +#: lxc/info.go:167 +msgid "Packets received" +msgstr "" + +#: lxc/info.go:168 +msgid "Packets sent" +msgstr "" + #: lxc/help.go:69 msgid "Path to an alternate client configuration directory." msgstr "" @@ -747,7 +783,7 @@ msgstr "" msgid "Permisson denied, are you in the lxd group?" msgstr "" -#: lxc/info.go:100 +#: lxc/info.go:101 #, c-format msgid "Pid: %d" msgstr "" @@ -784,7 +820,7 @@ msgid "Prints the version number of LXD.\n" "lxc version" msgstr "" -#: lxc/info.go:101 +#: lxc/info.go:123 #, c-format msgid "Processes: %d" msgstr "" @@ -808,7 +844,7 @@ msgstr "" msgid "Profile to apply to the new container" msgstr "" -#: lxc/info.go:98 +#: lxc/info.go:99 #, c-format msgid "Profiles: %s" msgstr "" @@ -845,6 +881,10 @@ msgstr "" msgid "Require user confirmation." msgstr "" +#: lxc/info.go:120 +msgid "Resources:" +msgstr "" + #: lxc/init.go:246 #, c-format msgid "Retrieving image: %s" @@ -907,7 +947,7 @@ msgstr "" msgid "Show all commands (not just interesting ones)" msgstr "" -#: lxc/info.go:33 +#: lxc/info.go:34 msgid "Show the container's last 100 log lines?" msgstr "" @@ -916,7 +956,7 @@ msgstr "" msgid "Size: %.2fMB" msgstr "" -#: lxc/info.go:130 +#: lxc/info.go:186 msgid "Snapshots:" msgstr "" @@ -929,7 +969,7 @@ msgstr "" msgid "Starting %s" msgstr "" -#: lxc/info.go:92 +#: lxc/info.go:93 #, c-format msgid "Status: %s" msgstr "" @@ -946,6 +986,14 @@ msgstr "" msgid "Store the container state (only for stop)." msgstr "" +#: lxc/info.go:149 +msgid "Swap (current)" +msgstr "" + +#: lxc/info.go:153 +msgid "Swap (peak)" +msgstr "" + #: lxc/list.go:343 msgid "TYPE" msgstr "" @@ -984,11 +1032,11 @@ msgstr "" msgid "Try `lxc info --show-log %s` for more info" msgstr "" -#: lxc/info.go:94 +#: lxc/info.go:95 msgid "Type: ephemeral" msgstr "" -#: lxc/info.go:96 +#: lxc/info.go:97 msgid "Type: persistent" msgstr "" @@ -1125,20 +1173,20 @@ msgstr "" msgid "remote %s is static and cannot be modified" msgstr "" -#: lxc/info.go:139 +#: lxc/info.go:195 msgid "stateful" msgstr "" -#: lxc/info.go:141 +#: lxc/info.go:197 msgid "stateless" msgstr "" -#: lxc/info.go:135 +#: lxc/info.go:191 #, c-format msgid "taken at %s" msgstr "" -#: lxc/exec.go:159 +#: lxc/exec.go:167 msgid "unreachable return reached" msgstr "" diff --git a/shared/util.go b/shared/util.go index e851cfb..ec25140 100644 --- a/shared/util.go +++ b/shared/util.go @@ -657,6 +657,23 @@ func ParseBitSizeString(input string) (int64, error) { return valueInt * multiplicator, nil } +func GetByteSizeString(input int64) string { + if input < 1024 { + return fmt.Sprintf("%d bytes", input) + } + + value := float64(input) + + for _, unit := range []string{"kB", "MB", "GB", "TB", "PB", "EB"} { + value = value / 1024 + if value < 1024 { + return fmt.Sprintf("%.2f%s", value, unit) + } + } + + return fmt.Sprintf("%.2fEB", value) +} + type TransferProgress struct { io.Reader percentage float64
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel