summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorumohnani8 <umohnani@redhat.com>2018-01-23 16:50:20 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-01-25 03:23:10 +0000
commit12e3d9d8a26d2c33d587dba9b7ea5b0dcfd92eea (patch)
tree6e596e575eba2c990db4f920baf41ab1bd1210c7 /cmd
parent4c7bab9812b95fed8e6f8255b51b843b3e762782 (diff)
downloadpodman-12e3d9d8a26d2c33d587dba9b7ea5b0dcfd92eea.tar.gz
podman-12e3d9d8a26d2c33d587dba9b7ea5b0dcfd92eea.tar.bz2
podman-12e3d9d8a26d2c33d587dba9b7ea5b0dcfd92eea.zip
Fix podman stats based on QE feedback
QE found issues with formatting the go template and the man page was lacking information. Changed the format of the output to match latest docker. Add shortID function that returns the truncated ID Signed-off-by: umohnani8 <umohnani@redhat.com> Closes: #258 Approved by: rhatdan
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/common.go12
-rw-r--r--cmd/podman/history.go7
-rw-r--r--cmd/podman/images.go2
-rw-r--r--cmd/podman/ps.go2
-rw-r--r--cmd/podman/stats.go41
5 files changed, 38 insertions, 26 deletions
diff --git a/cmd/podman/common.go b/cmd/podman/common.go
index ae4bbd65d..921f30b84 100644
--- a/cmd/podman/common.go
+++ b/cmd/podman/common.go
@@ -22,7 +22,10 @@ var (
}
)
-const crioConfigPath = "/etc/crio/crio.conf"
+const (
+ crioConfigPath = "/etc/crio/crio.conf"
+ idTruncLength = 12
+)
func getRuntime(c *cli.Context) (*libpod.Runtime, error) {
@@ -88,6 +91,13 @@ func splitCamelCase(src string) string {
return strings.Join(entries, " ")
}
+func shortID(id string) string {
+ if len(id) > idTruncLength {
+ return id[:idTruncLength]
+ }
+ return id
+}
+
// validateFlags searches for StringFlags or StringSlice flags that never had
// a value set. This commonly occurs when the CLI mistakenly takes the next
// option and uses it as a value.
diff --git a/cmd/podman/history.go b/cmd/podman/history.go
index f142f5fd4..1164555d3 100644
--- a/cmd/podman/history.go
+++ b/cmd/podman/history.go
@@ -14,10 +14,7 @@ import (
"github.com/urfave/cli"
)
-const (
- createdByTruncLength = 45
- idTruncLength = 12
-)
+const createdByTruncLength = 45
// historyTemplateParams stores info about each layer
type historyTemplateParams struct {
@@ -169,7 +166,7 @@ func getHistoryTemplateOutput(history []v1.History, layers []types.BlobInfo, ima
imageID = "<missing>"
}
if !opts.noTrunc && i == len(history)-1 {
- imageID = imageID[:idTruncLength]
+ imageID = shortID(imageID)
}
var size int64
diff --git a/cmd/podman/images.go b/cmd/podman/images.go
index 90dd8ae12..1f1174950 100644
--- a/cmd/podman/images.go
+++ b/cmd/podman/images.go
@@ -194,7 +194,7 @@ func getImagesTemplateOutput(runtime *libpod.Runtime, images []*storage.Image, o
imageID := "sha256:" + img.ID
if !opts.noTrunc {
- imageID = img.ID[:idTruncLength]
+ imageID = shortID(img.ID)
}
repository := "<none>"
diff --git a/cmd/podman/ps.go b/cmd/podman/ps.go
index 0b75b9a96..e4c90187b 100644
--- a/cmd/podman/ps.go
+++ b/cmd/podman/ps.go
@@ -482,7 +482,7 @@ func getTemplateOutput(containers []*libpod.Container, opts psOptions) ([]psTemp
}
if !opts.noTrunc {
- ctrID = ctr.ID()[:idTruncLength]
+ ctrID = shortID(ctr.ID())
imageName = conConfig.RootfsImageName
}
diff --git a/cmd/podman/stats.go b/cmd/podman/stats.go
index 871eb9e2f..21cca1d83 100644
--- a/cmd/podman/stats.go
+++ b/cmd/podman/stats.go
@@ -15,14 +15,14 @@ import (
)
type statsOutputParams struct {
- Container string `json:"name"`
- ID string `json:"id"`
- CPUPerc string `json:"cpu_percent"`
- MemUsage string `json:"mem_usage"`
- MemPerc string `json:"mem_percent"`
- NetIO string `json:"netio"`
- BlockIO string `json:"blocki"`
- PIDS string `json:"pids"`
+ ID string `json:"id"`
+ Name string `json:"name"`
+ CPUPerc string `json:"cpu_percent"`
+ MemUsage string `json:"mem_usage"`
+ MemPerc string `json:"mem_percent"`
+ NetIO string `json:"netio"`
+ BlockIO string `json:"blocki"`
+ PIDS string `json:"pids"`
}
var (
@@ -37,7 +37,7 @@ var (
},
cli.StringFlag{
Name: "format",
- Usage: "pretty-print container statistics using a Go template",
+ Usage: "pretty-print container statistics to JSON or using a Go template",
},
cli.BoolFlag{
Name: "no-reset",
@@ -184,7 +184,12 @@ func outputStats(stats []*libpod.ContainerStats, format string) error {
}
func genStatsFormat() (format string) {
- return "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDS}}"
+ if format != "" {
+ // "\t" from the command line is not being recognized as a tab
+ // replacing the string "\t" to a tab character if the user passes in "\t"
+ return strings.Replace(format, `\t`, "\t", -1)
+ }
+ return "table {{.ID}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDS}}"
}
// imagesToGeneric creates an empty array of interfaces for output
@@ -248,13 +253,13 @@ func pidsToString(pid uint64) string {
func getStatsOutputParams(stats *libpod.ContainerStats) statsOutputParams {
return statsOutputParams{
- Container: stats.ContainerID[:12],
- ID: stats.ContainerID,
- CPUPerc: floatToPercentString(stats.CPU),
- MemUsage: combineHumanValues(stats.MemUsage, stats.MemLimit),
- MemPerc: floatToPercentString(stats.MemPerc),
- NetIO: combineHumanValues(stats.NetInput, stats.NetOutput),
- BlockIO: combineHumanValues(stats.BlockInput, stats.BlockOutput),
- PIDS: pidsToString(stats.PIDs),
+ Name: stats.Name,
+ ID: shortID(stats.ContainerID),
+ CPUPerc: floatToPercentString(stats.CPU),
+ MemUsage: combineHumanValues(stats.MemUsage, stats.MemLimit),
+ MemPerc: floatToPercentString(stats.MemPerc),
+ NetIO: combineHumanValues(stats.NetInput, stats.NetOutput),
+ BlockIO: combineHumanValues(stats.BlockInput, stats.BlockOutput),
+ PIDS: pidsToString(stats.PIDs),
}
}