Skip to content

Commit

Permalink
Fixed: Precision for cpu and memory did not work properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ualex73 committed May 24, 2024
1 parent 13ecb4c commit 1a28016
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions custom_components/monitor_docker/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,11 @@ async def _run_docker_info(self) -> None:
self._info[ATTR_MEMORY_LIMIT] is not None
and self._info[ATTR_MEMORY_LIMIT] != 0
):
self._info[DOCKER_STATS_MEMORY_PERCENTAGE] = (
self._info[DOCKER_STATS_MEMORY_PERCENTAGE] = round(
self._info[DOCKER_STATS_MEMORY]
/ toMB(
self._info[ATTR_MEMORY_LIMIT],
self._config[CONF_PRECISION_MEMORY_PERCENTAGE],
)
* 100
/ toMB(self._info[ATTR_MEMORY_LIMIT], 4)
* 100,
self._config[CONF_PRECISION_MEMORY_PERCENTAGE],
)

# Try to fix possible 0 values in history at start-up
Expand Down Expand Up @@ -922,7 +920,7 @@ async def _run_container_stats(self) -> None:
(cpu_delta / system_delta)
* float(cpu_stats["online_cpus"])
* 100.0,
PRECISION,
self._config[CONF_PRECISION_CPU],
)

self._cpu_old = cpu_new
Expand Down Expand Up @@ -991,7 +989,7 @@ async def _run_container_stats(self) -> None:
)
memory_stats["usage_percent"] = round(
float(memory_stats["usage"]) / float(memory_stats["limit"]) * 100.0,
PRECISION,
self._config[CONF_PRECISION_MEMORY_PERCENTAGE],
)

if self._memory_error > 0:
Expand Down

0 comments on commit 1a28016

Please sign in to comment.