fix(agent): measure first disk I/O sample of an interval from the full baseline (#2420)

This commit is contained in:
Ludwig J. Marx
2026-09-25 19:38:04 +02:00
committed by GitHub
parent 3dfe062ee4
commit 433b83800f
3 changed files with 65 additions and 13 deletions

View File

@@ -599,6 +599,7 @@ func (a *Agent) initializeDiskIoStats(diskIoCounters map[string]disk.IOCountersS
stats.Time = now
stats.TotalRead = d.ReadBytes
stats.TotalWrite = d.WriteBytes
a.setDiskBaseline(device, prevDiskFromCounter(d, now))
// add to list of valid io device names
a.fsNames = append(a.fsNames, device)
}
@@ -681,19 +682,9 @@ func (a *Agent) updateDiskIo(cacheTimeMs uint16, systemStats *system.Stats) {
// Previous snapshot for this interval and device
prev, hasPrev := a.diskPrev[cacheTimeMs][name]
if !hasPrev {
// Seed from agent-level fsStats if present, else seed from current
prev = prevDisk{
readBytes: stats.TotalRead,
writeBytes: stats.TotalWrite,
readTime: d.ReadTime,
writeTime: d.WriteTime,
ioTime: d.IoTime,
weightedIO: d.WeightedIO,
readCount: d.ReadCount,
writeCount: d.WriteCount,
at: stats.Time,
}
if prev.at.IsZero() {
// Seed from the latest counters of any interval, else seed from current
prev, hasPrev = a.diskBaseline[name]
if !hasPrev {
prev = prevDiskFromCounter(d, now)
}
}
@@ -752,6 +743,7 @@ func (a *Agent) updateDiskIo(cacheTimeMs uint16, systemStats *system.Stats) {
}
// Update global fsStats baseline for cross-interval correctness
a.setDiskBaseline(name, prevDiskFromCounter(d, now))
stats.Time = now
stats.TotalRead = d.ReadBytes
stats.TotalWrite = d.WriteBytes
@@ -784,6 +776,15 @@ func (a *Agent) updateDiskIo(cacheTimeMs uint16, systemStats *system.Stats) {
}
}
// setDiskBaseline stores the latest counters of a device. A cache interval
// without its own snapshot measures its first sample from them.
func (a *Agent) setDiskBaseline(name string, d prevDisk) {
if a.diskBaseline == nil {
a.diskBaseline = make(map[string]prevDisk)
}
a.diskBaseline[name] = d
}
// ioTimeDelta returns the increase of a cumulative millisecond counter from
// the disk I/O stats. Linux prints these fields of /proc/diskstats as 32-bit
// unsigned ints, so they wrap to zero at 2^32. A busy disk reaches that in