|
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 | +})); |
3 | 36 |
|
4 | 37 | describe("isPhysicalDisk (#5513, #5385)", () => { |
5 | 38 | it.each([ |
@@ -28,7 +61,7 @@ describe("isPhysicalDisk (#5513, #5385)", () => { |
28 | 61 | expect(isPhysicalDisk(device)).toBe(false); |
29 | 62 | }); |
30 | 63 |
|
31 | | - it.each(["md0", "md127", "dm-0", "dm-12"])( |
| 64 | + it.each(["md0", "md127", "md0p1", "md_d0p1", "dm-0", "dm-12"])( |
32 | 65 | "skips stacked device %s", |
33 | 66 | (device) => { |
34 | 67 | expect(isPhysicalDisk(device)).toBe(false); |
@@ -62,3 +95,10 @@ describe("isPhysicalDisk (#5513, #5385)", () => { |
62 | 95 | expect(devices.filter(isPhysicalDisk)).toEqual(["nvme0n1", "nvme1n1"]); |
63 | 96 | }); |
64 | 97 | }); |
| 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 | +}); |
0 commit comments