mirror of
https://github.com/prometheus/node_exporter.git
synced 2025-01-02 09:27:48 -08:00
ZFS Collector: Add vdev_cache_stats functionality
Signed-Off-By: Joe Handzik <joseph.t.handzik@hpe.com>
This commit is contained in:
parent
a02ca9502c
commit
3c9e779989
|
@ -2383,6 +2383,15 @@ node_zfsFetch_stride_hits 7.06799e+06
|
||||||
# HELP node_zfsFetch_stride_misses kstat.zfs.misc.zfetchstats.stride_misses
|
# HELP node_zfsFetch_stride_misses kstat.zfs.misc.zfetchstats.stride_misses
|
||||||
# TYPE node_zfsFetch_stride_misses untyped
|
# TYPE node_zfsFetch_stride_misses untyped
|
||||||
node_zfsFetch_stride_misses 0
|
node_zfsFetch_stride_misses 0
|
||||||
|
# HELP node_zfsVdevCache_delegations kstat.zfs.misc.vdev_cache_stats.delegations
|
||||||
|
# TYPE node_zfsVdevCache_delegations untyped
|
||||||
|
node_zfsVdevCache_delegations 40
|
||||||
|
# HELP node_zfsVdevCache_hits kstat.zfs.misc.vdev_cache_stats.hits
|
||||||
|
# TYPE node_zfsVdevCache_hits untyped
|
||||||
|
node_zfsVdevCache_hits 0
|
||||||
|
# HELP node_zfsVdevCache_misses kstat.zfs.misc.vdev_cache_stats.misses
|
||||||
|
# TYPE node_zfsVdevCache_misses untyped
|
||||||
|
node_zfsVdevCache_misses 0
|
||||||
# HELP node_zfsZil_zil_commit_count kstat.zfs.misc.zil.zil_commit_count
|
# HELP node_zfsZil_zil_commit_count kstat.zfs.misc.zil.zil_commit_count
|
||||||
# TYPE node_zfsZil_zil_commit_count untyped
|
# TYPE node_zfsZil_zil_commit_count untyped
|
||||||
node_zfsZil_zil_commit_count 10
|
node_zfsZil_zil_commit_count 10
|
||||||
|
|
5
collector/fixtures/proc/spl/kstat/zfs/vdev_cache_stats
Normal file
5
collector/fixtures/proc/spl/kstat/zfs/vdev_cache_stats
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
8 1 0x01 3 144 8012540758 352116106118781
|
||||||
|
name type data
|
||||||
|
delegations 4 40
|
||||||
|
hits 4 0
|
||||||
|
misses 4 0
|
|
@ -35,6 +35,7 @@ type zfsSubsystemName string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
arc = zfsSubsystemName("zfsArc")
|
arc = zfsSubsystemName("zfsArc")
|
||||||
|
vdevCache = zfsSubsystemName("zfsVdevCache")
|
||||||
zfetch = zfsSubsystemName("zfsFetch")
|
zfetch = zfsSubsystemName("zfsFetch")
|
||||||
zil = zfsSubsystemName("zfsZil")
|
zil = zfsSubsystemName("zfsZil")
|
||||||
zpoolSubsystem = zfsSubsystemName("zfsPool")
|
zpoolSubsystem = zfsSubsystemName("zfsPool")
|
||||||
|
@ -81,6 +82,10 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||||
err = c.updateZil(ch)
|
err = c.updateZil(ch)
|
||||||
if err != nil { return err }
|
if err != nil { return err }
|
||||||
|
|
||||||
|
// VdevCacheStats
|
||||||
|
err = c.updateVdevCacheStats(ch)
|
||||||
|
if err != nil { return err }
|
||||||
|
|
||||||
// Pool stats
|
// Pool stats
|
||||||
return c.updatePoolStats(ch)
|
return c.updatePoolStats(ch)
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
zfsProcpathBase = "spl/kstat/zfs/"
|
zfsProcpathBase = "spl/kstat/zfs/"
|
||||||
zfsArcstatsExt = "arcstats"
|
zfsArcstatsExt = "arcstats"
|
||||||
zfsFetchstatsExt = "zfetchstats"
|
zfsFetchstatsExt = "zfetchstats"
|
||||||
zfsZilExt = "zil"
|
zfsVdevCacheStatsExt = "vdev_cache_stats"
|
||||||
|
zfsZilExt = "zil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *zfsCollector) openProcFile(path string) (file *os.File, err error) {
|
func (c *zfsCollector) openProcFile(path string) (file *os.File, err error) {
|
||||||
|
@ -78,6 +79,18 @@ func (c *zfsCollector) updateZil(ch chan<- prometheus.Metric) (err error) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *zfsCollector) updateVdevCacheStats(ch chan<- prometheus.Metric) (err error) {
|
||||||
|
file, err := c.openProcFile(filepath.Join(zfsProcpathBase, zfsVdevCacheStatsExt))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
return c.parseProcfsFile(file, zfsVdevCacheStatsExt, func(s zfsSysctl, v zfsMetricValue) {
|
||||||
|
ch <- c.constSysctlMetric(vdevCache, s, v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (c *zfsCollector) parseProcfsFile(reader io.Reader, fmt_ext string, handler func(zfsSysctl, zfsMetricValue)) (err error) {
|
func (c *zfsCollector) parseProcfsFile(reader io.Reader, fmt_ext string, handler func(zfsSysctl, zfsMetricValue)) (err error) {
|
||||||
scanner := bufio.NewScanner(reader)
|
scanner := bufio.NewScanner(reader)
|
||||||
|
|
||||||
|
|
|
@ -125,3 +125,39 @@ func TestZilParsing(t *testing.T) {
|
||||||
t.Fatal("Zil parsing handler was not called for some expected sysctls")
|
t.Fatal("Zil parsing handler was not called for some expected sysctls")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVdevCacheStatsParsing(t *testing.T) {
|
||||||
|
vdevCacheStatsFile, err := os.Open("fixtures/proc/spl/kstat/zfs/vdev_cache_stats")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer vdevCacheStatsFile.Close()
|
||||||
|
|
||||||
|
c := zfsCollector{}
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
handlerCalled := false
|
||||||
|
err = c.parseProcfsFile(vdevCacheStatsFile, "vdev_cache_stats", func(s zfsSysctl, v zfsMetricValue) {
|
||||||
|
|
||||||
|
if s != zfsSysctl("kstat.zfs.misc.vdev_cache_stats.delegations") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
handlerCalled = true
|
||||||
|
|
||||||
|
if v != zfsMetricValue(40) {
|
||||||
|
t.Fatalf("Incorrect value parsed from procfs data")
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !handlerCalled {
|
||||||
|
t.Fatal("VdevCacheStats parsing handler was not called for some expected sysctls")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue