From 63f30f70359c74143f7d6258f177c2e937dd88a3 Mon Sep 17 00:00:00 2001 From: Bob Farrell Date: Thu, 15 Apr 2021 11:38:42 +0100 Subject: [PATCH] Retain container statistics between poll iterations --- agent/app.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/agent/app.py b/agent/app.py index 0905f9f..a21edda 100644 --- a/agent/app.py +++ b/agent/app.py @@ -28,6 +28,7 @@ class StatRunner: cache = collections.deque([], 10) + container_cache = {} def __init__(self, **kwargs): self.opts = kwargs @@ -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('/')