summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/generic/containers_stats.go
diff options
context:
space:
mode:
authorMatej Marusak <mmarusak@redhat.com>2020-02-13 20:21:53 +0100
committerMatej Marusak <mmarusak@redhat.com>2020-02-17 20:05:14 +0100
commit98774e14762ac0a1010bd1785c362f7d24ff63fd (patch)
treee7358de89305a901c452004d8c16d185d59b2e39 /pkg/api/handlers/generic/containers_stats.go
parente4e5efc12b7902a22561170ca59f3da90b7b80ce (diff)
downloadpodman-98774e14762ac0a1010bd1785c362f7d24ff63fd.tar.gz
podman-98774e14762ac0a1010bd1785c362f7d24ff63fd.tar.bz2
podman-98774e14762ac0a1010bd1785c362f7d24ff63fd.zip
stats: Expose CPU usage in API
`stats.CPU` is a number representing CPU usage in percents. It is possible to calculate it from other exposed fields (once they are implemented correctly) but why to do it, when this is already calculated. This does not break API, it just adds another field. Signed-off-by: Matej Marusak <mmarusak@redhat.com>
Diffstat (limited to 'pkg/api/handlers/generic/containers_stats.go')
-rw-r--r--pkg/api/handlers/generic/containers_stats.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/pkg/api/handlers/generic/containers_stats.go b/pkg/api/handlers/generic/containers_stats.go
index 19e2cc882..977979741 100644
--- a/pkg/api/handlers/generic/containers_stats.go
+++ b/pkg/api/handlers/generic/containers_stats.go
@@ -7,7 +7,6 @@ import (
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/define"
- "github.com/containers/libpod/pkg/api/handlers"
"github.com/containers/libpod/pkg/api/handlers/utils"
"github.com/containers/libpod/pkg/cgroups"
docker "github.com/docker/docker/api/types"
@@ -58,17 +57,18 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) {
}
var preRead time.Time
- var preCPUStats docker.CPUStats
+ var preCPUStats CPUStats
if query.Stream {
preRead = time.Now()
systemUsage, _ := cgroups.GetSystemCPUUsage()
- preCPUStats = docker.CPUStats{
+ preCPUStats = CPUStats{
CPUUsage: docker.CPUUsage{
TotalUsage: stats.CPUNano,
PercpuUsage: stats.PerCPU,
UsageInKernelmode: stats.CPUSystemNano,
UsageInUsermode: stats.CPUNano - stats.CPUSystemNano,
},
+ CPU: stats.CPU,
SystemUsage: systemUsage,
OnlineCPUs: 0,
ThrottlingData: docker.ThrottlingData{},
@@ -124,9 +124,8 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) {
}
systemUsage, _ := cgroups.GetSystemCPUUsage()
-
- s := handlers.Stats{StatsJSON: docker.StatsJSON{
- Stats: docker.Stats{
+ s := StatsJSON{
+ Stats: Stats{
Read: time.Now(),
PreRead: preRead,
PidsStats: docker.PidsStats{
@@ -143,13 +142,14 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) {
IoTimeRecursive: nil,
SectorsRecursive: nil,
},
- CPUStats: docker.CPUStats{
+ CPUStats: CPUStats{
CPUUsage: docker.CPUUsage{
TotalUsage: cgroupStat.CPU.Usage.Total,
PercpuUsage: cgroupStat.CPU.Usage.PerCPU,
UsageInKernelmode: cgroupStat.CPU.Usage.Kernel,
UsageInUsermode: cgroupStat.CPU.Usage.Total - cgroupStat.CPU.Usage.Kernel,
},
+ CPU: stats.CPU,
SystemUsage: systemUsage,
OnlineCPUs: uint32(len(cgroupStat.CPU.Usage.PerCPU)),
ThrottlingData: docker.ThrottlingData{
@@ -173,7 +173,7 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) {
Name: stats.Name,
ID: stats.ContainerID,
Networks: net,
- }}
+ }
utils.WriteJSON(w, http.StatusOK, s)
if flusher, ok := w.(http.Flusher); ok {