fix(zfs) zfs arcstats.p on FreeBSD 14.0+ (#2754)

* dongjiang, fix zfs arcstats.p

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>

* dongjiang, fix gofmt -s

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>

* change warn log to debug log by code review

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>

---------

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
This commit is contained in:
dongjiang 2023-09-20 17:49:56 +08:00 committed by GitHub
parent 446b3e64ff
commit e8c5110ada
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,7 @@ import (
"fmt"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/unix"
@ -241,6 +242,7 @@ func NewZfsCollector(logger log.Logger) (Collector, error) {
valueType: prometheus.GaugeValue,
labels: nil,
},
// when FreeBSD 14.0+, `meta/pm/pd` install of `p`.
{
name: "arcstats_p_bytes",
description: "ZFS ARC MRU target size",
@ -249,6 +251,27 @@ func NewZfsCollector(logger log.Logger) (Collector, error) {
valueType: prometheus.GaugeValue,
labels: nil,
},
{
name: "arcstats_meta_bytes",
description: "ZFS ARC metadata target frac ",
mib: "kstat.zfs.misc.arcstats.meta",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.GaugeValue,
},
{
name: "arcstats_pd_bytes",
description: "ZFS ARC data MRU target frac",
mib: "kstat.zfs.misc.arcstats.pd",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.GaugeValue,
},
{
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",
@ -282,7 +305,9 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error {
for _, m := range c.sysctls {
v, err := m.Value()
if err != nil {
return fmt.Errorf("couldn't get sysctl: %w", err)
// debug logging
level.Debug(c.logger).Log("name", m.name, "couldn't get sysctl:", err)
continue
}
ch <- prometheus.MustNewConstMetric(