summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/libpod
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/api/handlers/libpod
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/api/handlers/libpod')
-rw-r--r--pkg/api/handlers/libpod/containers_stats.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/pkg/api/handlers/libpod/containers_stats.go b/pkg/api/handlers/libpod/containers_stats.go
index 75c404d4f..1807823fa 100644
--- a/pkg/api/handlers/libpod/containers_stats.go
+++ b/pkg/api/handlers/libpod/containers_stats.go
@@ -3,7 +3,6 @@ package libpod
import (
"encoding/json"
"net/http"
- "time"
"github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/pkg/api/handlers/utils"
@@ -14,8 +13,6 @@ import (
"github.com/sirupsen/logrus"
)
-const DefaultStatsPeriod = 5 * time.Second
-
func StatsContainer(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
decoder := r.Context().Value("decoder").(*schema.Decoder)
@@ -23,8 +20,10 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) {
query := struct {
Containers []string `schema:"containers"`
Stream bool `schema:"stream"`
+ Interval int `schema:"interval"`
}{
- Stream: true,
+ Stream: true,
+ Interval: 5,
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
@@ -36,7 +35,8 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) {
containerEngine := abi.ContainerEngine{Libpod: runtime}
statsOptions := entities.ContainerStatsOptions{
- Stream: query.Stream,
+ Stream: query.Stream,
+ Interval: query.Interval,
}
// Stats will stop if the connection is closed.