Add kstat-based Solaris metrics (#1197)
* collector/loadavg_solaris.go: Use libkstat to gather load averages. * go.mod: Added go-kstat. * boot_time_solaris.go: Added. * cpu_solaris.go: Added. * README.md: Updated entries for Solaris. * collector/zfs_solaris.go: Added. * CHANGELOG.md: Added note about kstat-based Solaris metrics. Signed-off-by: Jonathan Davies <jpds@protonmail.com>
This commit is contained in:
parent
a616953b9a
commit
e766485286
9 changed files with 583 additions and 14 deletions
66
collector/boot_time_solaris.go
Normal file
66
collector/boot_time_solaris.go
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
// +build solaris
|
||||
// +build !noboottime
|
||||
|
||||
package collector
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/siebenmann/go-kstat"
|
||||
)
|
||||
|
||||
type bootTimeCollector struct {
|
||||
boottime typedDesc
|
||||
}
|
||||
|
||||
func init() {
|
||||
registerCollector("boottime", defaultEnabled, newBootTimeCollector)
|
||||
}
|
||||
|
||||
func newBootTimeCollector() (Collector, error) {
|
||||
return &bootTimeCollector{
|
||||
boottime: typedDesc{
|
||||
prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "", "boot_time_seconds"),
|
||||
"Unix time of last boot, including microseconds.",
|
||||
nil, nil,
|
||||
), prometheus.GaugeValue},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// newBootTimeCollector returns a new Collector exposing system boot time on Solaris systems.
|
||||
// Update pushes boot time onto ch
|
||||
func (c *bootTimeCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
tok, err := kstat.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer tok.Close()
|
||||
|
||||
ks, err := tok.Lookup("unix", 0, "system_misc")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
v, err := ks.GetNamed("boot_time")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ch <- c.boottime.mustNewConstMetric(float64(v.UintVal))
|
||||
|
||||
return nil
|
||||
}
|
||||
140
collector/cpu_solaris.go
Normal file
140
collector/cpu_solaris.go
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
// +build solaris
|
||||
// +build !nocpu
|
||||
|
||||
package collector
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/siebenmann/go-kstat"
|
||||
)
|
||||
|
||||
// #include <unistd.h>
|
||||
import "C"
|
||||
|
||||
type cpuCollector struct {
|
||||
cpu typedDesc
|
||||
cpuFreq *prometheus.Desc
|
||||
cpuFreqMax *prometheus.Desc
|
||||
}
|
||||
|
||||
func init() {
|
||||
registerCollector("cpu", defaultEnabled, NewCpuCollector)
|
||||
}
|
||||
|
||||
func NewCpuCollector() (Collector, error) {
|
||||
return &cpuCollector{
|
||||
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue},
|
||||
cpuFreq: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "frequency_hertz"),
|
||||
"Current cpu thread frequency in hertz.",
|
||||
[]string{"cpu"}, nil,
|
||||
),
|
||||
cpuFreqMax: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "frequency_max_hertz"),
|
||||
"Maximum cpu thread frequency in hertz.",
|
||||
[]string{"cpu"}, nil,
|
||||
),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *cpuCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
if err := c.updateCPUstats(ch); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.updateCPUfreq(ch); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *cpuCollector) updateCPUstats(ch chan<- prometheus.Metric) error {
|
||||
ncpus := C.sysconf(C._SC_NPROCESSORS_ONLN)
|
||||
|
||||
tok, err := kstat.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer tok.Close()
|
||||
|
||||
for cpu := 0; cpu < int(ncpus); cpu++ {
|
||||
ksCPU, err := tok.Lookup("cpu", cpu, "sys")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for k, v := range map[string]string{
|
||||
"idle": "cpu_ticks_idle",
|
||||
"kernel": "cpu_ticks_kernel",
|
||||
"user": "cpu_ticks_user",
|
||||
"wait": "cpu_ticks_wait",
|
||||
} {
|
||||
kstatValue, err := ksCPU.GetNamed(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ch <- c.cpu.mustNewConstMetric(float64(kstatValue.UintVal), strconv.Itoa(cpu), k)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *cpuCollector) updateCPUfreq(ch chan<- prometheus.Metric) error {
|
||||
ncpus := C.sysconf(C._SC_NPROCESSORS_ONLN)
|
||||
|
||||
tok, err := kstat.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer tok.Close()
|
||||
|
||||
for cpu := 0; cpu < int(ncpus); cpu++ {
|
||||
ksCPUInfo, err := tok.Lookup("cpu_info", cpu, fmt.Sprintf("cpu_info%d", cpu))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cpuFreqV, err := ksCPUInfo.GetNamed("current_clock_Hz")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cpuFreqMaxV, err := ksCPUInfo.GetNamed("clock_MHz")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lcpu := strconv.Itoa(cpu)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.cpuFreq,
|
||||
prometheus.GaugeValue,
|
||||
float64(cpuFreqV.UintVal),
|
||||
lcpu,
|
||||
)
|
||||
// Multiply by 1e+6 to convert MHz to Hz.
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.cpuFreqMax,
|
||||
prometheus.GaugeValue,
|
||||
float64(cpuFreqMaxV.IntVal)*1e+6,
|
||||
lcpu,
|
||||
)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -16,21 +16,49 @@
|
|||
package collector
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/siebenmann/go-kstat"
|
||||
)
|
||||
|
||||
/*
|
||||
// Ensure "hrtime_t" is defined for sys/loadavg.h
|
||||
#include <sys/time.h>
|
||||
#include <sys/loadavg.h>
|
||||
*/
|
||||
// #include <sys/param.h>
|
||||
import "C"
|
||||
|
||||
func getLoad() ([]float64, error) {
|
||||
var loadavg [3]C.double
|
||||
samples := C.getloadavg(&loadavg[0], 3)
|
||||
if samples != 3 {
|
||||
return nil, errors.New("failed to get load average")
|
||||
func kstatToFloat(ks *kstat.KStat, kstatKey string) float64 {
|
||||
kstatValue, err := ks.GetNamed(kstatKey)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return []float64{float64(loadavg[0]), float64(loadavg[1]), float64(loadavg[2])}, nil
|
||||
|
||||
kstatLoadavg, err := strconv.ParseFloat(
|
||||
fmt.Sprintf("%.2f", float64(kstatValue.UintVal)/C.FSCALE), 64)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return kstatLoadavg
|
||||
}
|
||||
|
||||
func getLoad() ([]float64, error) {
|
||||
tok, err := kstat.Open()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer tok.Close()
|
||||
|
||||
ks, err := tok.Lookup("unix", 0, "system_misc")
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
loadavg1Min := kstatToFloat(ks, "avenrun_1min")
|
||||
loadavg5Min := kstatToFloat(ks, "avenrun_5min")
|
||||
loadavg15Min := kstatToFloat(ks, "avenrun_15min")
|
||||
|
||||
return []float64{loadavg1Min, loadavg5Min, loadavg15Min}, nil
|
||||
}
|
||||
|
|
|
|||
329
collector/zfs_solaris.go
Normal file
329
collector/zfs_solaris.go
Normal file
|
|
@ -0,0 +1,329 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
// +build solaris
|
||||
|
||||
package collector
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/siebenmann/go-kstat"
|
||||
)
|
||||
|
||||
type zfsCollector struct {
|
||||
abdstatsLinearCount *prometheus.Desc
|
||||
abdstatsLinearDataSize *prometheus.Desc
|
||||
abdstatsScatterChunkWaste *prometheus.Desc
|
||||
abdstatsScatterCount *prometheus.Desc
|
||||
abdstatsScatterDataSize *prometheus.Desc
|
||||
abdstatsStructSize *prometheus.Desc
|
||||
arcstatsAnonSize *prometheus.Desc
|
||||
arcstatsC *prometheus.Desc
|
||||
arcstatsCMax *prometheus.Desc
|
||||
arcstatsCMin *prometheus.Desc
|
||||
arcstatsDataSize *prometheus.Desc
|
||||
arcstatsDemandDataHits *prometheus.Desc
|
||||
arcstatsDemandDataMisses *prometheus.Desc
|
||||
arcstatsDemandMetadataHits *prometheus.Desc
|
||||
arcstatsDemandMetadataMisses *prometheus.Desc
|
||||
arcstatsHeaderSize *prometheus.Desc
|
||||
arcstatsHits *prometheus.Desc
|
||||
arcstatsMisses *prometheus.Desc
|
||||
arcstatsMFUGhostHits *prometheus.Desc
|
||||
arcstatsMFUGhostSize *prometheus.Desc
|
||||
arcstatsMFUSize *prometheus.Desc
|
||||
arcstatsMRUGhostHits *prometheus.Desc
|
||||
arcstatsMRUGhostSize *prometheus.Desc
|
||||
arcstatsMRUSize *prometheus.Desc
|
||||
arcstatsOtherSize *prometheus.Desc
|
||||
arcstatsP *prometheus.Desc
|
||||
arcstatsSize *prometheus.Desc
|
||||
zfetchstatsHits *prometheus.Desc
|
||||
zfetchstatsMisses *prometheus.Desc
|
||||
}
|
||||
|
||||
const (
|
||||
zfsCollectorSubsystem = "zfs"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registerCollector("zfs", defaultEnabled, NewZfsCollector)
|
||||
}
|
||||
|
||||
func NewZfsCollector() (Collector, error) {
|
||||
return &zfsCollector{
|
||||
abdstatsLinearCount: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "abdstats_linear_count_total"),
|
||||
"ZFS ARC buffer data linear count", nil, nil,
|
||||
),
|
||||
abdstatsLinearDataSize: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "abdstats_linear_data_bytes"),
|
||||
"ZFS ARC buffer data linear data size", nil, nil,
|
||||
),
|
||||
abdstatsScatterChunkWaste: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "abdstats_scatter_chunk_waste_bytes"),
|
||||
"ZFS ARC buffer data scatter chunk waste", nil, nil,
|
||||
),
|
||||
abdstatsScatterCount: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "abdstats_scatter_count_total"),
|
||||
"ZFS ARC buffer data scatter count", nil, nil,
|
||||
),
|
||||
abdstatsScatterDataSize: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "abdstats_scatter_data_bytes"),
|
||||
"ZFS ARC buffer data scatter data size", nil, nil,
|
||||
),
|
||||
abdstatsStructSize: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "abdstats_struct_bytes"),
|
||||
"ZFS ARC buffer data struct size", nil, nil,
|
||||
),
|
||||
arcstatsAnonSize: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_anon_bytes"),
|
||||
"ZFS ARC anon size", nil, nil,
|
||||
),
|
||||
arcstatsC: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_c_bytes"),
|
||||
"ZFS ARC target size", nil, nil,
|
||||
),
|
||||
arcstatsCMax: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_c_max_bytes"),
|
||||
"ZFS ARC maximum size", nil, nil,
|
||||
),
|
||||
arcstatsCMin: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_c_min_bytes"),
|
||||
"ZFS ARC minimum size", nil, nil,
|
||||
),
|
||||
arcstatsDataSize: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_data_bytes"),
|
||||
"ZFS ARC data size", nil, nil,
|
||||
),
|
||||
arcstatsDemandDataHits: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_demand_data_hits_total"),
|
||||
"ZFS ARC demand data hits", nil, nil,
|
||||
),
|
||||
arcstatsDemandDataMisses: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_demand_data_misses_total"),
|
||||
"ZFS ARC demand data misses", nil, nil,
|
||||
),
|
||||
arcstatsDemandMetadataHits: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_demand_metadata_hits_total"),
|
||||
"ZFS ARC demand metadata hits", nil, nil,
|
||||
),
|
||||
arcstatsDemandMetadataMisses: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_demand_metadata_misses_total"),
|
||||
"ZFS ARC demand metadata misses", nil, nil,
|
||||
),
|
||||
arcstatsHeaderSize: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_hdr_bytes"),
|
||||
"ZFS ARC header size", nil, nil,
|
||||
),
|
||||
arcstatsHits: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_hits_total"),
|
||||
"ZFS ARC hits", nil, nil,
|
||||
),
|
||||
arcstatsMisses: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_misses_total"),
|
||||
"ZFS ARC misses", nil, nil,
|
||||
),
|
||||
arcstatsMFUGhostHits: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_mfu_ghost_hits_total"),
|
||||
"ZFS ARC MFU ghost hits", nil, nil,
|
||||
),
|
||||
arcstatsMFUGhostSize: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_mfu_ghost_size"),
|
||||
"ZFS ARC MFU ghost size", nil, nil,
|
||||
),
|
||||
arcstatsMFUSize: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_mfu_bytes"),
|
||||
"ZFS ARC MFU size", nil, nil,
|
||||
),
|
||||
arcstatsMRUGhostHits: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_mru_ghost_hits_total"),
|
||||
"ZFS ARC MRU ghost hits", nil, nil,
|
||||
),
|
||||
arcstatsMRUGhostSize: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_mru_ghost_bytes"),
|
||||
"ZFS ARC MRU ghost size", nil, nil,
|
||||
),
|
||||
arcstatsMRUSize: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_mru_bytes"),
|
||||
"ZFS ARC MRU size", nil, nil,
|
||||
),
|
||||
arcstatsOtherSize: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_other_bytes"),
|
||||
"ZFS ARC other size", nil, nil,
|
||||
),
|
||||
arcstatsP: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_p_bytes"),
|
||||
"ZFS ARC MRU target size", nil, nil,
|
||||
),
|
||||
arcstatsSize: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "arcstats_size_bytes"),
|
||||
"ZFS ARC size", nil, nil,
|
||||
),
|
||||
zfetchstatsHits: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "zfetchstats_hits_total"),
|
||||
"ZFS cache fetch hits", nil, nil,
|
||||
),
|
||||
zfetchstatsMisses: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "zfetchstats_misses_total"),
|
||||
"ZFS cache fetch misses", nil, nil,
|
||||
),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *zfsCollector) updateZfsAbdStats(ch chan<- prometheus.Metric) error {
|
||||
var metricType prometheus.ValueType
|
||||
|
||||
tok, err := kstat.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer tok.Close()
|
||||
|
||||
ksZFSInfo, err := tok.Lookup("zfs", 0, "abdstats")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for k, v := range map[string]*prometheus.Desc{
|
||||
"linear_cnt": c.abdstatsLinearCount,
|
||||
"linear_data_size": c.abdstatsLinearDataSize,
|
||||
"scatter_chunk_waste": c.abdstatsScatterChunkWaste,
|
||||
"scatter_cnt": c.abdstatsScatterCount,
|
||||
"scatter_data_size": c.abdstatsScatterDataSize,
|
||||
"struct_size": c.abdstatsStructSize,
|
||||
} {
|
||||
ksZFSInfoValue, err := ksZFSInfo.GetNamed(k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if strings.HasSuffix(k, "_cnt") {
|
||||
metricType = prometheus.CounterValue
|
||||
} else {
|
||||
metricType = prometheus.GaugeValue
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
v,
|
||||
metricType,
|
||||
float64(ksZFSInfoValue.UintVal),
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *zfsCollector) updateZfsArcStats(ch chan<- prometheus.Metric) error {
|
||||
var metricType prometheus.ValueType
|
||||
|
||||
tok, err := kstat.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer tok.Close()
|
||||
|
||||
ksZFSInfo, err := tok.Lookup("zfs", 0, "arcstats")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for k, v := range map[string]*prometheus.Desc{
|
||||
"anon_size": c.arcstatsAnonSize,
|
||||
"c": c.arcstatsC,
|
||||
"c_max": c.arcstatsCMax,
|
||||
"c_min": c.arcstatsCMin,
|
||||
"data_size": c.arcstatsDataSize,
|
||||
"demand_data_hits": c.arcstatsDemandDataHits,
|
||||
"demand_data_misses": c.arcstatsDemandDataMisses,
|
||||
"demand_metadata_hits": c.arcstatsDemandMetadataHits,
|
||||
"demand_metadata_misses": c.arcstatsDemandMetadataMisses,
|
||||
"hdr_size": c.arcstatsHeaderSize,
|
||||
"hits": c.arcstatsHits,
|
||||
"misses": c.arcstatsMisses,
|
||||
"mfu_ghost_hits": c.arcstatsMFUGhostHits,
|
||||
"mfu_ghost_size": c.arcstatsMFUGhostSize,
|
||||
"mfu_size": c.arcstatsMFUSize,
|
||||
"mru_ghost_hits": c.arcstatsMRUGhostHits,
|
||||
"mru_ghost_size": c.arcstatsMRUGhostSize,
|
||||
"mru_size": c.arcstatsMRUSize,
|
||||
"other_size": c.arcstatsOtherSize,
|
||||
"p": c.arcstatsP,
|
||||
"size": c.arcstatsSize,
|
||||
} {
|
||||
ksZFSInfoValue, err := ksZFSInfo.GetNamed(k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if strings.HasSuffix(k, "_hits") || strings.HasSuffix(k, "_misses") {
|
||||
metricType = prometheus.CounterValue
|
||||
} else {
|
||||
metricType = prometheus.GaugeValue
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
v,
|
||||
metricType,
|
||||
float64(ksZFSInfoValue.UintVal),
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *zfsCollector) updateZfsFetchStats(ch chan<- prometheus.Metric) error {
|
||||
tok, err := kstat.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer tok.Close()
|
||||
|
||||
ksZFSInfo, err := tok.Lookup("zfs", 0, "zfetchstats")
|
||||
|
||||
for k, v := range map[string]*prometheus.Desc{
|
||||
"hits": c.zfetchstatsHits,
|
||||
"misses": c.zfetchstatsMisses,
|
||||
} {
|
||||
ksZFSInfoValue, err := ksZFSInfo.GetNamed(k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
v,
|
||||
prometheus.CounterValue,
|
||||
float64(ksZFSInfoValue.UintVal),
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
if err := c.updateZfsAbdStats(ch); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.updateZfsArcStats(ch); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.updateZfsFetchStats(ch); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue