Merge pull request #15364 from rhatdan/stats

Add podman stats --no-trunc option
This commit is contained in:
OpenShift Merge Robot
2022-08-17 21:46:21 +00:00
committed by GitHub
3 changed files with 17 additions and 1 deletions

View File

@ -58,6 +58,7 @@ type statsOptionsCLI struct {
var ( var (
statsOptions statsOptionsCLI statsOptions statsOptionsCLI
notrunc bool
) )
func statFlags(cmd *cobra.Command) { func statFlags(cmd *cobra.Command) {
@ -69,6 +70,7 @@ func statFlags(cmd *cobra.Command) {
flags.StringVar(&statsOptions.Format, formatFlagName, "", "Pretty-print container statistics to JSON or using a Go template") flags.StringVar(&statsOptions.Format, formatFlagName, "", "Pretty-print container statistics to JSON or using a Go template")
_ = cmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(&containerStats{})) _ = cmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(&containerStats{}))
flags.BoolVar(&notrunc, "no-trunc", false, "Do not truncate output")
flags.BoolVar(&statsOptions.NoReset, "no-reset", false, "Disable resetting the screen between intervals") flags.BoolVar(&statsOptions.NoReset, "no-reset", false, "Disable resetting the screen between intervals")
flags.BoolVar(&statsOptions.NoStream, "no-stream", false, "Disable streaming stats and only pull the first result, default setting is false") flags.BoolVar(&statsOptions.NoStream, "no-stream", false, "Disable streaming stats and only pull the first result, default setting is false")
intervalFlagName := "interval" intervalFlagName := "interval"
@ -186,6 +188,9 @@ type containerStats struct {
} }
func (s *containerStats) ID() string { func (s *containerStats) ID() string {
if notrunc {
return s.ContainerID
}
return s.ContainerID[0:12] return s.ContainerID[0:12]
} }

View File

@ -61,6 +61,10 @@ Do not clear the terminal/screen in between reporting intervals
Disable streaming stats and only pull the first result, default setting is false Disable streaming stats and only pull the first result, default setting is false
#### **--no-trunc**
Do not truncate output
## EXAMPLE ## EXAMPLE
``` ```
@ -76,6 +80,12 @@ ID NAME CPU % MEM USAGE / LIMIT MEM % NET IO BL
a9f807ffaacd frosty_hodgkin -- 3.092MB / 16.7GB 0.02% -- / -- -- / -- 2 a9f807ffaacd frosty_hodgkin -- 3.092MB / 16.7GB 0.02% -- / -- -- / -- 2
``` ```
```
$ podman stats --no-trunc 3667 --format 'table {{ .ID }} {{ .MemUsage }}'
ID MEM USAGE / LIMIT
3667c6aacb06aac2eaffce914c01736420023d56ef9b0f4cfe58b6d6a78b7503 49.15kB / 67.17GB
```
``` ```
# podman stats --no-stream --format=json a9f80 # podman stats --no-stream --format=json a9f80
[ [

View File

@ -79,9 +79,10 @@ var _ = Describe("Podman stats", func() {
session := podmanTest.RunTopContainer("") session := podmanTest.RunTopContainer("")
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
session = podmanTest.Podman([]string{"stats", "--all", "--no-stream", "--format", "\"{{.ID}}\""}) session = podmanTest.Podman([]string{"stats", "--all", "--no-trunc", "--no-stream", "--format", "\"{{.ID}}\""})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray()[0])).Should(BeEquivalentTo(66))
}) })
It("podman stats with GO template", func() { It("podman stats with GO template", func() {