summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorAshley Cui <acui@redhat.com>2020-10-13 09:05:38 -0400
committerAshley Cui <acui@redhat.com>2020-10-13 09:08:13 -0400
commit8f603a76f6d7a0a34e5dcb677b8a9e5b87ba0157 (patch)
treec0c9dbc434f1e17eb6bd09bd232dd2c7aa00ca3f /cmd/podman
parent212011f166d6f56421fcc5260def999e71156d32 (diff)
downloadpodman-8f603a76f6d7a0a34e5dcb677b8a9e5b87ba0157.tar.gz
podman-8f603a76f6d7a0a34e5dcb677b8a9e5b87ba0157.tar.bz2
podman-8f603a76f6d7a0a34e5dcb677b8a9e5b87ba0157.zip
Restore --format: stats & pod ps
Restore formatting for stats Fix formatting for pod ps Signed-off-by: Ashley Cui <acui@redhat.com>
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/containers/stats.go37
-rw-r--r--cmd/podman/pods/ps.go13
2 files changed, 31 insertions, 19 deletions
diff --git a/cmd/podman/containers/stats.go b/cmd/podman/containers/stats.go
index bbd389bbf..c30ea52ec 100644
--- a/cmd/podman/containers/stats.go
+++ b/cmd/podman/containers/stats.go
@@ -3,12 +3,13 @@ package containers
import (
"fmt"
"os"
- "strings"
"text/tabwriter"
"text/template"
tm "github.com/buger/goterm"
+ "github.com/containers/podman/v2/cmd/podman/parse"
"github.com/containers/podman/v2/cmd/podman/registry"
+ "github.com/containers/podman/v2/cmd/podman/report"
"github.com/containers/podman/v2/cmd/podman/validate"
"github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/pkg/cgroups"
@@ -58,9 +59,8 @@ type statsOptionsCLI struct {
}
var (
- statsOptions statsOptionsCLI
- defaultStatsRow = "{{.ID}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDS}}\n"
- defaultStatsHeader = "ID\tNAME\tCPU %\tMEM USAGE / LIMIT\tMEM %\tNET IO\tBLOCK IO\tPIDS\n"
+ statsOptions statsOptionsCLI
+ defaultStatsRow = "{{.ID}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDS}}\n"
)
func statFlags(flags *pflag.FlagSet) {
@@ -139,7 +139,16 @@ func stats(cmd *cobra.Command, args []string) error {
}
func outputStats(reports []define.ContainerStats) error {
- if len(statsOptions.Format) < 1 && !statsOptions.NoReset {
+ headers := report.Headers(define.ContainerStats{}, map[string]string{
+ "ID": "ID",
+ "CPUPerc": "CPU %",
+ "MemUsage": "MEM USAGE / LIMIT",
+ "MemPerc": "MEM %",
+ "NetIO": "NET IO",
+ "BlockIO": "BLOCK IO",
+ "PIDS": "PIDS",
+ })
+ if !statsOptions.NoReset {
tm.Clear()
tm.MoveCursor(1, 1)
tm.Flush()
@@ -148,25 +157,27 @@ func outputStats(reports []define.ContainerStats) error {
for _, r := range reports {
stats = append(stats, containerStats{r})
}
- if statsOptions.Format == "json" {
+ if parse.MatchesJSONFormat(statsOptions.Format) {
return outputJSON(stats)
}
format := defaultStatsRow
+
if len(statsOptions.Format) > 0 {
- format = statsOptions.Format
- if !strings.HasSuffix(format, "\n") {
- format += "\n"
- }
+ format = report.NormalizeFormat(statsOptions.Format)
+ } else if len(statsOptions.Format) < 1 {
+ format = defaultStatsRow
}
format = "{{range . }}" + format + "{{end}}"
- if len(statsOptions.Format) < 1 {
- format = defaultStatsHeader + format
- }
tmpl, err := template.New("stats").Parse(format)
if err != nil {
return err
}
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
+ if len(statsOptions.Format) < 1 {
+ if err := tmpl.Execute(w, headers); err != nil {
+ return err
+ }
+ }
if err := tmpl.Execute(w, stats); err != nil {
return err
}
diff --git a/cmd/podman/pods/ps.go b/cmd/podman/pods/ps.go
index b7952e6e3..0013cca02 100644
--- a/cmd/podman/pods/ps.go
+++ b/cmd/podman/pods/ps.go
@@ -106,12 +106,13 @@ func pods(cmd *cobra.Command, _ []string) error {
}
headers := report.Headers(ListPodReporter{}, map[string]string{
- "ContainerIds": "IDS",
- "ContainerNames": "NAMES",
- "ContainerStatuses": "STATUS",
- "Namespace": "NAMESPACES",
+ "Id": "POD ID",
+ "Name": "NAME",
+ "Status": "STATUS",
+ "Labels": "LABELS",
"NumberOfContainers": "# OF CONTAINERS",
- "InfraId": "INFRA ID",
+ "Created": "CREATED",
+ "InfraID": "INFRA ID",
})
row := podPsFormat()
if cmd.Flags().Changed("format") {
@@ -135,7 +136,7 @@ func pods(cmd *cobra.Command, _ []string) error {
}
func podPsFormat() string {
- row := []string{"{{.Id}}", "{{.Name}}", "{{.Status}}", "{{.Created}}}"}
+ row := []string{"{{.Id}}", "{{.Name}}", "{{.Status}}", "{{.Created}}", "{{.InfraID}}"}
if psInput.CtrIds {
row = append(row, "{{.ContainerIds}}")