Skip to content

diskstats_linux.go: add collector.diskstats.disable-queue-stats flag #3283

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
35 changes: 24 additions & 11 deletions collector/diskstats_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strconv"
"strings"

"github.com/alecthomas/kingpin/v2"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/blockdevice"
)
Expand Down Expand Up @@ -65,6 +66,10 @@ const (
udevSCSIIdentSerial = "SCSI_IDENT_SERIAL"
)

var (
disableQueueStats = kingpin.Flag("collector.diskstats.disable-queue-stats", "disable queue stats").Default("false").Bool()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually prefer "positive" flags. Then the disable would be --no-collector.diskstats.enable-queue-stats

This makes the explicit version of the disable less awkward looking (--no-collector.diskstats.disable-queue-stats).

Suggested change
disableQueueStats = kingpin.Flag("collector.diskstats.disable-queue-stats", "disable queue stats").Default("false").Bool()
enableQueueStats = kingpin.Flag("collector.diskstats.enable-queue-stats", "enable queue stats").Default("true").Bool()

)

type typedFactorDesc struct {
desc *prometheus.Desc
valueType prometheus.ValueType
Expand Down Expand Up @@ -106,13 +111,16 @@ func NewDiskstatsCollector(logger *slog.Logger) (Collector, error) {
return nil, fmt.Errorf("failed to parse device filter flags: %w", err)
}

infoLabels := []string{"device", "major", "minor", "path", "wwn", "model", "serial", "revision"}
if !*disableQueueStats {
infoLabels = append(infoLabels, "rotational")
}
collector := diskstatsCollector{
deviceFilter: deviceFilter,
fs: fs,
infoDesc: typedFactorDesc{
desc: prometheus.NewDesc(prometheus.BuildFQName(namespace, diskSubsystem, "info"),
"Info of /sys/block/<block_device>.",
[]string{"device", "major", "minor", "path", "wwn", "model", "serial", "revision", "rotational"},
"Info of /sys/block/<block_device>.", infoLabels,
nil,
), valueType: prometheus.GaugeValue,
},
Expand Down Expand Up @@ -294,22 +302,27 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
serial = info[udevIDSerialShort]
}

queueStats, err := c.fs.SysBlockDeviceQueueStats(dev)
// Block Device Queue stats may not exist for all devices.
if err != nil && !os.IsNotExist(err) {
c.logger.Debug("Failed to get block device queue stats", "device", dev, "err", err)
}

ch <- c.infoDesc.mustNewConstMetric(1.0, dev,
labels := []string{
dev,
fmt.Sprint(stats.MajorNumber),
fmt.Sprint(stats.MinorNumber),
info[udevIDPath],
info[udevIDWWN],
info[udevIDModel],
serial,
info[udevIDRevision],
strconv.FormatUint(queueStats.Rotational, 2),
)
}

if !*disableQueueStats {
queueStats, err := c.fs.SysBlockDeviceQueueStats(dev)
// Block Device Queue stats may not exist for all devices.
if err != nil && !os.IsNotExist(err) {
c.logger.Debug("Failed to get block device queue stats", "device", dev, "err", err)
}
labels = append(labels, strconv.FormatUint(queueStats.Rotational, 2))
}

ch <- c.infoDesc.mustNewConstMetric(1.0, labels...)

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

Expand Down
Loading