implement docker host details page

This commit is contained in:
Alex Holliday committed 2026-08-31 12:02:40 -07:00
1 parent a7ee90e1ee
commit ca896fa22f
14 files changed
+366 -17

No files matched your search

+2 -2
View File
@@ -100,7 +100,7 @@ export class DockerProvider implements IStatusProvider<DockerStatusPayload> {
const systemDelta = stats.cpu_stats.system_cpu_usage - (stats.precpu_stats.system_cpu_usage ?? 0);
const onlineCpus = stats.cpu_stats.online_cpus ?? stats.cpu_stats.cpu_usage.percpu_usage?.length ?? 1;
if (!(systemDelta > 0) || cpuDelta < 0) return 0;
return (cpuDelta / systemDelta) * onlineCpus * 100;
return (cpuDelta / systemDelta) * onlineCpus;
}
private computeMemory(stats: Dockerode.ContainerStats): Pick<DockerContainerInfo, "memoryUsedBytes" | "memoryLimitBytes" | "memoryPct"> {
@@ -111,7 +111,7 @@ export class DockerProvider implements IStatusProvider<DockerStatusPayload> {
return {
memoryUsedBytes,
memoryLimitBytes,
memoryPct: memoryLimitBytes > 0 ? (memoryUsedBytes / memoryLimitBytes) * 100 : 0,
memoryPct: memoryLimitBytes > 0 ? memoryUsedBytes / memoryLimitBytes : 0,
};
}
+2 -2
View File
@@ -117,10 +117,10 @@ export interface DockerContainerInfo {
state: DockerContainerState;
status: string;
health: DockerHealthStatus;
cpuPct?: number;
cpuPct?: number; // fraction of one core (docker stats convention / 100); exceeds 1 when using multiple cores
memoryUsedBytes?: number;
memoryLimitBytes?: number;
memoryPct?: number;
memoryPct?: number; // 0-1 fraction of the memory limit
restartCount?: number;
startedAt?: string; // ISO date
}
@@ -324,10 +324,10 @@ describe("DockerProvider", () => {
const result = await provider.handle(makeMonitor());
const container = result.payload?.containers[0];
expect(container?.cpuPct).toBeCloseTo(80);
expect(container?.cpuPct).toBeCloseTo(0.8);
expect(container?.memoryUsedBytes).toBe(200 * 1024 * 1024);
expect(container?.memoryLimitBytes).toBe(1024 * 1024 * 1024);
expect(container?.memoryPct).toBeCloseTo(19.53125);
expect(container?.memoryPct).toBeCloseTo(0.1953125);
});
it("falls back to the cgroup v1 cache field for page cache", async () => {
@@ -351,7 +351,7 @@ describe("DockerProvider", () => {
const result = await provider.handle(makeMonitor());
expect(result.payload?.containers[0]?.cpuPct).toBeCloseTo(40);
expect(result.payload?.containers[0]?.cpuPct).toBeCloseTo(0.4);
});
it("returns 0 cpu when the system delta is not positive", async () => {