Skip to content

Commit

Permalink
Retain container statistics between poll iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
bobf committed Apr 15, 2021
1 parent d78e366 commit 63f30f7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions agent/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

class StatRunner:
cache = collections.deque([], 10)
container_cache = {}

def __init__(self, **kwargs):
self.opts = kwargs
Expand Down Expand Up @@ -170,6 +171,9 @@ def container_definition(self, container, with_stats=False):
definition = { 'id': container.id, 'name': container.name }
if with_stats:
definition.update(self.docker().containers.get(container.id).stats(stream=False))
self.container_cache[container.id] = definition
elif container.id in self.container_cache:
definition.update(self.container_cache[container.id])
definition['polled'] = with_stats
# Remove `/` prefix from container name; may be a slight bug in Python Docker library.
definition['name'] = definition['name'].strip('/')
Expand Down

0 comments on commit 63f30f7

Please sign in to comment.