From 3fe03c6856f70e5a88e3aa85cecffd168bdf1149 Mon Sep 17 00:00:00 2001 From: Chris Gilbert Date: Mon, 22 Oct 2018 11:53:55 +0100 Subject: [PATCH] Deduct the cache figure from the memory usage when calculating the memory.percentage metric --- dockerplugin.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dockerplugin.py b/dockerplugin.py index f410cf6..968a304 100755 --- a/dockerplugin.py +++ b/dockerplugin.py @@ -236,9 +236,6 @@ def read_memory_stats(container, dimensions, stats, t): values = [mem_stats['limit'], mem_stats['max_usage'], mem_stats['usage']] emit(container, dimensions, 'memory.usage', values, t=t) - mem_percent = 100.0 * mem_stats['usage'] / mem_stats['limit'] - emit(container, dimensions, 'memory.percent', [mem_percent], t=t) - detailed = mem_stats.get('stats') if detailed: for key, value in detailed.items(): @@ -248,6 +245,14 @@ def read_memory_stats(container, dimensions, stats, t): log.notice('No detailed memory stats available from container {0}.' .format(_c(container))) + if detailed and detailed.get('cache'): + # If we have detailed memory stats then the page cache should be deducted from the usage figure + mem_percent = 100.0 * (mem_stats['usage'] - detailed['cache']) / mem_stats['limit'] + else: + mem_percent = 100.0 * mem_stats['usage'] / mem_stats['limit'] + + emit(container, dimensions, 'memory.percent', [mem_percent], t=t) + def read_cpu_shares_stats(container, container_inspect, cstats,