Skip to content

Comments

Collect diskstats from /sys#2042

Closed
luizluca wants to merge 1 commit intoprometheus:masterfrom
luizluca:disk_sys
Closed

Collect diskstats from /sys#2042
luizluca wants to merge 1 commit intoprometheus:masterfrom
luizluca:disk_sys

Conversation

@luizluca
Copy link
Contributor

@luizluca luizluca commented May 19, 2021

It might be slower than /proc/diskstats but it will allow to securely collect devices, not partitions. /proc/diskstats was already not atomic as, according to docs, it does not use locks and values might change on the fly.

The PR is divided in two commits. One does not change the behavior, except from reading /sys/block/*/stat instead of /proc/diskstats. It could be incorporated in a minor release without major issues.

The second one might break the user experience when collector.diskstats.ignored-devices was changed to include partitions. It could be postponed until a breakage is allowed.

diskstats_linux_test.go was removed but I can add a new one if necessary. I think that the end2end test might be enough.

fixtures/sys was expanded with the corresponding devices previously present in proc/diskstats.

Related #2041

@luizluca luizluca mentioned this pull request May 20, 2021
@discordianfish
Copy link
Member

Ideally the functionality of reading and parsing should be moved to https://github.com/prometheus/procfs
Either way, we certainly want to keep testing this.

@luizluca
Copy link
Contributor Author

luizluca commented Jun 1, 2021

Ideally the functionality of reading and parsing should be moved to https://github.com/prometheus/procfs
Either way, we certainly want to keep testing this.

I can provide a /sys disk parser in procfs. I just need tapestats (prometheus/procfs#382 and #2044) to be merged first as I need to know if I did something wrong before starting a new parser based on it.

diskstats now use procfs/blockdevice instead of manually reading
procfs. It prefers to use /sys but it will fallback to /proc
if /sys fails. Although reading /sys/block/<dev>/stat is slower,
/proc/diskstats have never garanteed atomicity between lines.
A new option collector.diskstats.prefer-sysfs (true by default)
can be used to skip /sys.

Using /sys, diskstats will ignore partitions. If they are needed,
/proc must be used or procfs/blockdevice must be extended. This
solves issues with ambiguous names like xvda1 that that can both
represent a partition in xvda or a standalone disk (Fixes prometheus#2041).
If collector.diskstats.ignored-devices was changed to include
partitions, collector.diskstats.prefer-sysfs must be set to false.
if collector.diskstats.ignored-devices was untouched, both /proc
and /sys should return the same results.

With /sys as default, collector.diskstats.ignored-devices could
be simplified to match only device names, not partitions. For now,
partition filtering was kept and extended to match mmcblk0p[12].

The diskstats_linux_test.go was not implemented for /sys/block.

Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
@luizluca
Copy link
Contributor Author

luizluca commented Jul 6, 2021

I reimplemented using procfs and opened a new PR #2072

@SuperQ
Copy link
Member

SuperQ commented Jul 6, 2021

Awesome! Thank you.

@luizluca
Copy link
Contributor Author

luizluca commented Jul 6, 2021

I reopened as #2043 as I cannot reopen after a forced-pushed

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.

3 participants