summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/varlink/io.podman.varlink30
-rw-r--r--pkg/varlinkapi/pods.go33
2 files changed, 61 insertions, 2 deletions
diff --git a/cmd/podman/varlink/io.podman.varlink b/cmd/podman/varlink/io.podman.varlink
index 3d4a8fa84..2fc53b43e 100644
--- a/cmd/podman/varlink/io.podman.varlink
+++ b/cmd/podman/varlink/io.podman.varlink
@@ -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)
diff --git a/pkg/varlinkapi/pods.go b/pkg/varlinkapi/pods.go
index 640dd665e..75733db11 100644
--- a/pkg/varlinkapi/pods.go
+++ b/pkg/varlinkapi/pods.go
@@ -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)
+}