Add GetPodStats to varlink

Signed-off-by: haircommander <pehunt@redhat.com>

Closes: #1319
Approved by: baude
This commit is contained in:
haircommander 2018-08-21 16:32:21 -04:00 committed by Atomic Bot
parent 7310697b73
commit 3df6332a65
2 changed files with 61 additions and 2 deletions

View file

@ -757,8 +757,34 @@ method WaitPod() -> (notimplemented: NotImplemented)
# This method has not been implemented yet.
method TopPod() -> (notimplemented: NotImplemented)
# This method has not been implemented yet.
method StatsPod() -> (notimplemented: NotImplemented)
# GetPodStats takes the name or ID of a pod and returns a pod name and slice of ContainerStats structure which
# contains attributes like memory and cpu usage. If the pod cannot be found, a [PodNotFound](#PodNotFound)
# error will be returned.
# #### Example
# ~~~
# $ varlink call unix:/run/podman/io.podman/io.podman.GetPodStats '{"name": "7f62b508b6f12b11d8fe02e"}'
# {
# "containers": [
# {
# "block_input": 0,
# "block_output": 0,
# "cpu": 2.833470544016107524276e-08,
# "cpu_nano": 54363072,
# "id": "a64b51f805121fe2c5a3dc5112eb61d6ed139e3d1c99110360d08b58d48e4a93",
# "mem_limit": 12276146176,
# "mem_perc": 7.974359265237864966003e-03,
# "mem_usage": 978944,
# "name": "quirky_heisenberg",
# "net_input": 866,
# "net_output": 7388,
# "pids": 1,
# "system_nano": 20000000
# }
# ],
# "pod": "7f62b508b6f12b11d8fe02e0db4de6b9e43a7d7699b33a4fc0d574f6e82b4ebd"
# }
# ~~~
method GetPodStats(name: string) -> (pod: string, containers: []ContainerStats)
# ImageNotFound means the image could not be found by the provided name or ID in local storage.
error ImageNotFound (name: string)

View file

@ -187,3 +187,36 @@ func (i *LibpodAPI) RemovePod(call iopodman.VarlinkCall, name string, force bool
return call.ReplyRemovePod(pod.ID())
}
// GetPodStats ...
func (i *LibpodAPI) GetPodStats(call iopodman.VarlinkCall, name string) error {
pod, err := i.Runtime.LookupPod(name)
if err != nil {
return call.ReplyPodNotFound(name)
}
prevStats := make(map[string]*libpod.ContainerStats)
podStats, err := pod.GetPodStats(prevStats)
if err != nil {
return call.ReplyErrorOccurred(err.Error())
}
containersStats := make([]iopodman.ContainerStats, 0)
for ctrID, containerStats := range podStats {
cs := iopodman.ContainerStats{
Id: ctrID,
Name: containerStats.Name,
Cpu: containerStats.CPU,
Cpu_nano: int64(containerStats.CPUNano),
System_nano: int64(containerStats.SystemNano),
Mem_usage: int64(containerStats.MemUsage),
Mem_limit: int64(containerStats.MemLimit),
Mem_perc: containerStats.MemPerc,
Net_input: int64(containerStats.NetInput),
Net_output: int64(containerStats.NetOutput),
Block_input: int64(containerStats.BlockInput),
Block_output: int64(containerStats.BlockOutput),
Pids: int64(containerStats.PIDs),
}
containersStats = append(containersStats, cs)
}
return call.ReplyGetPodStats(pod.ID(), containersStats)
}