From e3522077748ef2bd32bc1db09b500b3694e09561 Mon Sep 17 00:00:00 2001 From: "W. Andrew Denton" Date: Mon, 7 Mar 2022 14:24:08 -0800 Subject: [PATCH 1/2] diskstats_linux: always scale reads and writes by 512 bytes, not by device units. Signed-off-by: W. Andrew Denton --- collector/diskstats_linux.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/collector/diskstats_linux.go b/collector/diskstats_linux.go index b79d6bd398..0981ff3a39 100644 --- a/collector/diskstats_linux.go +++ b/collector/diskstats_linux.go @@ -29,6 +29,9 @@ import ( const ( secondsPerTick = 1.0 / 1000.0 + + // Read sectors and write sectors are the "standard UNIX 512-byte sectors, not any device- or filesystem-specific block size. + unixSectorSize = 512.0 ) var ( @@ -195,14 +198,6 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error { continue } - diskSectorSize := 512.0 - blockQueue, err := c.fs.SysBlockDeviceQueueStats(dev) - if err != nil { - level.Debug(c.logger).Log("msg", "Error getting queue stats", "device", dev, "err", err) - } else { - diskSectorSize = float64(blockQueue.LogicalBlockSize) - } - ch <- c.infoDesc.mustNewConstMetric(1.0, dev, fmt.Sprint(stats.MajorNumber), fmt.Sprint(stats.MinorNumber)) statCount := stats.IoStatsCount - 3 // Total diskstats record count, less MajorNumber, MinorNumber and DeviceName @@ -210,11 +205,11 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error { for i, val := range []float64{ float64(stats.ReadIOs), float64(stats.ReadMerges), - float64(stats.ReadSectors) * diskSectorSize, + float64(stats.ReadSectors) * unixSectorSize, float64(stats.ReadTicks) * secondsPerTick, float64(stats.WriteIOs), float64(stats.WriteMerges), - float64(stats.WriteSectors) * diskSectorSize, + float64(stats.WriteSectors) * unixSectorSize, float64(stats.WriteTicks) * secondsPerTick, float64(stats.IOsInProgress), float64(stats.IOsTotalTicks) * secondsPerTick, From 47cc274c8196bb8bbe5b3a950c142daf615c1c2c Mon Sep 17 00:00:00 2001 From: "W. Andrew Denton" Date: Thu, 10 Mar 2022 16:43:07 -0800 Subject: [PATCH 2/2] Add a reference to the Linux kernel's documentation for block stat. Signed-off-by: W. Andrew Denton --- collector/diskstats_linux.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/collector/diskstats_linux.go b/collector/diskstats_linux.go index 0981ff3a39..f0de40776b 100644 --- a/collector/diskstats_linux.go +++ b/collector/diskstats_linux.go @@ -30,7 +30,8 @@ import ( const ( secondsPerTick = 1.0 / 1000.0 - // Read sectors and write sectors are the "standard UNIX 512-byte sectors, not any device- or filesystem-specific block size. + // Read sectors and write sectors are the "standard UNIX 512-byte sectors, not any device- or filesystem-specific block size." + // See also https://www.kernel.org/doc/Documentation/block/stat.txt unixSectorSize = 512.0 )