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
|
@ -10,6 +10,7 @@
|
|||
* [CHANGE] Add a limit to the number of in-flight requests #1166
|
||||
* [ENHANCEMENT] Add Infiniband counters #1120
|
||||
* [FEATURE] Add a flag to disable exporter metrics #1148
|
||||
* [FEATURE] Add kstat-based Solaris metrics for boottime, cpu and zfs collectors #1197
|
||||
|
||||
## 0.17.0 / 2018-11-30
|
||||
|
||||
|
|
|
@ -29,9 +29,9 @@ Name | Description | OS
|
|||
arp | Exposes ARP statistics from `/proc/net/arp`. | Linux
|
||||
bcache | Exposes bcache statistics from `/sys/fs/bcache/`. | Linux
|
||||
bonding | Exposes the number of configured and active slaves of Linux bonding interfaces. | Linux
|
||||
boottime | Exposes system boot time derived from the `kern.boottime` sysctl. | Darwin, Dragonfly, FreeBSD, NetBSD, OpenBSD
|
||||
boottime | Exposes system boot time derived from the `kern.boottime` sysctl. | Darwin, Dragonfly, FreeBSD, NetBSD, OpenBSD, Solaris
|
||||
conntrack | Shows conntrack statistics (does nothing if no `/proc/sys/net/netfilter/` present). | Linux
|
||||
cpu | Exposes CPU statistics | Darwin, Dragonfly, FreeBSD, Linux
|
||||
cpu | Exposes CPU statistics | Darwin, Dragonfly, FreeBSD, Linux, Solaris
|
||||
diskstats | Exposes disk I/O statistics. | Darwin, Linux
|
||||
edac | Exposes error detection and correction statistics. | Linux
|
||||
entropy | Exposes available entropy. | Linux
|
||||
|
@ -57,7 +57,7 @@ timex | Exposes selected adjtimex(2) system call stats. | Linux
|
|||
uname | Exposes system information as provided by the uname system call. | Linux
|
||||
vmstat | Exposes statistics from `/proc/vmstat`. | Linux
|
||||
xfs | Exposes XFS runtime statistics. | Linux (kernel 4.4+)
|
||||
zfs | Exposes [ZFS](http://open-zfs.org/) performance statistics. | [Linux](http://zfsonlinux.org/)
|
||||
zfs | Exposes [ZFS](http://open-zfs.org/) performance statistics. | [Linux](http://zfsonlinux.org/), Solaris
|
||||
|
||||
### Disabled by default
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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 kstatToFloat(ks *kstat.KStat, kstatKey string) float64 {
|
||||
kstatValue, err := ks.GetNamed(kstatKey)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
kstatLoadavg, err := strconv.ParseFloat(
|
||||
fmt.Sprintf("%.2f", float64(kstatValue.UintVal)/C.FSCALE), 64)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return kstatLoadavg
|
||||
}
|
||||
|
||||
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")
|
||||
tok, err := kstat.Open()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return []float64{float64(loadavg[0]), float64(loadavg[1]), float64(loadavg[2])}, nil
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
1
go.mod
1
go.mod
|
@ -22,6 +22,7 @@ require (
|
|||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910
|
||||
github.com/prometheus/common v0.0.0-20181015124227-bcb74de08d37
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d
|
||||
github.com/siebenmann/go-kstat v0.0.0-20160321171754-d34789b79745
|
||||
github.com/sirupsen/logrus v1.1.1 // indirect
|
||||
github.com/soundcloud/go-runit v0.0.0-20150630195641-06ad41a06c4a
|
||||
golang.org/x/crypto v0.0.0-20181009213950-7c1a557ab941 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -45,6 +45,8 @@ github.com/prometheus/common v0.0.0-20181015124227-bcb74de08d37 h1:Y7YdJ9Xb3MoQO
|
|||
github.com/prometheus/common v0.0.0-20181015124227-bcb74de08d37/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d h1:GoAlyOgbOEIFdaDqxJVlbOQ1DtGmZWs/Qau0hIlk+WQ=
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/siebenmann/go-kstat v0.0.0-20160321171754-d34789b79745 h1:IuH7WumZNax0D+rEqmy2TyhKCzrtMGqbZO0b8rO00JA=
|
||||
github.com/siebenmann/go-kstat v0.0.0-20160321171754-d34789b79745/go.mod h1:G81aIFAMS9ECrwBYR9YxhlPjWgrItd+Kje78O6+uqm8=
|
||||
github.com/sirupsen/logrus v1.1.1 h1:VzGj7lhU7KEB9e9gMpAV/v5XT2NVSvLJhJLCWbnkgXg=
|
||||
github.com/sirupsen/logrus v1.1.1/go.mod h1:zrgwTnHtNr00buQ1vSptGe8m1f/BbgsPukg8qsT7A+A=
|
||||
github.com/soundcloud/go-runit v0.0.0-20150630195641-06ad41a06c4a h1:os5OBNhwOwybXZMNLqT96XqtjdTtwRFw2w08uluvNeI=
|
||||
|
|
|
@ -50,6 +50,8 @@ github.com/prometheus/procfs/nfs
|
|||
github.com/prometheus/procfs/sysfs
|
||||
github.com/prometheus/procfs/xfs
|
||||
github.com/prometheus/procfs/internal/util
|
||||
# github.com/siebenmann/go-kstat v0.0.0-20160321171754-d34789b79745
|
||||
github.com/siebenmann/go-kstat
|
||||
# github.com/sirupsen/logrus v1.1.1
|
||||
github.com/sirupsen/logrus
|
||||
# github.com/soundcloud/go-runit v0.0.0-20150630195641-06ad41a06c4a
|
||||
|
|
Loading…
Reference in New Issue