prometheus / node_exporter

Exporter for machine metrics
https://prometheus.io/
Apache License 2.0
10.88k stars 2.33k forks source link

feat: support to get rotational of the disk. #2956

Open zhucan opened 5 months ago

zhucan commented 5 months ago

        content, err := os.ReadFile(fmt.Sprintf("/sys/block/%s/queue/rotational", dev))
        if err != nil {
            level.Debug(c.logger).Log("msg", "Failed to get sys block device queue stats", "err", err)
        }
        rotational := strings.Replace(string(content), "\n", "", -1)
        i, err := strconv.Atoi(rotational)
tjhop commented 5 months ago

For what it's worth, there is already code in place to get rotational info as reported by udev: https://github.com/prometheus/node_exporter/blob/94ef5cc666ce6c797e1e7fbe9082cb1dc42af1f4/collector/diskstats_linux.go#L252-L258

However, I don't have that metric available on any of the systems I personally own, and I do have rotational info in sysfs for my disks. I would also be in favor of a sysfs based method for collecting rotational info, but it might be better suited to live in github.com/prometheus/procfs, in my opinion

tjhop commented 5 months ago

Turns out it already does exist in procfs and I forgot about it!

https://pkg.go.dev/github.com/prometheus/procfs@v0.13.0/blockdevice#BlockQueueStats

Seems we would just need to utilize it

SuperQ commented 3 months ago

Yes, this seems like it would be easy to add to the diskstats collector.