From f527765193377ddc33e417a876a750453aceac83 Mon Sep 17 00:00:00 2001 From: Daniel Kimsey Date: Sat, 23 Mar 2024 15:28:14 -0500 Subject: [PATCH] zfs: Only attempt to pull mibs from supported Releases In particular 14.0 changed the way arcstats were listed, but we previously attempted to grab them all. By adding a bit of a major release detection we reduce the error noise. Signed-off-by: Daniel Kimsey --- collector/uname_bsd.go | 13 +++++++ collector/zfs_freebsd.go | 74 ++++++++++++++++++++++++---------------- 2 files changed, 58 insertions(+), 29 deletions(-) diff --git a/collector/uname_bsd.go b/collector/uname_bsd.go index fa565a1ccf..7b541209a3 100644 --- a/collector/uname_bsd.go +++ b/collector/uname_bsd.go @@ -18,6 +18,7 @@ package collector import ( + "strconv" "strings" "golang.org/x/sys/unix" @@ -61,3 +62,15 @@ func parseHostNameAndDomainName(utsname unix.Utsname) (hostname string, domainna } return hostname, domainname } + +// getOSReleaseMajorMinor returns the Major.Minor version of the Operating System based on the uname's Release as a floating point number +// this is intended to assist in detecting OS compatibilty/support +func getOSReleaseMajorMinor() (float64, error) { + u, err := getUname() + if err != nil { + return 0, err + } + majorMinor := versionRegex.FindString(u.Release) + f, err := strconv.ParseFloat(majorMinor, 64) + return f, err +} diff --git a/collector/zfs_freebsd.go b/collector/zfs_freebsd.go index d888c3a724..64d4ccaa2b 100644 --- a/collector/zfs_freebsd.go +++ b/collector/zfs_freebsd.go @@ -17,8 +17,9 @@ package collector import ( - "github.com/prometheus/client_golang/prometheus" "log/slog" + + "github.com/prometheus/client_golang/prometheus" ) type zfsCollector struct { @@ -31,7 +32,8 @@ const ( ) func NewZFSCollector(logger *slog.Logger) (Collector, error) { - return &zfsCollector{ + c := &zfsCollector{ + // Common ZFS sysctl metrics sysctls: []bsdSysctl{ { name: "abdstats_linear_count_total", @@ -208,59 +210,73 @@ func NewZFSCollector(logger *slog.Logger) (Collector, error) { dataType: bsdSysctlTypeUint64, valueType: prometheus.GaugeValue, }, - // when FreeBSD 14.0+, `meta/pm/pd` install of `p`. { - name: "arcstats_p_bytes", - description: "ZFS ARC MRU target size", - mib: "kstat.zfs.misc.arcstats.p", + name: "arcstats_size_bytes", + description: "ZFS ARC size", + mib: "kstat.zfs.misc.arcstats.size", dataType: bsdSysctlTypeUint64, valueType: prometheus.GaugeValue, }, { + name: "zfetchstats_hits_total", + description: "ZFS cache fetch hits", + mib: "kstat.zfs.misc.zfetchstats.hits", + dataType: bsdSysctlTypeUint64, + valueType: prometheus.CounterValue, + }, + { + name: "zfetchstats_misses_total", + description: "ZFS cache fetch misses", + mib: "kstat.zfs.misc.zfetchstats.misses", + dataType: bsdSysctlTypeUint64, + valueType: prometheus.CounterValue, + }, + }, + logger: logger, + } + + v, err := getOSReleaseMajorMinor() + if err != nil { + c.logger.Warn("unable to determine OS release, zfs arcstats metrics may be missing or unsupported", "error", err) + return c, nil + } + // when FreeBSD 14.0+, use `meta/pm/pd` instead of `p`. + if v >= 14.0 { + c.sysctls = append(c.sysctls, + bsdSysctl{ name: "arcstats_meta_bytes", description: "ZFS ARC metadata target frac ", mib: "kstat.zfs.misc.arcstats.meta", dataType: bsdSysctlTypeUint64, valueType: prometheus.GaugeValue, }, - { + bsdSysctl{ name: "arcstats_pd_bytes", description: "ZFS ARC data MRU target frac", mib: "kstat.zfs.misc.arcstats.pd", dataType: bsdSysctlTypeUint64, valueType: prometheus.GaugeValue, }, - { + bsdSysctl{ name: "arcstats_pm_bytes", description: "ZFS ARC meta MRU target frac", mib: "kstat.zfs.misc.arcstats.pm", dataType: bsdSysctlTypeUint64, valueType: prometheus.GaugeValue, }, - { - name: "arcstats_size_bytes", - description: "ZFS ARC size", - mib: "kstat.zfs.misc.arcstats.size", + ) + } else { + c.sysctls = append(c.sysctls, + bsdSysctl{ + name: "arcstats_p_bytes", + description: "ZFS ARC MRU target size", + mib: "kstat.zfs.misc.arcstats.p", dataType: bsdSysctlTypeUint64, valueType: prometheus.GaugeValue, }, - { - name: "zfetchstats_hits_total", - description: "ZFS cache fetch hits", - mib: "kstat.zfs.misc.zfetchstats.hits", - dataType: bsdSysctlTypeUint64, - valueType: prometheus.CounterValue, - }, - { - name: "zfetchstats_misses_total", - description: "ZFS cache fetch misses", - mib: "kstat.zfs.misc.zfetchstats.misses", - dataType: bsdSysctlTypeUint64, - valueType: prometheus.CounterValue, - }, - }, - logger: logger, - }, nil + ) + } + return c, nil } func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error {