Skip to content

Commit 03450a4

Browse files
phyberdiscordianfish
authored andcommitted
filesystem_freebsd: Use bytesToString to get label values
Signed-off-by: David O'Rourke <david.orourke@gmail.com>
1 parent d6fbce1 commit 03450a4

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

collector/filesystem_freebsd.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
package collector
1717

1818
import (
19-
"bytes"
20-
2119
"github.com/go-kit/kit/log/level"
2220
"golang.org/x/sys/unix"
2321
)
@@ -42,19 +40,14 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {
4240
}
4341
stats := []filesystemStats{}
4442
for _, fs := range buf {
45-
// We need to work out the lengths of the actual strings here,
46-
// otherwuse we will end up with null bytes in our label values.
47-
mountpoint_len := bytes.Index(fs.Mntonname[:], []byte{0})
48-
mountpoint := string(fs.Mntonname[:mountpoint_len])
43+
mountpoint := bytesToString(fs.Mntonname[:])
4944
if c.ignoredMountPointsPattern.MatchString(mountpoint) {
5045
level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint)
5146
continue
5247
}
5348

54-
device_len := bytes.Index(fs.Mntfromname[:], []byte{0})
55-
fstype_len := bytes.Index(fs.Fstypename[:], []byte{0})
56-
device := string(fs.Mntfromname[:device_len])
57-
fstype := string(fs.Fstypename[:fstype_len])
49+
device := bytesToString(fs.Mntfromname[:])
50+
fstype := bytesToString(fs.Fstypename[:])
5851
if c.ignoredFSTypesPattern.MatchString(fstype) {
5952
level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype)
6053
continue

0 commit comments

Comments
 (0)