Skip to content

Commit

Permalink
Fixed: Total memory percentage is wrong when limits are set
Browse files Browse the repository at this point in the history
  • Loading branch information
ualex73 committed Oct 24, 2020
1 parent 2b46276 commit 0b4c5d1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions custom_components/monitor_docker/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,6 @@ async def _run_docker_info(self):
self._info[DOCKER_STATS_MEMORY] += stats.get(
CONTAINER_STATS_MEMORY
)
if stats.get(CONTAINER_STATS_MEMORY_PERCENTAGE) is not None:
self._info[DOCKER_STATS_MEMORY_PERCENTAGE] += stats.get(
CONTAINER_STATS_MEMORY_PERCENTAGE
)
except Exception as err:
_LOGGER.error(
"%s: run_docker_info memory/cpu of X (%s)",
Expand All @@ -405,6 +401,18 @@ async def _run_docker_info(self):
exc_info=True,
)

# Calculate memory percentage
if (
self._info[ATTR_MEMORY_LIMIT] is not None
and self._info[ATTR_MEMORY_LIMIT] is not 0
):
self._info[DOCKER_STATS_MEMORY_PERCENTAGE] = round(
self._info[DOCKER_STATS_MEMORY]
/ toMB(self._info[ATTR_MEMORY_LIMIT])
* 100,
PRECISION,
)

# Try to fix possible 0 values in history at start-up
self._info[DOCKER_STATS_CPU_PERCENTAGE] = (
None
Expand Down

0 comments on commit 0b4c5d1

Please sign in to comment.