mirror of
				https://github.com/prometheus/node_exporter.git
				synced 2025-08-20 18:33:52 -07:00 
			
		
		
		
	Merge f527765193 into be19d537cd
				
					
				
			This commit is contained in:
		
						commit
						27c3e5481d
					
				| 
						 | 
				
			
			@ -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
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,35 +210,6 @@ 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",
 | 
			
		||||
				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",
 | 
			
		||||
| 
						 | 
				
			
			@ -260,7 +233,50 @@ func NewZFSCollector(logger *slog.Logger) (Collector, error) {
 | 
			
		|||
			},
 | 
			
		||||
		},
 | 
			
		||||
		logger: logger,
 | 
			
		||||
	}, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	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,
 | 
			
		||||
			},
 | 
			
		||||
		)
 | 
			
		||||
	} 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,
 | 
			
		||||
			},
 | 
			
		||||
		)
 | 
			
		||||
	}
 | 
			
		||||
	return c, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue