summaryrefslogtreecommitdiff
path: root/pkg/api/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/api/handlers')
-rw-r--r--pkg/api/handlers/generic/containers_stats.go43
1 files changed, 13 insertions, 30 deletions
diff --git a/pkg/api/handlers/generic/containers_stats.go b/pkg/api/handlers/generic/containers_stats.go
index b8021378b..4fb856bdb 100644
--- a/pkg/api/handlers/generic/containers_stats.go
+++ b/pkg/api/handlers/generic/containers_stats.go
@@ -51,10 +51,7 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) {
return
}
if state != define.ContainerStateRunning && !query.Stream {
- utils.WriteJSON(w, http.StatusOK, &handlers.Stats{StatsJSON: docker.StatsJSON{
- Name: ctnr.Name(),
- ID: ctnr.ID(),
- }})
+ utils.InternalServerError(w, define.ErrCtrStateInvalid)
return
}
@@ -82,44 +79,30 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) {
time.Sleep(DefaultStatsPeriod)
}
- // Anonymous function to get the cgroup on demand.
- getCgroup := func() *cgroups.CgroupControl {
- cgroupPath, err := ctnr.CGroupPath()
- if err != nil {
- return &cgroups.CgroupControl{}
- }
-
- cgroup, err := cgroups.Load(cgroupPath)
- if err != nil {
- return &cgroups.CgroupControl{}
- }
-
- return cgroup
- }
-
for ok := true; ok; ok = query.Stream {
- state, err := ctnr.State()
+ // Container stats
+ stats, err := ctnr.GetContainerStats(stats)
if err != nil {
utils.InternalServerError(w, err)
return
}
- if state != define.ContainerStateRunning {
- time.Sleep(10 * time.Second)
- continue
+ inspect, err := ctnr.Inspect(false)
+ if err != nil {
+ utils.InternalServerError(w, err)
+ return
}
-
- cgroup := getCgroup()
- cgroupStat, err := cgroup.Stat()
+ // Cgroup stats
+ cgroupPath, err := ctnr.CGroupPath()
if err != nil {
- cgroupStat = &cgroups.Metrics{}
+ utils.InternalServerError(w, err)
+ return
}
-
- stats, err := ctnr.GetContainerStats(stats)
+ cgroup, err := cgroups.Load(cgroupPath)
if err != nil {
utils.InternalServerError(w, err)
return
}
- inspect, err := ctnr.Inspect(false)
+ cgroupStat, err := cgroup.Stat()
if err != nil {
utils.InternalServerError(w, err)
return