Skip to content

collector/diskstats: add block device rotational#3022

Merged
SuperQ merged 2 commits into
prometheus:masterfrom
rexagod:2956
Feb 4, 2025
Merged

collector/diskstats: add block device rotational#3022
SuperQ merged 2 commits into
prometheus:masterfrom
rexagod:2956

Conversation

@rexagod

@rexagod rexagod commented May 23, 2024

Copy link
Copy Markdown
Contributor

Add metric to indicate if a device is rotational or not.

Fixes: #2956

Comment thread collector/diskstats_linux.go Outdated
@rexagod rexagod force-pushed the 2956 branch 2 times, most recently from 2a22d79 to bac46b7 Compare August 13, 2024 14:21
@rexagod

rexagod commented Aug 13, 2024

Copy link
Copy Markdown
Contributor Author

Tests keep passing locally for me, I'll need to dig a bit more into this.

@discordianfish

Copy link
Copy Markdown
Member

@rexagod Any updates on the test failures?

@rexagod

rexagod commented Sep 22, 2024

Copy link
Copy Markdown
Contributor Author

Rebased on #3131, tests passing.

@rexagod rexagod force-pushed the 2956 branch 3 times, most recently from d10e657 to d25ba39 Compare September 22, 2024 22:19
Sync dependencies and log using the machinery introduced in prometheus#3097.

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
@rexagod rexagod force-pushed the 2956 branch 2 times, most recently from 3698deb to 2d50932 Compare October 20, 2024 17:31
Add metric to indicate if a device is rotational or not.

Fixes: prometheus#2956
Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
@rexagod

rexagod commented Nov 27, 2024

Copy link
Copy Markdown
Contributor Author

(bump)

@discordianfish discordianfish left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@discordianfish

Copy link
Copy Markdown
Member

@SuperQ PTAL

@rexagod

rexagod commented Feb 4, 2025

Copy link
Copy Markdown
Contributor Author

Ping.

@SuperQ SuperQ merged commit 9889bcd into prometheus:master Feb 4, 2025
SuperQ added a commit that referenced this pull request Feb 16, 2025
* [CHANGE] meminfo: Convert linux implementation to use procfs lib #3049
* [CHANGE] Update logging to use Go log/slog #3097
* [FEATURE] filesystem: Add `node_filesystem_mount_info` metric #2970
* [FEATURE] btrfs: Add metrics for commit statistics #3010
* [FEATURE] interrupts: Add collector include/exclude filtering #3028
* [FEATURE] interrupts: Add "exclude zeros" filtering #3028
* [FEATURE] slabinfo: Add filters for slab name. #3041
* [FEATURE] pressure: add IRQ PSI metrics #3048
* [FEATURE] hwmon: Add include and exclude filter for sensors #3072
* [FEATURE] filesystem: Add NetBSD support #3082
* [FEATURE] netdev: Add ifAlias label #3087
* [FEATURE] hwmon: Add Support for GPU Clock Frequencies #3093
* [FEATURE] Add `exclude[]` URL parameter #3116
* [FEATURE] Add AIX support #3136
* [FEATURE] filesystem: Add fs-types/mount-points include flags #3171
* [FEATURE] netstat: Add collector for tcp packet counters for FreeBSD. #3177
* [ENHANCEMENT] ethtool: Add logging for filtering flags #2979
* [ENHANCEMENT] netstat: Add TCPRcvQDrop to default metrics #3021
* [ENHANCEMENT] diskstats: Add block device rotational #3022
* [ENHANCEMENT] cpu: Support CPU online status #3032
* [ENHANCEMENT] arp: optimize interface name resolution #3133
* [ENHANCEMENT] textfile: Allow specifiying multiple directory globs #3135
* [ENHANCEMENT] filesystem: Add reporting of purgeable space on MacOS #3206
* [ENHANCEMENT] ethtool: Skip full scan of NetClass directories #3239
* [BUGFIX] zfs: Prevent `procfs` integer underflow #2961
* [BUGFIX] pressure: Fix collection on systems that do not expose a full CPU stat #3054
* [BUGFIX] cpu: Fix FreeBSD 32-bit host support and plug memory leak #3083
* [BUGFIX] hwmon: Add safety check to hwmon read #3134
* [BUGFIX] zfs: Allow space in dataset name #3186

Signed-off-by: Ben Kochie <superq@gmail.com>
@SuperQ SuperQ mentioned this pull request Feb 16, 2025
SuperQ added a commit that referenced this pull request Feb 17, 2025
* [CHANGE] meminfo: Convert linux implementation to use procfs lib #3049
* [CHANGE] Update logging to use Go log/slog #3097
* [FEATURE] filesystem: Add `node_filesystem_mount_info` metric #2970
* [FEATURE] btrfs: Add metrics for commit statistics #3010
* [FEATURE] interrupts: Add collector include/exclude filtering #3028
* [FEATURE] interrupts: Add "exclude zeros" filtering #3028
* [FEATURE] slabinfo: Add filters for slab name. #3041
* [FEATURE] pressure: add IRQ PSI metrics #3048
* [FEATURE] hwmon: Add include and exclude filter for sensors #3072
* [FEATURE] filesystem: Add NetBSD support #3082
* [FEATURE] netdev: Add ifAlias label #3087
* [FEATURE] hwmon: Add Support for GPU Clock Frequencies #3093
* [FEATURE] Add `exclude[]` URL parameter #3116
* [FEATURE] Add AIX support #3136
* [FEATURE] filesystem: Add fs-types/mount-points include flags #3171
* [FEATURE] netstat: Add collector for tcp packet counters for FreeBSD. #3177
* [ENHANCEMENT] ethtool: Add logging for filtering flags #2979
* [ENHANCEMENT] netstat: Add TCPRcvQDrop to default metrics #3021
* [ENHANCEMENT] diskstats: Add block device rotational #3022
* [ENHANCEMENT] cpu: Support CPU online status #3032
* [ENHANCEMENT] arp: optimize interface name resolution #3133
* [ENHANCEMENT] textfile: Allow specifiying multiple directory globs #3135
* [ENHANCEMENT] filesystem: Add reporting of purgeable space on MacOS #3206
* [ENHANCEMENT] ethtool: Skip full scan of NetClass directories #3239
* [BUGFIX] zfs: Prevent `procfs` integer underflow #2961
* [BUGFIX] pressure: Fix collection on systems that do not expose a full CPU stat #3054
* [BUGFIX] cpu: Fix FreeBSD 32-bit host support and plug memory leak #3083
* [BUGFIX] hwmon: Add safety check to hwmon read #3134
* [BUGFIX] zfs: Allow space in dataset name #3186

Signed-off-by: Ben Kochie <superq@gmail.com>
ruthwikkakumani added a commit to ruthwikkakumani/node_exporter that referenced this pull request Jun 17, 2026
…ometheus#3282)

Fix a 10× scrape-latency regression introduced in prometheus#3022 on systems with
many block devices.

Previously, Update() called SysBlockDeviceQueueStats(dev) for every
block device per scrape, reading ~30 sysfs files per device. On systems
with 1,000+ devices this resulted in 30,000+ unnecessary file reads per
scrape, causing timeouts.

Replace the expensive struct call with a targeted rotationalLabel()
helper that reads exactly one file per device:
  /sys/block/<device>/queue/rotational

The helper uses the existing sysFilePath() utility so it honours the
--path.sysfs flag. It returns "1" for rotational (HDD) and "0" for
non-rotational (SSD/NVMe), failing closed to "0" on any error —
matching the zero-initialised-struct behaviour of the old code.

Also add:
- TestRotationalLabel: dynamic t.TempDir()-based tests covering the
  rotational, missing-file, and malformed-content cases.
- BenchmarkDiskstatsUpdate: measures the full Update() call to catch
  future per-device sysfs I/O regressions before merge.

Fixes prometheus#3282

Signed-off-by: Ruthwik Kakumani <ruthwikkakumani08@gmail.com>
ruthwikkakumani added a commit to ruthwikkakumani/node_exporter that referenced this pull request Jun 17, 2026
…ometheus#3282)

Fix a 10× scrape-latency regression introduced in prometheus#3022 on systems with
many block devices.

Previously, Update() called SysBlockDeviceQueueStats(dev) for every
block device per scrape, reading ~30 sysfs files per device. On systems
with 1,000+ devices this resulted in 30,000+ unnecessary file reads per
scrape, causing timeouts.

Replace the expensive struct call with a targeted rotationalLabel()
helper that delegates to blockdevice.FS.SysBlockDeviceRotational(dev)
(added in prometheus/procfs#824). This reads exactly 1 sysfs file per
device:
  /sys/block/<device>/queue/rotational

Returns "1" for rotational (HDD) and "0" for non-rotational (SSD/NVMe),
failing closed to "0" on any error — matching the zero-initialised-struct
behaviour of the old code.

Also add:
- TestRotationalLabel: dynamic t.TempDir()-based tests via blockdevice.FS,
  covering HDD, SSD, and missing-file cases.
- BenchmarkDiskstatsUpdate: measures the full Update() call to catch
  future per-device sysfs I/O regressions before merge.

Fixes prometheus#3282

Signed-off-by: Ruthwik Kakumani <ruthwikkakumani08@gmail.com>
ruthwikkakumani added a commit to ruthwikkakumani/node_exporter that referenced this pull request Jun 17, 2026
…ometheus#3282)

Fix a 10× scrape-latency regression introduced in prometheus#3022 on systems with
many block devices.

Previously, Update() called SysBlockDeviceQueueStats(dev) for every
block device per scrape, reading ~30 sysfs files per device. On systems
with 1,000+ devices this resulted in 30,000+ unnecessary file reads per
scrape, causing timeouts.

Replace the expensive struct call with a targeted rotationalLabel()
helper that delegates to blockdevice.FS.SysBlockDeviceRotational(dev)
(added in prometheus/procfs#824). This reads exactly 1 sysfs file per
device:
  /sys/block/<device>/queue/rotational

Returns "1" for rotational (HDD) and "0" for non-rotational (SSD/NVMe),
failing closed to "0" on any error — matching the zero-initialised-struct
behaviour of the old code.

Also add:
- TestRotationalLabel: dynamic t.TempDir()-based tests via blockdevice.FS,
  covering HDD, SSD, and missing-file cases.
- BenchmarkDiskstatsUpdate: measures the full Update() call to catch
  future per-device sysfs I/O regressions before merge.

Fixes prometheus#3282

Signed-off-by: Ruthwik Kakumani <ruthwikkakumani08@gmail.com>
ruthwikkakumani added a commit to ruthwikkakumani/node_exporter that referenced this pull request Jun 18, 2026
…ometheus#3282)

Fix a 10× scrape-latency regression introduced in prometheus#3022 on systems with
many block devices.

Previously, Update() called SysBlockDeviceQueueStats(dev) for every
block device per scrape, reading ~30 sysfs files per device. On systems
with 1,000+ devices this resulted in 30,000+ unnecessary file reads per
scrape, causing timeouts.

Replace the expensive struct call with a targeted rotationalLabel()
helper that delegates to blockdevice.FS.SysBlockDeviceRotational(dev)
(added in prometheus/procfs#824). This reads exactly 1 sysfs file per
device:
  /sys/block/<device>/queue/rotational

Returns "1" for rotational (HDD) and "0" for non-rotational (SSD/NVMe),
failing closed to "0" on any error — matching the zero-initialised-struct
behaviour of the old code.

Also add:
- TestRotationalLabel: dynamic t.TempDir()-based tests via blockdevice.FS,
  covering HDD, SSD, and missing-file cases.
- BenchmarkDiskstatsUpdate: measures the full Update() call to catch
  future per-device sysfs I/O regressions before merge.

Fixes prometheus#3282

Signed-off-by: Ruthwik Kakumani <ruthwikkakumani08@gmail.com>
ruthwikkakumani added a commit to ruthwikkakumani/node_exporter that referenced this pull request Jun 18, 2026
…ometheus#3282)

Fix a 10× scrape-latency regression introduced in prometheus#3022 on systems with
many block devices.

Previously, Update() called SysBlockDeviceQueueStats(dev) for every
block device per scrape, reading ~30 sysfs files per device. On systems
with 1,000+ devices this resulted in 30,000+ unnecessary file reads per
scrape, causing timeouts.

Replace the expensive struct call with a targeted rotationalLabel()
helper that delegates to blockdevice.FS.SysBlockDeviceRotational(dev)
(added in prometheus/procfs#824). This reads exactly 1 sysfs file per
device:
  /sys/block/<device>/queue/rotational

Returns "1" for rotational (HDD) and "0" for non-rotational (SSD/NVMe),
failing closed to "0" on any error — matching the zero-initialised-struct
behaviour of the old code.

Also add:
- TestRotationalLabel: dynamic t.TempDir()-based tests via blockdevice.FS,
  covering HDD, SSD, and missing-file cases.
- BenchmarkDiskstatsUpdate: measures the full Update() call to catch
  future per-device sysfs I/O regressions before merge.

Fixes prometheus#3282

Signed-off-by: Ruthwik Kakumani <ruthwikkakumani08@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: support to get rotational of the disk.

3 participants