summaryrefslogtreecommitdiff
path: root/pkg/domain
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 /pkg/domain
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 'pkg/domain')
-rw-r--r--pkg/domain/entities/containers.go2
-rw-r--r--pkg/domain/infra/abi/containers.go5
-rw-r--r--pkg/domain/infra/tunnel/containers.go2
3 files changed, 7 insertions, 2 deletions
diff --git a/pkg/domain/entities/containers.go b/pkg/domain/entities/containers.go
index 302b35a47..dcb351e82 100644
--- a/pkg/domain/entities/containers.go
+++ b/pkg/domain/entities/containers.go
@@ -435,6 +435,8 @@ type ContainerStatsOptions struct {
Latest bool
// Stream stats.
Stream bool
+ // Interval in seconds
+ Interval int
}
// ContainerStatsReport is used for streaming container stats.
diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go
index 50751aa12..6eeef870f 100644
--- a/pkg/domain/infra/abi/containers.go
+++ b/pkg/domain/infra/abi/containers.go
@@ -1281,6 +1281,9 @@ func (ic *ContainerEngine) Shutdown(_ context.Context) {
}
func (ic *ContainerEngine) ContainerStats(ctx context.Context, namesOrIds []string, options entities.ContainerStatsOptions) (statsChan chan entities.ContainerStatsReport, err error) {
+ if options.Interval < 1 {
+ return nil, errors.New("Invalid interval, must be a positive number greater zero")
+ }
statsChan = make(chan entities.ContainerStatsReport, 1)
containerFunc := ic.Libpod.GetRunningContainers
@@ -1361,7 +1364,7 @@ func (ic *ContainerEngine) ContainerStats(ctx context.Context, namesOrIds []stri
return
}
- time.Sleep(time.Second)
+ time.Sleep(time.Second * time.Duration(options.Interval))
goto stream
}()
diff --git a/pkg/domain/infra/tunnel/containers.go b/pkg/domain/infra/tunnel/containers.go
index c17d7b54f..1df79c373 100644
--- a/pkg/domain/infra/tunnel/containers.go
+++ b/pkg/domain/infra/tunnel/containers.go
@@ -871,7 +871,7 @@ func (ic *ContainerEngine) ContainerStats(ctx context.Context, namesOrIds []stri
if options.Latest {
return nil, errors.New("latest is not supported for the remote client")
}
- return containers.Stats(ic.ClientCtx, namesOrIds, new(containers.StatsOptions).WithStream(options.Stream))
+ return containers.Stats(ic.ClientCtx, namesOrIds, new(containers.StatsOptions).WithStream(options.Stream).WithInterval(options.Interval))
}
// ShouldRestart reports back whether the container will restart