Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zfs: Only attempt to pull mibs from supported Releases #3141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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