Skip to content

Commit 84ce3a0

Browse files
W. Andrew Dentondiscordianfish
authored andcommitted
diskstats_linux: always scale reads and writes by 512 bytes, not by device units.
Signed-off-by: W. Andrew Denton <[email protected]>
1 parent e9feae9 commit 84ce3a0

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

collector/diskstats_linux.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import (
2929

3030
const (
3131
secondsPerTick = 1.0 / 1000.0
32+
33+
// Read sectors and write sectors are the "standard UNIX 512-byte sectors, not any device- or filesystem-specific block size.
34+
unixSectorSize = 512.0
3235
)
3336

3437
var (
@@ -195,26 +198,18 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
195198
continue
196199
}
197200

198-
diskSectorSize := 512.0
199-
blockQueue, err := c.fs.SysBlockDeviceQueueStats(dev)
200-
if err != nil {
201-
level.Debug(c.logger).Log("msg", "Error getting queue stats", "device", dev, "err", err)
202-
} else {
203-
diskSectorSize = float64(blockQueue.LogicalBlockSize)
204-
}
205-
206201
ch <- c.infoDesc.mustNewConstMetric(1.0, dev, fmt.Sprint(stats.MajorNumber), fmt.Sprint(stats.MinorNumber))
207202

208203
statCount := stats.IoStatsCount - 3 // Total diskstats record count, less MajorNumber, MinorNumber and DeviceName
209204

210205
for i, val := range []float64{
211206
float64(stats.ReadIOs),
212207
float64(stats.ReadMerges),
213-
float64(stats.ReadSectors) * diskSectorSize,
208+
float64(stats.ReadSectors) * unixSectorSize,
214209
float64(stats.ReadTicks) * secondsPerTick,
215210
float64(stats.WriteIOs),
216211
float64(stats.WriteMerges),
217-
float64(stats.WriteSectors) * diskSectorSize,
212+
float64(stats.WriteSectors) * unixSectorSize,
218213
float64(stats.WriteTicks) * secondsPerTick,
219214
float64(stats.IOsInProgress),
220215
float64(stats.IOsTotalTicks) * secondsPerTick,

0 commit comments

Comments
 (0)