mirror of
https://github.com/karl0ss/homepage.git
synced 2025-04-29 12:03:41 +01:00
Merge pull request #1156 from SebastianOsinski/improve_docker_memory_stats
Display Docker container's used memory instead of total memory
This commit is contained in:
commit
bffda3240a
@ -3,7 +3,7 @@
|
|||||||
"build": {
|
"build": {
|
||||||
"dockerfile": "Dockerfile",
|
"dockerfile": "Dockerfile",
|
||||||
"args": {
|
"args": {
|
||||||
"VARIANT": "18-buster"
|
"VARIANT": "18-bullseye"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"customizations": {
|
"customizations": {
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,6 +4,7 @@
|
|||||||
/node_modules
|
/node_modules
|
||||||
/.pnp
|
/.pnp
|
||||||
.pnp.js
|
.pnp.js
|
||||||
|
.pnpm-store
|
||||||
|
|
||||||
# testing
|
# testing
|
||||||
/coverage
|
/coverage
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
import { useTranslation } from "next-i18next";
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
import calculateCPUPercent from "./stats-helpers";
|
import { calculateCPUPercent, calculateUsedMemory } from "./stats-helpers";
|
||||||
|
|
||||||
import Container from "components/services/widget/container";
|
import Container from "components/services/widget/container";
|
||||||
import Block from "components/services/widget/block";
|
import Block from "components/services/widget/block";
|
||||||
@ -47,7 +47,7 @@ export default function Component({ service }) {
|
|||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block label="docker.cpu" value={t("common.percent", { value: calculateCPUPercent(statsData.stats) })} />
|
<Block label="docker.cpu" value={t("common.percent", { value: calculateCPUPercent(statsData.stats) })} />
|
||||||
{statsData.stats.memory_stats.usage &&
|
{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 && (
|
{network && (
|
||||||
<>
|
<>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export default function calculateCPUPercent(stats) {
|
export function calculateCPUPercent(stats) {
|
||||||
let cpuPercent = 0.0;
|
let cpuPercent = 0.0;
|
||||||
const cpuDelta = stats.cpu_stats.cpu_usage.total_usage - stats.precpu_stats.cpu_usage.total_usage;
|
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;
|
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;
|
return Math.round(cpuPercent * 10) / 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function calculateUsedMemory(stats) {
|
||||||
|
return stats.memory_stats.usage - (stats.memory_stats.stats.cache ?? 0)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user