Skip to content

fix(monitoring): prevent double-counting partition I/O in disk stats (#5385) - #5443

Open
fliptrigga13 wants to merge 1 commit into
Dokploy:canaryfrom
fliptrigga13:fix/issue-5385-disk-stats-double-counting
Open

fliptrigga13 wants to merge 1 commit into
Dokploy:canaryfrom
fliptrigga13:fix/issue-5385-disk-stats-double-counting

Conversation

@fliptrigga13

@fliptrigga13 fliptrigga13 commented Sep 13, 2026

Copy link
Copy Markdown

Summary

Fixes #5385

Problem

In /proc/diskstats, Linux reports I/O metrics for both whole physical block devices (e.g. sda, nvme0n1, vda, mmcblk0) and their constituent partitions (e.g. sda1, sda2, nvme0n1p1, vda1). Because the whole-device counters already aggregate all read and write traffic across all its partitions, iterating over all devices returned by osutils.disk.stats() and summing their readBytes and writeBytes caused every byte of disk activity to be counted twice in Dokploy host monitoring.

Solution

  • Introduced shouldIncludeDiskStat(device: string, allDevices: string[]):
    1. Filters out virtual pseudo-devices (loop*, ram*, sr*, fd*).
    2. Detects partition suffix patterns (p\d+$ for digit-bearing parents like nvme0n1p1 / mmcblk0p1 / md0p1, and \d+$ for letter-bearing parents like sda1 / vda1).
    3. If a partition row's parent disk is present in allDevices, the partition row is skipped to avoid double-counting.
    4. If only the partition is present (common in certain restricted containers or virtualized setups), the partition stats are preserved.
  • Added comprehensive unit test suite in apps/dokploy/__test__/monitoring/disk-stats-double-count.test.ts covering NVMe, SCSI/SATA, MMC, MD, virtual disks, and standalone partition fallback scenarios (5/5 tests passing).

RetriggerConfidence Score: 4/5

The production change appears safe to merge, with a non-blocking test-quality issue that weakens regression protection.

Summary

  • Adds partition-parent detection for common SATA, virtio, NVMe, MMC, and MD naming schemes.
  • Applies the filter while aggregating node-os-utils disk statistics.
  • Adds representative test cases, although they currently exercise a copied helper rather than production code.

Reviews (1) · Last reviewed commit: "fix(monitoring): prevent double-counting..."

Comment on lines +3 to +7
// Recreate the pure function under test to avoid monorepo bundle resolution issues during vitest
const virtualDiskPatterns = [/^loop/, /^ram/, /^sr\d+$/, /^fd\d+$/];
const partitionSuffixPatterns = [/p\d+$/, /\d+$/];

const shouldIncludeDiskStat = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tests Duplicate Production Logic

This test recreates shouldIncludeDiskStat instead of exercising the exported production implementation. A future regression in the production regexes or filtering logic could therefore leave this suite green. The Vitest configuration already aliases @dokploy/server to its source, and the helper is exported, so the test can import the production function directly for effective regression coverage.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disk stats in Monitoring counts each byte twice

1 participant