Skip to content

Commit 6ffe910

Browse files
committed
fix: skip partitioned md arrays and test the Block I/O sum
1 parent a18d12e commit 6ffe910

2 files changed

Lines changed: 44 additions & 4 deletions

File tree

‎apps/dokploy/__test__/monitoring/is-physical-disk.test.ts‎

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
1-
import { isPhysicalDisk } from "@dokploy/server/monitoring/utils";
2-
import { describe, expect, it } from "vitest";
1+
import {
2+
getHostSystemStats,
3+
isPhysicalDisk,
4+
} from "@dokploy/server/monitoring/utils";
5+
import { describe, expect, it, vi } from "vitest";
6+
7+
const GiB = 1024 ** 3;
8+
const diskStat = (device: string, readGiB: number, writeGiB: number) => ({
9+
device,
10+
readBytes: { toBytes: () => readGiB * GiB },
11+
writeBytes: { toBytes: () => writeGiB * GiB },
12+
});
13+
14+
vi.mock("node-os-utils", () => ({
15+
OSUtils: class {
16+
cpu = { usage: async () => ({ success: false }) };
17+
memory = { info: async () => ({ success: false }) };
18+
network = { overview: async () => ({ success: false }) };
19+
disk = {
20+
stats: async () => ({
21+
success: true,
22+
data: [
23+
diskStat("nvme0n1", 50, 100),
24+
diskStat("nvme0n1p1", 50, 100),
25+
diskStat("nvme1n1", 50, 100),
26+
diskStat("nvme1n1p1", 50, 100),
27+
diskStat("md0", 50, 100),
28+
diskStat("md0p1", 50, 100),
29+
diskStat("dm-0", 50, 100),
30+
diskStat("zram0", 10, 20),
31+
],
32+
}),
33+
};
34+
},
35+
}));
336

437
describe("isPhysicalDisk (#5513, #5385)", () => {
538
it.each([
@@ -28,7 +61,7 @@ describe("isPhysicalDisk (#5513, #5385)", () => {
2861
expect(isPhysicalDisk(device)).toBe(false);
2962
});
3063

31-
it.each(["md0", "md127", "dm-0", "dm-12"])(
64+
it.each(["md0", "md127", "md0p1", "md_d0p1", "dm-0", "dm-12"])(
3265
"skips stacked device %s",
3366
(device) => {
3467
expect(isPhysicalDisk(device)).toBe(false);
@@ -62,3 +95,10 @@ describe("isPhysicalDisk (#5513, #5385)", () => {
6295
expect(devices.filter(isPhysicalDisk)).toEqual(["nvme0n1", "nvme1n1"]);
6396
});
6497
});
98+
99+
describe("getHostSystemStats Block I/O (#5513, #5385)", () => {
100+
it("sums only whole physical disks", async () => {
101+
const stats = await getHostSystemStats();
102+
expect(stats.BlockIO).toBe("100.00GiB / 200.00GiB");
103+
});
104+
});

‎packages/server/src/monitoring/utils.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const NON_PHYSICAL_DEVICE_PATTERNS = [
6666
// Partitions and md/dm devices repeat I/O already counted on the underlying disk.
6767
/^(sd|hd|vd|xvd)[a-z]+\d+$/,
6868
/^(nvme\d+n\d+|mmcblk\d+)p\d+$/,
69-
/^(md\d+|dm-\d+)$/,
69+
/^(md|dm-)/,
7070
];
7171

7272
export const isPhysicalDisk = (device: string) =>

0 commit comments

Comments
 (0)