From 03450a4d7ddb96145a72cffc6029b99751bedc7a Mon Sep 17 00:00:00 2001 From: David O'Rourke Date: Tue, 2 Jun 2020 12:07:09 +0100 Subject: [PATCH] filesystem_freebsd: Use bytesToString to get label values Signed-off-by: David O'Rourke --- collector/filesystem_freebsd.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/collector/filesystem_freebsd.go b/collector/filesystem_freebsd.go index 8bc83140..1d377b1f 100644 --- a/collector/filesystem_freebsd.go +++ b/collector/filesystem_freebsd.go @@ -16,8 +16,6 @@ package collector import ( - "bytes" - "github.com/go-kit/kit/log/level" "golang.org/x/sys/unix" ) @@ -42,19 +40,14 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { } stats := []filesystemStats{} for _, fs := range buf { - // We need to work out the lengths of the actual strings here, - // otherwuse we will end up with null bytes in our label values. - mountpoint_len := bytes.Index(fs.Mntonname[:], []byte{0}) - mountpoint := string(fs.Mntonname[:mountpoint_len]) + mountpoint := bytesToString(fs.Mntonname[:]) if c.ignoredMountPointsPattern.MatchString(mountpoint) { level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint) continue } - device_len := bytes.Index(fs.Mntfromname[:], []byte{0}) - fstype_len := bytes.Index(fs.Fstypename[:], []byte{0}) - device := string(fs.Mntfromname[:device_len]) - fstype := string(fs.Fstypename[:fstype_len]) + device := bytesToString(fs.Mntfromname[:]) + fstype := bytesToString(fs.Fstypename[:]) if c.ignoredFSTypesPattern.MatchString(fstype) { level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype) continue