From 23ca27057b3f93c027e25130f797a78547e29e17 Mon Sep 17 00:00:00 2001 From: void143 Date: Thu, 11 Jun 2026 23:52:04 +0300 Subject: [PATCH] Fix I/O stats showing 0/0 on cgroup v2 hosts The Docker stats API reports the blkio operation as "Read"/"Write" under cgroup v1 but lowercase "read"/"write" under cgroup v2. ReadIO compared the op with a case-sensitive equality, so on cgroup v2 hosts neither branch matched and every container reported 0/0 for IO read/write. Compare the op case-insensitively with strings.EqualFold so the values are populated correctly on both cgroup v1 and v2. --- connector/collector/docker.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/connector/collector/docker.go b/connector/collector/docker.go index 46cd499c..d5a289af 100644 --- a/connector/collector/docker.go +++ b/connector/collector/docker.go @@ -1,6 +1,8 @@ package collector import ( + "strings" + "github.com/bcicen/ctop/models" api "github.com/fsouza/go-dockerclient" ) @@ -111,10 +113,13 @@ func (c *Docker) ReadNet(stats *api.Stats) { func (c *Docker) ReadIO(stats *api.Stats) { var read, write int64 for _, blk := range stats.BlkioStats.IOServiceBytesRecursive { - if blk.Op == "Read" { + // cgroup v1 reports the operation as "Read"/"Write", while cgroup v2 + // reports it lowercase as "read"/"write". Match case-insensitively so + // I/O stats are populated on both (otherwise cgroup v2 hosts show 0/0). + if strings.EqualFold(blk.Op, "Read") { read += int64(blk.Value) } - if blk.Op == "Write" { + if strings.EqualFold(blk.Op, "Write") { write += int64(blk.Value) } }