Noticed today that filesystems are exported with lots of NUL bytes.
Before:
node_filesystem_avail_bytes{device="/dev/sd0a���������������������������������������������������������������������������������",fstype="ffs�������������",mountpoint="/�����������������������������������������������������������������������������������������"}
After:
node_filesystem_avail_bytes{device="/dev/sd0a",fstype="ffs",mountpoint="/"}
The patch is from the pull request I sent to node_exporter.
--
:wq Claudio
diff -Nur node_exporter.orig/Makefile node_exporter/Makefile
--- node_exporter.orig/Makefile Sun Mar 19 16:42:37 2023
+++ node_exporter/Makefile Sun Mar 19 16:15:06 2023
@@ -2,6 +2,7 @@
MODGO_MODNAME = github.com/prometheus/node_exporter
MODGO_VERSION = v1.5.0
+REVISION = 0
DISTNAME = node_exporter-${MODGO_VERSION}
@@ -12,6 +13,8 @@
MAINTAINER = Claudio Jeker <[email protected]>
# Apache 2.0
PERMIT_PACKAGE = Yes
+
+WRKDIST = ${WRKSRC}
WANTLIB = c pthread
diff -Nur node_exporter.orig/patches/patch-filesystem-collector
node_exporter/patches/patch-filesystem-collector
--- node_exporter.orig/patches/patch-filesystem-collector Thu Jan 1
01:00:00 1970
+++ node_exporter/patches/patch-filesystem-collector Sun Mar 19 16:41:16 2023
@@ -0,0 +1,190 @@
+commit ed5c66f419e9f905b0888c90fb478d4a5874ce4c
+Author: Claudio Jeker <[email protected]>
+Date: 42 minutes ago
+
+ Fix filesystem collector for OpenBSD to not print loads of zero bytes in
name
+
+ Use the filesystem collector for all OpenBSD archs, there is no reason to
+ only use it on amd64 systems.
+
+diff --git collector/filesystem_bsd.go collector/filesystem_bsd.go
+index dc35c4f..d3025a0 100644
+--- collector/filesystem_bsd.go
++++ collector/filesystem_bsd.go
+@@ -11,8 +11,8 @@
+ // See the License for the specific language governing permissions and
+ // limitations under the License.
+
+-//go:build ((openbsd && !amd64) || darwin || dragonfly) && !nofilesystem
+-// +build openbsd,!amd64 darwin dragonfly
++//go:build (darwin || dragonfly) && !nofilesystem
++// +build darwin dragonfly
+ // +build !nofilesystem
+
+ package collector
+diff --git collector/filesystem_openbsd.go collector/filesystem_openbsd.go
+new file mode 100644
+index 0000000..16cd610
+--- /dev/null
++++ collector/filesystem_openbsd.go
+@@ -0,0 +1,77 @@
++// Copyright 2020 The Prometheus Authors
++// Licensed under the Apache License, Version 2.0 (the "License");
++// you may not use this file except in compliance with the License.
++// You may obtain a copy of the License at
++//
++// http://www.apache.org/licenses/LICENSE-2.0
++//
++// Unless required by applicable law or agreed to in writing, software
++// distributed under the License is distributed on an "AS IS" BASIS,
++// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
++// See the License for the specific language governing permissions and
++// limitations under the License.
++
++//go:build openbsd && !nofilesystem
++// +build openbsd,!nofilesystem
++
++package collector
++
++import (
++ "github.com/go-kit/log/level"
++ "golang.org/x/sys/unix"
++)
++
++const (
++ defMountPointsExcluded = "^/(dev)($|/)"
++ defFSTypesExcluded = "^devfs$"
++)
++
++// Expose filesystem fullness.
++func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error)
{
++ var mnt []unix.Statfs_t
++ size, err := unix.Getfsstat(mnt, unix.MNT_NOWAIT)
++ if err != nil {
++ return nil, err
++ }
++ mnt = make([]unix.Statfs_t, size)
++ _, err = unix.Getfsstat(mnt, unix.MNT_NOWAIT)
++ if err != nil {
++ return nil, err
++ }
++
++ stats = []filesystemStats{}
++ for _, v := range mnt {
++ mountpoint := unix.ByteSliceToString(v.F_mntonname[:])
++ if c.excludedMountPointsPattern.MatchString(mountpoint) {
++ level.Debug(c.logger).Log("msg", "Ignoring mount
point", "mountpoint", mountpoint)
++ continue
++ }
++
++ device := unix.ByteSliceToString(v.F_mntfromname[:])
++ fstype := unix.ByteSliceToString(v.F_fstypename[:])
++ if c.excludedFSTypesPattern.MatchString(fstype) {
++ level.Debug(c.logger).Log("msg", "Ignoring fs type",
"type", fstype)
++ continue
++ }
++
++ var ro float64
++ if (v.F_flags & unix.MNT_RDONLY) != 0 {
++ ro = 1
++ }
++
++ stats = append(stats, filesystemStats{
++ labels: filesystemLabels{
++ device: device,
++ mountPoint: mountpoint,
++ fsType: fstype,
++ },
++ size: float64(v.F_blocks) * float64(v.F_bsize),
++ free: float64(v.F_bfree) * float64(v.F_bsize),
++ avail: float64(v.F_bavail) * float64(v.F_bsize),
++ files: float64(v.F_files),
++ filesFree: float64(v.F_ffree),
++ ro: ro,
++ })
++ }
++ return stats, nil
++}
+diff --git collector/filesystem_openbsd_amd64.go
collector/filesystem_openbsd_amd64.go
+deleted file mode 100644
+index 75fc844..0000000
+--- collector/filesystem_openbsd_amd64.go
++++ /dev/null
+@@ -1,77 +0,0 @@
+-// Copyright 2020 The Prometheus Authors
+-// Licensed under the Apache License, Version 2.0 (the "License");
+-// you may not use this file except in compliance with the License.
+-// You may obtain a copy of the License at
+-//
+-// http://www.apache.org/licenses/LICENSE-2.0
+-//
+-// Unless required by applicable law or agreed to in writing, software
+-// distributed under the License is distributed on an "AS IS" BASIS,
+-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-// See the License for the specific language governing permissions and
+-// limitations under the License.
+-
+-//go:build openbsd && !nofilesystem
+-// +build openbsd,!nofilesystem
+-
+-package collector
+-
+-import (
+- "github.com/go-kit/log/level"
+- "golang.org/x/sys/unix"
+-)
+-
+-const (
+- defMountPointsExcluded = "^/(dev)($|/)"
+- defFSTypesExcluded = "^devfs$"
+-)
+-
+-// Expose filesystem fullness.
+-func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error)
{
+- var mnt []unix.Statfs_t
+- size, err := unix.Getfsstat(mnt, unix.MNT_NOWAIT)
+- if err != nil {
+- return nil, err
+- }
+- mnt = make([]unix.Statfs_t, size)
+- _, err = unix.Getfsstat(mnt, unix.MNT_NOWAIT)
+- if err != nil {
+- return nil, err
+- }
+-
+- stats = []filesystemStats{}
+- for _, v := range mnt {
+- mountpoint := string(v.F_mntonname[:])
+- if c.excludedMountPointsPattern.MatchString(mountpoint) {
+- level.Debug(c.logger).Log("msg", "Ignoring mount
point", "mountpoint", mountpoint)
+- continue
+- }
+-
+- device := string(v.F_mntfromname[:])
+- fstype := string(v.F_fstypename[:])
+- if c.excludedFSTypesPattern.MatchString(fstype) {
+- level.Debug(c.logger).Log("msg", "Ignoring fs type",
"type", fstype)
+- continue
+- }
+-
+- var ro float64
+- if (v.F_flags & unix.MNT_RDONLY) != 0 {
+- ro = 1
+- }
+-
+- stats = append(stats, filesystemStats{
+- labels: filesystemLabels{
+- device: device,
+- mountPoint: mountpoint,
+- fsType: fstype,
+- },
+- size: float64(v.F_blocks) * float64(v.F_bsize),
+- free: float64(v.F_bfree) * float64(v.F_bsize),
+- avail: float64(v.F_bavail) * float64(v.F_bsize),
+- files: float64(v.F_files),
+- filesFree: float64(v.F_ffree),
+- ro: ro,
+- })
+- }
+- return stats, nil
+-}