Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a37e101bba |
No files matched your search
@@ -481,13 +481,14 @@ export function calculateCpuUsage(stats: ContainerStats): number {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const numberOfCpus = stats.cpu_stats.online_cpus;
|
const cpuDelta = stats.cpu_stats.cpu_usage.total_usage - (stats.precpu_stats?.cpu_usage?.total_usage ?? 0);
|
||||||
const usage = stats.cpu_stats.system_cpu_usage;
|
const systemDelta = (stats.cpu_stats.system_cpu_usage ?? 0) - (stats.precpu_stats?.system_cpu_usage ?? 0);
|
||||||
if (!usage || usage === 0) {
|
|
||||||
|
if (systemDelta <= 0 || cpuDelta < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (stats.cpu_stats.cpu_usage.total_usage / usage) * numberOfCpus * 100;
|
return (cpuDelta / systemDelta) * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calculateMemoryUsage(stats: ContainerStats): number {
|
export function calculateMemoryUsage(stats: ContainerStats): number {
|
||||||
|
|||||||
@@ -72,16 +72,16 @@ describe("calculateCpuUsage", () => {
|
|||||||
const stats = createStats({
|
const stats = createStats({
|
||||||
cpu_stats: { online_cpus: 4, cpu_usage: { total_usage: 2000 }, system_cpu_usage: 10000 },
|
cpu_stats: { online_cpus: 4, cpu_usage: { total_usage: 2000 }, system_cpu_usage: 10000 },
|
||||||
});
|
});
|
||||||
// (2000 / 10000) * 4 * 100 = 80
|
// (2000 / 10000) * 100 = 20
|
||||||
expect(calculateCpuUsage(stats)).toBe(80);
|
expect(calculateCpuUsage(stats)).toBe(20);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should handle fractional CPU usage", () => {
|
test("should handle fractional CPU usage", () => {
|
||||||
const stats = createStats({
|
const stats = createStats({
|
||||||
cpu_stats: { online_cpus: 2, cpu_usage: { total_usage: 500 }, system_cpu_usage: 100000 },
|
cpu_stats: { online_cpus: 2, cpu_usage: { total_usage: 500 }, system_cpu_usage: 100000 },
|
||||||
});
|
});
|
||||||
// (500 / 100000) * 2 * 100 = 1
|
// (500 / 100000) * 100 = 0.5
|
||||||
expect(calculateCpuUsage(stats)).toBe(1);
|
expect(calculateCpuUsage(stats)).toBe(0.5);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -493,7 +493,6 @@ export default function DownloadClientsWidget({
|
|||||||
title: t("items.name.columnTitle"),
|
title: t("items.name.columnTitle"),
|
||||||
sortable: true,
|
sortable: true,
|
||||||
ellipsis: true,
|
ellipsis: true,
|
||||||
width: 240,
|
|
||||||
render: (record) => (
|
render: (record) => (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
key={displayMode}
|
key={displayMode}
|
||||||
|
|||||||
Reference in new issue
Block a user