Skip to content
This repository has been archived by the owner on Mar 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #35 from chrisgilbert/FixMemoryCalculation
Browse files Browse the repository at this point in the history
Deduct the cache figure from the memory usage percentage metric
  • Loading branch information
keitwb authored Oct 30, 2018
2 parents 6f4e377 + 3fe03c6 commit 9859d5a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions dockerplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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,
Expand Down

0 comments on commit 9859d5a

Please sign in to comment.