Display Docker container's used memory instead of total memory

This commit is contained in:
Sebastian Osiński 2023-03-28 19:40:09 +02:00
parent 58bb5a2bbf
commit e549a87719
4 changed files with 9 additions and 4 deletions

View file

@ -3,7 +3,7 @@
"build": {
"dockerfile": "Dockerfile",
"args": {
"VARIANT": "18-buster"
"VARIANT": "18-bullseye"
}
},
"customizations": {

1
.gitignore vendored
View file

@ -4,6 +4,7 @@
/node_modules
/.pnp
.pnp.js
.pnpm-store
# testing
/coverage

View file

@ -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 }) {
<Container service={service}>
<Block label="docker.cpu" value={t("common.percent", { value: calculateCPUPercent(statsData.stats) })} />
{statsData.stats.memory_stats.usage &&
<Block label="docker.mem" value={t("common.bytes", { value: statsData.stats.memory_stats.usage })} />
<Block label="docker.mem" value={t("common.bytes", { value: calculateUsedMemory(statsData.stats) })} />
}
{network && (
<>

View file

@ -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
}