summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorThomas Weber <towe75@googlemail.com>2021-07-21 07:42:39 +0200
committerThomas Weber <towe75@googlemail.com>2021-07-27 07:20:47 +0200
commitcdbbd79155a7752843f2b420c3036ce6c390a3b6 (patch)
tree2e438fbb7626b5ffa05e140a114e9c75ccc100a9 /cmd
parent389c9b8dca942fb4977823dd504d3d351cb92acd (diff)
downloadpodman-cdbbd79155a7752843f2b420c3036ce6c390a3b6.tar.gz
podman-cdbbd79155a7752843f2b420c3036ce6c390a3b6.tar.bz2
podman-cdbbd79155a7752843f2b420c3036ce6c390a3b6.zip
stats: add a interval parameter to cli and api stream mode
podman stats polled by default in a 1 sec period. This can put quite some load on a machine if you run many containers. The default value is now 5 seconds. You can change this interval with a new, optional, --interval, -i cli flag. The api request got also a interval query parameter for the same purpose. Additionally a unused const was removed. Api and cli will fail the request if a 0 or negative value is passed in. Signed-off-by: Thomas Weber <towe75@googlemail.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/containers/stats.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/cmd/podman/containers/stats.go b/cmd/podman/containers/stats.go
index 208d5d58f..69fef7b79 100644
--- a/cmd/podman/containers/stats.go
+++ b/cmd/podman/containers/stats.go
@@ -5,6 +5,7 @@ import (
"os"
tm "github.com/buger/goterm"
+ "github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/report"
"github.com/containers/podman/v3/cmd/podman/common"
"github.com/containers/podman/v3/cmd/podman/registry"
@@ -55,6 +56,7 @@ type statsOptionsCLI struct {
Latest bool
NoReset bool
NoStream bool
+ Interval int
}
var (
@@ -72,6 +74,9 @@ func statFlags(cmd *cobra.Command) {
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")
+ intervalFlagName := "interval"
+ flags.IntVarP(&statsOptions.Interval, intervalFlagName, "i", 5, "Time in seconds between stats reports")
+ _ = cmd.RegisterFlagCompletionFunc(intervalFlagName, completion.AutocompleteNone)
}
func init() {
@@ -122,8 +127,9 @@ func stats(cmd *cobra.Command, args []string) error {
// Convert to the entities options. We should not leak CLI-only
// options into the backend and separate concerns.
opts := entities.ContainerStatsOptions{
- Latest: statsOptions.Latest,
- Stream: !statsOptions.NoStream,
+ Latest: statsOptions.Latest,
+ Stream: !statsOptions.NoStream,
+ Interval: statsOptions.Interval,
}
statsChan, err := registry.ContainerEngine().ContainerStats(registry.Context(), args, opts)
if err != nil {