From 936368d217fb300a0ab81d607175041b3504b331 Mon Sep 17 00:00:00 2001 From: Marcus Cobden <52370+leth@users.noreply.github.com> Date: Tue, 8 Nov 2022 15:09:39 +0000 Subject: [PATCH] Fix btrfs device stats always being zero (#2516) * Respect rootfs path config option in btrfs ioctl * Fix btrfs device stats always being zero Signed-off-by: Marcus Cobden --- collector/btrfs_linux.go | 10 ++++++---- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/collector/btrfs_linux.go b/collector/btrfs_linux.go index 94b27df8..b5642b33 100644 --- a/collector/btrfs_linux.go +++ b/collector/btrfs_linux.go @@ -123,13 +123,15 @@ func (c *btrfsCollector) getIoctlStats() (map[string]*btrfsIoctlFsStats, error) continue } - fs, err := dennwc.Open(mount.mountPoint, true) + mountPath := rootfsFilePath(mount.mountPoint) + + fs, err := dennwc.Open(mountPath, true) if err != nil { // Failed to open this mount point, maybe we didn't have permission // maybe we'll find another mount point for this FS later. level.Debug(c.logger).Log( "msg", "Error inspecting btrfs mountpoint", - "mountPoint", mount.mountPoint, + "mountPoint", mountPath, "err", err) continue } @@ -140,7 +142,7 @@ func (c *btrfsCollector) getIoctlStats() (map[string]*btrfsIoctlFsStats, error) // perhaps it'll work with a different mount point level.Debug(c.logger).Log( "msg", "Error querying btrfs filesystem", - "mountPoint", mount.mountPoint, + "mountPoint", mountPath, "err", err) continue } @@ -155,7 +157,7 @@ func (c *btrfsCollector) getIoctlStats() (map[string]*btrfsIoctlFsStats, error) if err != nil { level.Debug(c.logger).Log( "msg", "Error querying btrfs device stats", - "mountPoint", mount.mountPoint, + "mountPoint", mountPath, "err", err) continue } diff --git a/go.mod b/go.mod index 9fc2c607..a46e4e14 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.17 require ( github.com/beevik/ntp v0.3.0 github.com/coreos/go-systemd/v22 v22.4.0 - github.com/dennwc/btrfs v0.0.0-20220403080356-b3db0b2dedac + github.com/dennwc/btrfs v0.0.0-20221026161108-3097362dc072 github.com/ema/qdisc v0.0.0-20200603082823-62d0308e3e00 github.com/go-kit/log v0.2.1 github.com/godbus/dbus/v5 v5.1.0 diff --git a/go.sum b/go.sum index 0967aa7b..84c8b3f3 100644 --- a/go.sum +++ b/go.sum @@ -99,8 +99,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dennwc/btrfs v0.0.0-20220403080356-b3db0b2dedac h1:cjfIEKdg/lZ+ewJk8FYoYZTN2HY/okVSPtmHLaYMAvE= -github.com/dennwc/btrfs v0.0.0-20220403080356-b3db0b2dedac/go.mod h1:MYsOV9Dgsec3FFSOjywi0QK5r6TeBbdWxdrMGtiYXHA= +github.com/dennwc/btrfs v0.0.0-20221026161108-3097362dc072 h1:7jWBDCngQSBfRmrRCpYH3iPPVOe5i8xbl+5rQHkwZDE= +github.com/dennwc/btrfs v0.0.0-20221026161108-3097362dc072/go.mod h1:MYsOV9Dgsec3FFSOjywi0QK5r6TeBbdWxdrMGtiYXHA= github.com/dennwc/ioctl v1.0.0 h1:DsWAAjIxRqNcLn9x6mwfuf2pet3iB7aK90K4tF16rLg= github.com/dennwc/ioctl v1.0.0/go.mod h1:ellh2YB5ldny99SBU/VX7Nq0xiZbHphf1DrtHxxjMk0= github.com/ema/qdisc v0.0.0-20200603082823-62d0308e3e00 h1:0GHzegkDz/zSrt+Zph1OueNImPdUxoToypnkhhRYTjI=