Skip to content

Commit

Permalink
zfs: Only attempt to pull mibs from supported Releases
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dekimsey committed Oct 2, 2024
1 parent 1b332ed commit f527765
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 29 deletions.
13 changes: 13 additions & 0 deletions collector/uname_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package collector

import (
"strconv"
"strings"

"golang.org/x/sys/unix"
Expand Down Expand Up @@ -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
}
74 changes: 45 additions & 29 deletions collector/zfs_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
package collector

import (
"github.com/prometheus/client_golang/prometheus"
"log/slog"

"github.com/prometheus/client_golang/prometheus"
)

type zfsCollector struct {
Expand All @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f527765

Please sign in to comment.