Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diskstats_linux: always scale reads and writes by 512 bytes, not by device units #2311

Merged
merged 2 commits into from
Mar 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions collector/diskstats_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ 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."
// See also https://www.kernel.org/doc/Documentation/block/stat.txt
unixSectorSize = 512.0
)

var (
Expand Down Expand Up @@ -195,26 +199,18 @@ 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

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,
Expand Down