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

collector/zfs: consistent metric names #3025

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ For advanced use the `node_exporter` can be passed an optional list of collector

This can be useful for having different Prometheus servers collect specific metrics from nodes.

### Feature Flags

Feature flags are used to enable or disable specific features. They can be set using the `--feature.gates` flag (`key1=true,key2=false,...`). The following feature flags are available:
* `ConsistentZFSLinuxMetricNames` (default: `false`): Use consistent metric names for ZFS metrics on Linux (same as BSD).

## Development building and running

Prerequisites:
Expand Down
13 changes: 12 additions & 1 deletion collector/zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ package collector

import (
"errors"
"github.com/prometheus/node_exporter/featuregate"
"strings"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)

var errZFSNotAvailable = errors.New("ZFS / ZFS statistics are not available")
var (
errZFSNotAvailable = errors.New("ZFS / ZFS statistics are not available")
consistentZFSLinuxMetricNames = featuregate.NewFeatureGate(
"ConsistentZFSLinuxMetricNames",
"Use consistent metric names for ZFS metrics on Linux (similar to the ones from FreeBSD)",
"v1.8.1", "v1.9.0")
)

type zfsSysctl string

Expand Down Expand Up @@ -91,6 +98,10 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error {
}

func (s zfsSysctl) metricName() string {
if isEnabled, _ := consistentZFSLinuxMetricNames.IsEnabled(); isEnabled {
mib := string(s)
return bsdsysctl[mib]
}
parts := strings.Split(string(s), ".")
return strings.Replace(parts[len(parts)-1], "-", "_", -1)
}
Expand Down
51 changes: 51 additions & 0 deletions collector/zfs_common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2024 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.

package collector

var (
bsdsysctl = map[string]string{
"kstat.zfs.misc.abdstats.linear_cnt": "abdstats_linear_count_total",
"kstat.zfs.misc.abdstats.linear_data_size": "abdstats_linear_data_bytes",
"kstat.zfs.misc.abdstats.scatter_chunk_waste": "abdstats_scatter_chunk_waste_bytes",
"kstat.zfs.misc.abdstats.scatter_cnt": "abdstats_scatter_count_total",
"kstat.zfs.misc.abdstats.scatter_data_size": "abdstats_scatter_data_bytes",
"kstat.zfs.misc.abdstats.struct_size": "abdstats_struct_bytes",
"kstat.zfs.misc.arcstats.anon_size": "arcstats_anon_bytes",
"kstat.zfs.misc.arcstats.c": "arcstats_c_bytes",
"kstat.zfs.misc.arcstats.c_max": "arcstats_c_max_bytes",
"kstat.zfs.misc.arcstats.c_min": "arcstats_c_min_bytes",
"kstat.zfs.misc.arcstats.data_size": "arcstats_data_bytes",
"kstat.zfs.misc.arcstats.demand_data_hits": "arcstats_demand_data_hits_total",
"kstat.zfs.misc.arcstats.demand_data_misses": "arcstats_demand_data_misses_total",
"kstat.zfs.misc.arcstats.demand_metadata_hits": "arcstats_demand_metadata_hits_total",
"kstat.zfs.misc.arcstats.demand_metadata_misses": "arcstats_demand_metadata_misses_total",
"kstat.zfs.misc.arcstats.hdr_size": "arcstats_hdr_bytes",
"kstat.zfs.misc.arcstats.hits": "arcstats_hits_total",
"kstat.zfs.misc.arcstats.misses": "arcstats_misses_total",
"kstat.zfs.misc.arcstats.mfu_ghost_hits": "arcstats_mfu_ghost_hits_total",
"kstat.zfs.misc.arcstats.mfu_ghost_size": "arcstats_mfu_ghost_size",
"kstat.zfs.misc.arcstats.mfu_size": "arcstats_mfu_bytes",
"kstat.zfs.misc.arcstats.mru_ghost_hits": "arcstats_mru_ghost_hits_total",
"kstat.zfs.misc.arcstats.mru_ghost_size": "arcstats_mru_ghost_bytes",
"kstat.zfs.misc.arcstats.mru_size": "arcstats_mru_bytes",
"kstat.zfs.misc.arcstats.other_size": "arcstats_other_bytes",
"kstat.zfs.misc.arcstats.p": "arcstats_p_bytes",
"kstat.zfs.misc.arcstats.meta": "arcstats_meta_bytes",
"kstat.zfs.misc.arcstats.pd": "arcstats_pd_bytes",
"kstat.zfs.misc.arcstats.pm": "arcstats_pm_bytes",
"kstat.zfs.misc.arcstats.size": "arcstats_size_bytes",
"kstat.zfs.misc.zfetchstats.hits": "zfetchstats_hits_total",
"kstat.zfs.misc.zfetchstats.misses": "zfetchstats_misses_total",
}
)
34 changes: 1 addition & 33 deletions collector/zfs_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,225 +39,193 @@ func NewZfsCollector(logger log.Logger) (Collector, error) {
return &zfsCollector{
sysctls: []bsdSysctl{
{
name: "abdstats_linear_count_total",
description: "ZFS ARC buffer data linear count",
mib: "kstat.zfs.misc.abdstats.linear_cnt",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.CounterValue,
},
{
name: "abdstats_linear_data_bytes",
description: "ZFS ARC buffer data linear data size",
mib: "kstat.zfs.misc.abdstats.linear_data_size",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.GaugeValue,
},
{
name: "abdstats_scatter_chunk_waste_bytes",
description: "ZFS ARC buffer data scatter chunk waste",
mib: "kstat.zfs.misc.abdstats.scatter_chunk_waste",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.GaugeValue,
},
{
name: "abdstats_scatter_count_total",
description: "ZFS ARC buffer data scatter count",
mib: "kstat.zfs.misc.abdstats.scatter_cnt",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.CounterValue,
},
{
name: "abdstats_scatter_data_bytes",
description: "ZFS ARC buffer data scatter data size",
mib: "kstat.zfs.misc.abdstats.scatter_data_size",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.GaugeValue,
},
{
name: "abdstats_struct_bytes",
description: "ZFS ARC buffer data struct size",
mib: "kstat.zfs.misc.abdstats.struct_size",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.GaugeValue,
},
{
name: "arcstats_anon_bytes",
description: "ZFS ARC anon size",
mib: "kstat.zfs.misc.arcstats.anon_size",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.GaugeValue,
},
{
name: "arcstats_c_bytes",
description: "ZFS ARC target size",
mib: "kstat.zfs.misc.arcstats.c",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.GaugeValue,
},
{
name: "arcstats_c_max_bytes",
description: "ZFS ARC maximum size",
mib: "kstat.zfs.misc.arcstats.c_max",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.GaugeValue,
},
{
name: "arcstats_c_min_bytes",
description: "ZFS ARC minimum size",
mib: "kstat.zfs.misc.arcstats.c_min",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.GaugeValue,
},
{
name: "arcstats_data_bytes",
description: "ZFS ARC data size",
mib: "kstat.zfs.misc.arcstats.data_size",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.GaugeValue,
},
{
name: "arcstats_demand_data_hits_total",
description: "ZFS ARC demand data hits",
mib: "kstat.zfs.misc.arcstats.demand_data_hits",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.CounterValue,
},
{
name: "arcstats_demand_data_misses_total",
description: "ZFS ARC demand data misses",
mib: "kstat.zfs.misc.arcstats.demand_data_misses",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.CounterValue,
},
{
name: "arcstats_demand_metadata_hits_total",
description: "ZFS ARC demand metadata hits",
mib: "kstat.zfs.misc.arcstats.demand_metadata_hits",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.CounterValue,
},
{
name: "arcstats_demand_metadata_misses_total",
description: "ZFS ARC demand metadata misses",
mib: "kstat.zfs.misc.arcstats.demand_metadata_misses",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.CounterValue,
},
{
name: "arcstats_hdr_bytes",
description: "ZFS ARC header size",
mib: "kstat.zfs.misc.arcstats.hdr_size",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.GaugeValue,
},
{
name: "arcstats_hits_total",
description: "ZFS ARC hits",
mib: "kstat.zfs.misc.arcstats.hits",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.CounterValue,
},
{
name: "arcstats_misses_total",
description: "ZFS ARC misses",
mib: "kstat.zfs.misc.arcstats.misses",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.CounterValue,
},
{
name: "arcstats_mfu_ghost_hits_total",
description: "ZFS ARC MFU ghost hits",
mib: "kstat.zfs.misc.arcstats.mfu_ghost_hits",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.CounterValue,
},
{
name: "arcstats_mfu_ghost_size",
description: "ZFS ARC MFU ghost size",
mib: "kstat.zfs.misc.arcstats.mfu_ghost_size",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.GaugeValue,
},
{
name: "arcstats_mfu_bytes",
description: "ZFS ARC MFU size",
mib: "kstat.zfs.misc.arcstats.mfu_size",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.GaugeValue,
},
{
name: "arcstats_mru_ghost_hits_total",
description: "ZFS ARC MRU ghost hits",
mib: "kstat.zfs.misc.arcstats.mru_ghost_hits",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.CounterValue,
},
{
name: "arcstats_mru_ghost_bytes",
description: "ZFS ARC MRU ghost size",
mib: "kstat.zfs.misc.arcstats.mru_ghost_size",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.GaugeValue,
},
{
name: "arcstats_mru_bytes",
description: "ZFS ARC MRU size",
mib: "kstat.zfs.misc.arcstats.mru_size",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.GaugeValue,
},
{
name: "arcstats_other_bytes",
description: "ZFS ARC other size",
mib: "kstat.zfs.misc.arcstats.other_size",
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",
dataType: bsdSysctlTypeUint64,
valueType: prometheus.GaugeValue,
},
{
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",
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,
Expand All @@ -279,7 +247,7 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error {

ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, m.name),
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, bsdsysctl[m.mib]),
m.description,
nil, nil,
), m.valueType, v)
Expand Down
Loading