From e549a8771945ee5b5bc1adbf67a8711e58d71059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Osi=C5=84ski?= Date: Tue, 28 Mar 2023 19:40:09 +0200 Subject: [PATCH] Display Docker container's used memory instead of total memory --- .devcontainer/devcontainer.json | 2 +- .gitignore | 1 + src/widgets/docker/component.jsx | 4 ++-- src/widgets/docker/stats-helpers.js | 6 +++++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index e547dd7e..15d1b9f3 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,7 +3,7 @@ "build": { "dockerfile": "Dockerfile", "args": { - "VARIANT": "18-buster" + "VARIANT": "18-bullseye" } }, "customizations": { diff --git a/.gitignore b/.gitignore index 5649354a..7fdc6550 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ /node_modules /.pnp .pnp.js +.pnpm-store # testing /coverage diff --git a/src/widgets/docker/component.jsx b/src/widgets/docker/component.jsx index 7ef5e6ce..88b47add 100644 --- a/src/widgets/docker/component.jsx +++ b/src/widgets/docker/component.jsx @@ -1,7 +1,7 @@ import useSWR from "swr"; import { useTranslation } from "next-i18next"; -import calculateCPUPercent from "./stats-helpers"; +import { calculateCPUPercent, calculateUsedMemory } from "./stats-helpers"; import Container from "components/services/widget/container"; import Block from "components/services/widget/block"; @@ -47,7 +47,7 @@ export default function Component({ service }) { {statsData.stats.memory_stats.usage && - + } {network && ( <> diff --git a/src/widgets/docker/stats-helpers.js b/src/widgets/docker/stats-helpers.js index c5cd8a7b..1b73327e 100644 --- a/src/widgets/docker/stats-helpers.js +++ b/src/widgets/docker/stats-helpers.js @@ -1,4 +1,4 @@ -export default function calculateCPUPercent(stats) { +export function calculateCPUPercent(stats) { let cpuPercent = 0.0; const cpuDelta = stats.cpu_stats.cpu_usage.total_usage - stats.precpu_stats.cpu_usage.total_usage; const systemDelta = stats.cpu_stats.system_cpu_usage - stats.precpu_stats.system_cpu_usage; @@ -9,3 +9,7 @@ export default function calculateCPUPercent(stats) { return Math.round(cpuPercent * 10) / 10; } + +export function calculateUsedMemory(stats) { + return stats.memory_stats.usage - stats.memory_stats.stats.cache +} \ No newline at end of file