summaryrefslogtreecommitdiff
path: root/libpod/pod.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-08-08 15:16:01 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-08-17 07:55:36 +0000
commitbf741b3ea30f9431775f03cca081758efcb780b1 (patch)
tree07e1b78dc585c2f4c70c04ef49b8c7cd92d59193 /libpod/pod.go
parent1b87fbc591bf13bc7ba55d5a70334237fe8620d7 (diff)
downloadpodman-bf741b3ea30f9431775f03cca081758efcb780b1.tar.gz
podman-bf741b3ea30f9431775f03cca081758efcb780b1.tar.bz2
podman-bf741b3ea30f9431775f03cca081758efcb780b1.zip
podman pod stats
add the ability to monitor container statistics in a pod. Signed-off-by: baude <bbaude@redhat.com> Closes: #1265 Approved by: rhatdan
Diffstat (limited to 'libpod/pod.go')
-rw-r--r--libpod/pod.go44
1 files changed, 41 insertions, 3 deletions
diff --git a/libpod/pod.go b/libpod/pod.go
index 5d762190b..e5d491e52 100644
--- a/libpod/pod.go
+++ b/libpod/pod.go
@@ -148,16 +148,54 @@ func (p *Pod) AllContainersByID() ([]string, error) {
// AllContainers retrieves the containers in the pod
func (p *Pod) AllContainers() ([]*Container, error) {
- p.lock.Lock()
- defer p.lock.Unlock()
-
if !p.valid {
return nil, ErrPodRemoved
}
+ p.lock.Lock()
+ defer p.lock.Unlock()
+ return p.allContainers()
+}
+func (p *Pod) allContainers() ([]*Container, error) {
return p.runtime.state.PodContainers(p)
}
// TODO add pod batching
// Lock pod to avoid lock contention
// Store and lock all containers (no RemoveContainer in batch guarantees cache will not become stale)
+
+// PodContainerStats is an organization struct for pods and their containers
+type PodContainerStats struct {
+ Pod *Pod
+ ContainerStats map[string]*ContainerStats
+}
+
+// GetPodStats returns the stats for each of its containers
+func (p *Pod) GetPodStats(previousContainerStats map[string]*ContainerStats) (map[string]*ContainerStats, error) {
+ var (
+ ok bool
+ prevStat *ContainerStats
+ )
+ p.lock.Lock()
+ defer p.lock.Unlock()
+
+ if err := p.updatePod(); err != nil {
+ return nil, err
+ }
+ containers, err := p.runtime.state.PodContainers(p)
+ if err != nil {
+ return nil, err
+ }
+ newContainerStats := make(map[string]*ContainerStats)
+ for _, c := range containers {
+ if prevStat, ok = previousContainerStats[c.ID()]; !ok {
+ prevStat = &ContainerStats{}
+ }
+ newStats, err := c.GetContainerStats(prevStat)
+ if err != nil {
+ return nil, err
+ }
+ newContainerStats[c.ID()] = newStats
+ }
+ return newContainerStats, nil
+}